高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
public with sharing class CampaignMeetingcostController {
    private String camId;
    public Boolean status { get; set; }
    public Boolean canseePage { get; set; }
    public Campaign camMain { get; set; }
    public Campaign_Cost__c CampaignCostMain  { get; set; }
    public String errorMessage { get; set; }
    public Boolean errorflg { get; set; }
    public CampaignMeetingcostController() {
        camId = ApexPages.currentPage().getParameters().get('id');
    }
    //SWAG-BBG8AK 添加批准列表 start
    public CampaignMeetingcostController(ApexPages.StandardController controller) {
        this();
    }
    //SWAG-BBG8AK 添加批准列表 end
 
    public void init() {
        canseePage = true;
        errorMessage = '';
        errorflg = false;
        status = false;
        String userid = UserInfo.getUserId();
 
        camMain =
            [select id, CostStatus__c , OwnerId,
             Meeting_Type__c, cost_Create_Date__c,
             JingliApprovalManager__c, BuchangApprovalManager__c,
             ZongjianApprovalManager__c, ZongjianApprovalManager_CancleShen__c,
             Sponsor_Ones_Post__c
             from Campaign
             WHERE id = : camId];
 
        List<GroupMember> memberG = new List<GroupMember>();
        if (camMain != null && camMain.Sponsor_Ones_Post__c == '1.华北') {
            memberG = [SELECT Id FROM GroupMember WHERE Group.DeveloperName = 'X00_Meetingfee_Huabei' and UserorGroupId  = :userid];
        }
        List<Campaign_Cost__c> CampaignCostList =
            [SELECT id, OwnerId
             , totalMeetingCost__c
             , medicalInsititute__c, medicalInsitituteCost__c
             , nonMedicalInstitute__c, nonMedicalInstituteCost__c
             , standFittingCompany__c, StandFittingComCost__c
             , broadcastingCompany__c, broadcastingCompanyCost__c
             , OtherSponsorCost__c, animalExperienceCost__c
             , isStand__c, IsSatelliteMeeting__c, isTitle__c, IsDocLOGO__c, IsShowingEquipment__c
             , IsAnimalExperience__c, isOther__c
             , standArea__c, AnimalExperienceNumber__c
             , satelliteMeetingHours__c, showingEquipmentNumber__c
             , titleArea__c, otherWords__c
             , DocLOGOcontent__c
             , paymentFromCompany__c,  paymentFromCooperator__c, livingCost__c
             , tansportCost__c, travelByAir__c, travelByTrain__c, travelByCar__c
             , banquetCost__c, lunchCost__c, teaBreakCost__c, broadcastingCost__c
             , publicityCost__c, sundriesCost__c , sundryContent__c, hostCompany__c
             , hostCompanyCostAndTax__c
             , Campaign__r.CostStatus__c, Campaign__r.cost_Create_Date__c // SWAG-BBG8AK 费用状态和会议费用创建日
             FROM Campaign_Cost__c WHERE Campaign__c = : camId];
 
 
 
        if  (camMain == null || (memberG.size() == 0
                                 && camMain.OwnerId != userid
                                 && userid != camMain.JingliApprovalManager__c
                                 && userid != camMain.BuchangApprovalManager__c
                                 && userid != camMain.ZongjianApprovalManager__c
                                 && userid != camMain.ZongjianApprovalManager_CancleShen__c
                                 && UserInfo.getProfileId() != system.label.ProfileId_SystemAdmin)) {
            errorMessage = '您无权查看会议费用情况。';
            errorflg = true;
            canseePage = false;
            return;
        }
        if (CampaignCostList.size() > 0) {
            CampaignCostMain = CampaignCostList[0];
        } else {
            CampaignCostMain = new Campaign_Cost__c();
            CampaignCostMain.Campaign__c = camId;
            CampaignCostMain.OwnerId = camMain.OwnerId;
        }
        //system.debug('CampaignCostMain:' + CampaignCostMain.Campaign__r.CostStatus__c);
        if (camMain != null
                && (
                    (camMain.OwnerId == userid
                     && (camMain.CostStatus__c == null ||
                         camMain.CostStatus__c == '费用已填写')
                    )
                    || UserInfo.getProfileId() == system.label.ProfileId_SystemAdmin
                )) {
            status = true;
        }
 
    }
    public void dummy() {
 
    }
    // 判断是否显示赞助会
    public boolean getshowSponsor() {
        boolean temp =  false;
        if (camMain != null
                && camMain.Meeting_Type__c != null
                && camMain.Meeting_Type__c.equals('赞助会')) {
            temp = true;
        }
        return temp;
    }
    // 判断是否显示自办会//共同主办会
    public boolean getshowHost() {
        boolean temp =  false;
        if (camMain != null
                && camMain.Meeting_Type__c != null
                && ( camMain.Meeting_Type__c.equals('主办会')
                     || camMain.Meeting_Type__c.equals('共同主办会')
                     || CampaignCostMain.IsSatelliteMeeting__c == true)) {
            temp = true;
        }
        return temp;
    }
    @TestVisible
    private Campaign_Cost__c setupSaveCampaign() {
        Campaign_Cost__c camCostUP = new Campaign_Cost__c();
        camCostUP.id = CampaignCostMain.id;
        camCostUP.JingliApprovalManager__c = camMain.JingliApprovalManager__c;
        camCostUP.BuchangApprovalManager__c = camMain.BuchangApprovalManager__c;
        camCostUP.ZongjianApprovalManager__c = camMain.ZongjianApprovalManager__c;
        camCostUP.Campaign__c = camMain.id;
        camCostUP.OwnerId = camMain.OwnerId;
        if (getshowSponsor()) {
            camCostUP.medicalInsititute__c       = CampaignCostMain.medicalInsititute__c;
            camCostUP.medicalInsitituteCost__c     = CampaignCostMain.medicalInsitituteCost__c;
            camCostUP.nonMedicalInstitute__c     = CampaignCostMain.nonMedicalInstitute__c;
            camCostUP.nonMedicalInstituteCost__c   = CampaignCostMain.nonMedicalInstituteCost__c;
            camCostUP.standFittingCompany__c     = CampaignCostMain.standFittingCompany__c;
            camCostUP.StandFittingComCost__c     = CampaignCostMain.StandFittingComCost__c;
            camCostUP.broadcastingCompany__c     = CampaignCostMain.broadcastingCompany__c;
            camCostUP.broadcastingCompanyCost__c   = CampaignCostMain.broadcastingCompanyCost__c;
            camCostUP.OtherSponsorCost__c       = CampaignCostMain.OtherSponsorCost__c;
            camCostUP.animalExperienceCost__c     = CampaignCostMain.animalExperienceCost__c;
        } else {
            camCostUP.medicalInsititute__c      = null;
            camCostUP.medicalInsitituteCost__c     = null;
            camCostUP.nonMedicalInstitute__c     = null;
            camCostUP.nonMedicalInstituteCost__c  = null;
            camCostUP.standFittingCompany__c     = null;
            camCostUP.StandFittingComCost__c     = null;
            camCostUP.broadcastingCompany__c     = null;
            camCostUP.broadcastingCompanyCost__c   = null;
            camCostUP.OtherSponsorCost__c       = null;
            camCostUP.animalExperienceCost__c     = null;
        }
 
        camCostUP.isStand__c             = CampaignCostMain.isStand__c;
        camCostUP.IsSatelliteMeeting__c       = CampaignCostMain.IsSatelliteMeeting__c;
        camCostUP.isTitle__c             = CampaignCostMain.isTitle__c;
        camCostUP.IsDocLOGO__c             = CampaignCostMain.IsDocLOGO__c;
        camCostUP.IsShowingEquipment__c       = CampaignCostMain.IsShowingEquipment__c;
        camCostUP.IsAnimalExperience__c       = CampaignCostMain.IsAnimalExperience__c;
        camCostUP.isOther__c             = CampaignCostMain.isOther__c;
        if (camCostUP.isStand__c == true) {
            camCostUP.standArea__c           = CampaignCostMain.standArea__c;
        } else {
            camCostUP.standArea__c           = null;
        }
        if (camCostUP.IsAnimalExperience__c == true) {
            camCostUP.AnimalExperienceNumber__c   = CampaignCostMain.AnimalExperienceNumber__c;
        } else {
            camCostUP.AnimalExperienceNumber__c   = null;
        }
        if (camCostUP.IsSatelliteMeeting__c == true) {
            camCostUP.satelliteMeetingHours__c     = CampaignCostMain.satelliteMeetingHours__c;
        } else {
            camCostUP.satelliteMeetingHours__c     = null;
        }
        if (camCostUP.IsShowingEquipment__c == true) {
            camCostUP.showingEquipmentNumber__c   = CampaignCostMain.showingEquipmentNumber__c;
        } else {
            camCostUP.showingEquipmentNumber__c   = null;
        }
        if (camCostUP.isTitle__c == true) {
            camCostUP.titleArea__c           = CampaignCostMain.titleArea__c;
        } else {
            camCostUP.titleArea__c           = null;
        }
        if (camCostUP.isOther__c == true) {
            camCostUP.otherWords__c         = CampaignCostMain.otherWords__c;
        } else {
            camCostUP.otherWords__c         = null;
        }
        if (camCostUP.IsDocLOGO__c == true) {
            camCostUP.DocLOGOcontent__c       = CampaignCostMain.DocLOGOcontent__c;
        } else {
            camCostUP.DocLOGOcontent__c       = null;
        }
 
        if (getshowHost()) {
            camCostUP.paymentFromCompany__c     = CampaignCostMain.paymentFromCompany__c;
            camCostUP.paymentFromCooperator__c     = CampaignCostMain.paymentFromCooperator__c;
            camCostUP.livingCost__c         = CampaignCostMain.livingCost__c;
            camCostUP.tansportCost__c         = CampaignCostMain.tansportCost__c;
            camCostUP.travelByAir__c         = CampaignCostMain.travelByAir__c;
            camCostUP.travelByTrain__c         = CampaignCostMain.travelByTrain__c;
            camCostUP.travelByCar__c         = CampaignCostMain.travelByCar__c;
            camCostUP.banquetCost__c         = CampaignCostMain.banquetCost__c;
            camCostUP.lunchCost__c           = CampaignCostMain.lunchCost__c;
            camCostUP.teaBreakCost__c         = CampaignCostMain.teaBreakCost__c;
            camCostUP.broadcastingCost__c       = CampaignCostMain.broadcastingCost__c;
            camCostUP.publicityCost__c         = CampaignCostMain.publicityCost__c;
            camCostUP.sundriesCost__c         = CampaignCostMain.sundriesCost__c;
            camCostUP.sundryContent__c         = CampaignCostMain.sundryContent__c;
            camCostUP.hostCompany__c         = CampaignCostMain.hostCompany__c;
            camCostUP.hostCompanyCostAndTax__c     = CampaignCostMain.hostCompanyCostAndTax__c;
        } else {
            camCostUP.paymentFromCompany__c     = null;
            camCostUP.paymentFromCooperator__c     = null;
            camCostUP.livingCost__c         = null;
            camCostUP.tansportCost__c         = null;
            camCostUP.travelByAir__c         = false;
            camCostUP.travelByTrain__c         = false;
            camCostUP.travelByCar__c         = false;
            camCostUP.banquetCost__c         = null;
            camCostUP.lunchCost__c           = null;
            camCostUP.teaBreakCost__c         = null;
            camCostUP.broadcastingCost__c       = null;
            camCostUP.publicityCost__c         = null;
            camCostUP.sundriesCost__c         = null;
            camCostUP.sundryContent__c         = null;
            camCostUP.hostCompany__c         = null;
            camCostUP.hostCompanyCostAndTax__c     = null;
        }
        if (camMain.cost_Create_Date__c == null) {
 
            camMain.cost_Create_Date__c = date.today();
            camMain.CostStatus__c = '费用已填写';
        }
        return camCostUP;
    }
 
    private Decimal NullZero(Decimal d ) {
        return d == null ? 0 : d;
    }
    //SWAG-BBG8AK 提交待审批后台逻辑 start
    public void submit() {
        Campaign_Cost__c camCostUP = setupSaveCampaign();
        
        
 
        // SWAG-C3RBA8 20210608S Start 
        Decimal costTotal = NullZero(camCostUP.medicalInsitituteCost__c) + NullZero(camCostUP.nonMedicalInstituteCost__c)
                            + NullZero(camCostUP.StandFittingComCost__c) + NullZero(camCostUP.broadcastingCompanyCost__c )
                            + NullZero(camCostUP.animalExperienceCost__c) + NullZero(camCostUP.OtherSponsorCost__c)
                            + NullZero(camCostUP.paymentFromCompany__c) + NullZero(camCostUP.paymentFromCooperator__c)
                            + NullZero(camCostUP.livingCost__c) + NullZero(camCostUP.tansportCost__c)
                            + NullZero(camCostUP.banquetCost__c) + NullZero(camCostUP.lunchCost__c )
                            + NullZero(camCostUP.teaBreakCost__c) + NullZero(camCostUP.broadcastingCost__c )
                            + NullZero(camCostUP.publicityCost__c) + NullZero(camCostUP.sundriesCost__c) + NullZero(camCostUP.hostCompanyCostAndTax__c);
        
        if (costTotal == 0) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '金额为0,不能提交审批。'));
            return;
        }
        // SWAG-C3RBA8 20210608S End 
 
        Savepoint sp = Database.setSavepoint();
        try {
            status = false;
            upsert camCostUP;
            
            CampaignCostMain = camCostUP;
            camMain.CostStatus__c = '费用已提交';
            camMain.Campaign_Cost__c = camCostUP.id;
            update camMain;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '已提交审批。'));
        } catch (Exception e) {
            Database.rollback(sp);
            ApexPages.addMessages(e);
        }
    }
    //SWAG-BBG8AK 提交待审批后台逻辑 end
 
    //保存画面数据
    public void save() {
        errorMessage = '';
 
        Campaign_Cost__c camCostUP = setupSaveCampaign();
 
 
        system.debug('camMain:' + camMain);
        try {
            upsert camCostUP;
            CampaignCostMain = camCostUP;
            camMain.Campaign_Cost__c = camCostUP.id;
            update camMain;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, ' 保存完了。'));
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
    }
 
}