buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
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
public without sharing class LexArriveGsDetailsController {
    public static Consumable_order__c coc { get; set; }
    private static String accountid = null;
    private static Decimal orderallcount = 0;
    public static Boolean arrivetoorder { get; set; }
    public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecords { get; set; }
    public static List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview { get; set; }
    private static String eSetId = '';
    private static Integer consumableorderdetailsCount = null;
 
    //初始化
    @AuraEnabled
    public static Results init(String eSetIdStr) {
        Results results = new Results();
        results.isNoteStay = LexUtility.getIsNoteStay();
        eSetId = eSetIdStr;
        consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
        try {
            //取经销商信息
            String userId = UserInfo.getUserId();
            List<user> useracc = New List<user>();
            useracc = [select accountid from user where id =:userId];
            accountid = useracc[0].accountid;
            List<Consumable_order__c> rs = New List<Consumable_order__c>();
            if(eSetId == NULL || eSetId == '') {
 
            }else {
                rs = [SELECT id,name,Order_reason__c,Arrive_Order__c,Arrive_Order__r.Total_num__c,Arrive_Order__r.IsShipment__c,Arrive_Order__r.Name,
                            recordtypeid,Order_status__c,Deliver_date__c,Arrive_total_amount__c
                        FROM Consumable_order__c
                        WHERE id =:eSetId];
                coc =  new Consumable_order__c();
                if(rs.size()>0){
                    coc = rs[0];
                    orderallcount = coc.Arrive_Order__r.Total_num__c;
                }
                if(coc.Arrive_Order__c == null){
                    arrivetoorder = true;
                }
                List<Consumable_order_details2__c> consumablearriveproductdetailsSelected = [SELECT Id,Dealer_Arrive__c,Bar_Code__c, RecordTypeid, Name,Consumable_Product__r.Name__c,
                                                            Consumable_Product__c,Consumable_Product__r.Name,Dealer_Saled__c,
                                                            Sterilization_limit__c,Deliver_date__c,
                                                            Intra_Trade_List_RMB__c,Asset_Model_No__c,Arrive_Date__c,Send_Date__c,
                                                            Consumable_Product__r.SFDA_Status__c,
                                                            Consumable_Product__r.Product2__r.Packing_list_manual__c,
                                                            Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
                                                            Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
                                                        FROM Consumable_order_details2__c
                                                        WHERE Consumable_Arrived_order__c = :eSetId
                                                        ORDER BY Name ];
                for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
                        consumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
                    }
            }
            for(ConsumableorderdetailsInfo bss : consumableorderdetailsRecords){
                bss.packing_list = bss.Prod.Product2__r.Packing_list_manual__c;
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                //update by rentx 20210622 start CHAN-C3K4ZQ
                bss.expiration_DateStr = bss.Prod.Product2__r.SFDA_Expiration_Date__c == null ? '' : bss.Prod.Product2__r.SFDA_Expiration_Date__c.format();
                bss.Sterilization_limitStr = bss.esd.Sterilization_limit__c == null ? '' : bss.esd.Sterilization_limit__c.format();
                //update by rentx 20210622 end CHAN-C3K4ZQ
            }
            consumableorderdetailsCount = consumableorderdetailsRecords.size();
            //add by rentx 20210622 CHAN-C3K4ZQ
            // makeRecordsView(consumableorderdetailsRecords);
            //add by rentx 20210622 CHAN-
            for(ConsumableorderdetailsInfo con : consumableorderdetailsRecords){
                con.prodName = con.esd.Consumable_Product__r.Name__c;
            }
            results.coc = coc;
            results.accountid = accountid;
            results.orderallcount = orderallcount;
            results.arrivetoorder = arrivetoorder;
            results.consumableorderdetailsRecords = consumableorderdetailsRecords;
            results.consumableorderdetailsCount = consumableorderdetailsCount;
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    //出库
    @AuraEnabled
    public static Results proSale(String cocStr, Decimal orderallcountParm, Integer consumableorderdetailsCountParm, String eSetIdStr) {
        Results results = new Results();
        eSetId = eSetIdStr;
        try {
            orderallcount = orderallcountParm;
            consumableorderdetailsCount = consumableorderdetailsCountParm;
            coc = (Consumable_order__c)JSON.deserialize(cocStr, Consumable_order__c.class);
            List<Consumable_order_details2__c> orderdetails = new List<Consumable_order_details2__c>();
            //发货明细2
            orderdetails = [SELECT Id 
                            FROM Consumable_order_details2__c
                            WHERE Consumable_order_minor__c =:coc.Arrive_Order__c
                            AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                            AND Dealer_Arrive__c = true ];
            if(orderallcount!= consumableorderdetailsCount){
                results.result = 'Fail';
                results.errorMsg = '订单不完全到货,无法出库';
                return results;
            }
            if(coc.Arrive_Order__r.IsShipment__c == true){
                results.result = 'Fail';
                results.errorMsg = '订单已经出库';
                return results;
            }
            results.url = '/lexsummonscreat?arriveorder=' + eSetId +'&KeyWords=Redirect';
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    public class Results {
        @AuraEnabled
        public String result;
        @AuraEnabled
        public String errorMsg;
        @AuraEnabled
        public Consumable_order__c coc;
        @AuraEnabled
        public String accountid;
        @AuraEnabled
        public Decimal orderallcount;
        @AuraEnabled
        public Boolean arrivetoorder;
        @AuraEnabled
        public List<ConsumableorderdetailsInfo> consumableorderdetailsRecords;
        @AuraEnabled
        public Integer consumableorderdetailsCount;
        @AuraEnabled
        public String url;
        @AuraEnabled
        public Boolean isNoteStay;
    }
 
    public class ConsumableorderdetailsInfo implements Comparable {
        @AuraEnabled
        public Consumable_order_details2__c esd;
        @AuraEnabled
        public Product2__c Prod;
        @AuraEnabled
        public Decimal packing_list;
        @AuraEnabled
        public Date expiration_Date;
        @AuraEnabled
        public String approbation_No;
        @AuraEnabled
        public String expiration_DateStr;
        @AuraEnabled
        public String Sterilization_limitStr;
        @AuraEnabled
        public String prodName;
 
 
        // 已存在消耗品明细用
        public ConsumableorderdetailsInfo(Consumable_order_details2__c e) {
            esd = e;
            Prod = e.Consumable_Product__r;
        }
        // 排序Consumable_order__c
        public Integer compareTo(Object compareTo) {
            return null;
        }
    }
}