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;
|
}
|
}
|
}
|