高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
public with sharing class SampleInventorySectionController {
    public List<SIListInfo> SIInfo { get; set; }
    private String accId { get; set; }
    public String accName { get; set; }
 
    public SampleInventorySectionController(ApexPages.StandardController controller) {
        accId = controller.getId();
    }
    public void init () {
        SIInfo = new List<SIListInfo>();
        Map<String, SIListInfo> SIListInfoMap = new Map<String, SIListInfo>();
        Decimal EffectiveInventoryInfo = 0;
        Decimal ExpiredInventoryInfo = 0;
        List<Sample_inventory_sheet__c> samSheetList = [select Id, Batch__c, ValidTo__c, ProductCode__c, OTCode_Batch_ValidTo__c, Agency__c, Inventory__c, Pro_Model__c
                                                            from Sample_inventory_sheet__c where Agency__c =: accId and Checked_ExpiredInventory__c = false];
        Account account = [select Id, Management_Code__c, Name from Account where Id =: accId];
        accName = account.Name;
        if(samSheetList != null){
            for(Sample_inventory_sheet__c samSheet : samSheetList){
                if(!SIListInfoMap.containsKey(samSheet.ProductCode__c)){
                    if(samSheet.ValidTo__c >= Date.today() || samSheet.ValidTo__c == null){
                        EffectiveInventoryInfo = samSheet.Inventory__c;
                        ExpiredInventoryInfo = 0;
                    } else{
                        EffectiveInventoryInfo = 0;
                        ExpiredInventoryInfo = samSheet.Inventory__c;
                    }
                    SIListInfo info = new SIListInfo(samSheet.ProductCode__c, EffectiveInventoryInfo, ExpiredInventoryInfo);
                    SIInfo.add(info);
                    SIListInfoMap.put(samSheet.ProductCode__c, info);
                } else{
                    SIListInfo oldinfo = SIListInfoMap.get(samSheet.ProductCode__c);
                    if(samSheet.ValidTo__c >= Date.today() || samSheet.ValidTo__c == null){
                        EffectiveInventoryInfo = samSheet.Inventory__c;
                        ExpiredInventoryInfo = 0;
                    } else{
                        EffectiveInventoryInfo = 0;
                        ExpiredInventoryInfo = samSheet.Inventory__c;
                    }
                    oldinfo.EffectiveInventory += EffectiveInventoryInfo;
                    oldinfo.ExpiredInventory += ExpiredInventoryInfo;
                    SIListInfoMap.put(samSheet.ProductCode__c, oldinfo);
                    SIInfo.clear();
                    for(String ProModel : SIListInfoMap.keySet()){
                        SIListInfo info = SIListInfoMap.get(ProModel);
                        SIInfo.add(info);
                    }
                }
            }
        }
    }
 
    public class SIListInfo{
        public Decimal EffectiveInventory { get; set; }
        public Decimal ExpiredInventory { get; set; }
        public String ProductName { get; set; }
        public Decimal ProductSpecs { get; set; }
        public String OTCode { get; set; }
        public SIListInfo(String ProductCode, Decimal EffectiveInventoryInfo, Decimal ExpiredInventoryInfo){
            Product2 product = [select Id, Name, ProductCode, Packing_list_manual__c, SFDA_Expiration_Date__c from Product2 where ProductCode =: ProductCode];
            ProductName = product.Name;
            ProductSpecs = product.Packing_list_manual__c;
            EffectiveInventory = EffectiveInventoryInfo;
            ExpiredInventory = ExpiredInventoryInfo;
            OTCode = ProductCode;
        }
    }
}