<apex:page tabStyle="Account" standardController="Account" extensions="AccountTestAndAssets_MR">
<apex:sectionHeader title="Account Tests & Assets" subtitle="{!account.Name}"/>
<apex:form id="theForm">
<apex:pageBlock title="Account Tests & Assets Edit" id="theBlock" >
<apex:pageMessages id="msgs"/>
<apex:pageblockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageblockButtons>
<apex:pageBlockSection title="Tests" columns="1" collapsible="false" id="theTestSection">
<apex:panelGrid columns="8" width="100%">
<apex:outputText > </apex:outputText>
<apex:outputText >Primary Manufacturer</apex:outputText>
<apex:outputText >Primary Platform</apex:outputText>
<apex:outputText >Dako</apex:outputText>
<apex:outputText >Dako Value</apex:outputText>
<apex:outputText >Competitive</apex:outputText>
<apex:outputText >Competitive Value</apex:outputText>
<apex:outputText >Total</apex:outputText>
<apex:outputText >IHC</apex:outputText>
<apex:outputText value="{!account.IHC_Primary_Manufacturer__c}" />
<apex:outputText value="{!account.IHC_Primary_Platform__c}" />
<apex:inputField value="{!account.IHC_Dako__c}" >
<apex:actionSupport event="onchange" rerender="IHC_Comp"/>
</apex:inputField>
<apex:outputText value="{!account.IHC_Dako_Value__c}"/>
<apex:outputText value="{!Acc_IHC_Competitor}" id="IHC_Comp" />
<apex:outputText value="{!account.IHC_Competitor_Value__c}"/>
<apex:inputField value="{!account.IHC_Total__c}" >
<apex:actionSupport event="onchange" rerender="IHC_Comp"/>
</apex:inputField>
</apex:panelGrid>
</apex:pageBlockSection>
<apex:pageBlockSection title="Manage Assets" columns="1" collapsible="false" id="theAddSection">
<apex:panelGrid columns="8" width="100%">
<apex:outputText styleClass="columnHeader" >Type</apex:outputText>
<apex:outputText styleClass="columnHeader">Manufacturer</apex:outputText>
<apex:outputText styleClass="columnHeader">Model Name</apex:outputText>
<apex:outputText styleClass="columnHeader">Serial Number</apex:outputText>
<apex:outputText styleClass="columnHeader">Install. Date</apex:outputText>
<apex:outputText styleClass="columnHeader">Expiry Date</apex:outputText>
<apex:outputText styleClass="columnHeader">Expiry Type</apex:outputText>
<apex:outputText styleClass="columnHeader">Primary</apex:outputText>
<apex:inputField value="{!newAsset.Account_Asset_Type__c}" />
<apex:inputField value="{!newAsset.Account_Asset_Manufacturer__c}" />
<apex:inputField value="{!newAsset.Account_Asset_Model_name__c}" />
<apex:inputField value="{!newAsset.SerialNumber}" />
<apex:inputField value="{!newAsset.InstallDate}" />
<apex:inputField value="{!newAsset.Account_Asset_Expiry_Date__c}" />
<apex:inputField value="{!newAsset.Account_Asset_Expiry_type__c}" />
<apex:inputField value="{!newAsset.Primary_Type__c}"/>
<apex:commandButton value="Add Asset / Save" action="{!addNewAsset}" reRender="theAddSection,theTestSection, msgs"/>
</apex:panelGrid>
<apex:pageBlockTable styleClass="bRelatedList" value="{!lstAssets}" var="theAsset" id="theAssetTable" >
<apex:column styleClass="actionColumn" headerValue="Action" >
<apex:commandLink value="View" styleClass="actionLink" action="{!viewAsset}" id="viewLnk" />
|
<apex:commandLink id="editLnk" value="Edit" styleClass="actionLink" action="{!editAsset}" reRender="theAddSection">
<apex:param name="objectId" value="{!theAsset.Id}"/>
</apex:commandLink>
|
<apex:commandLink id="delLnk" value="Del" styleClass="actionLink" action="{!deleteAsset}" reRender="theAddSection, theTestSection" onclick=" if(!confirm('The selected Asset will be deleted, do you want to continue? ?')){return};">
<apex:param name="objectId" value="{!theAsset.Id}"/>
</apex:commandLink>
|
</apex:column>
<apex:column headerValue="Type">
<apex:outputField value="{!theAsset.Account_Asset_Type__c}"/>
</apex:column>
<apex:column headervalue="Manufacturer">
<apex:outputField value="{!theAsset.Account_Asset_Manufacturer__c}"/>
</apex:column>
<apex:column headervalue="Model Name">
<apex:outputField value="{!theAsset.Account_Asset_Model_name__c}"/>
</apex:column>
<apex:column headervalue="Serial Number">
<apex:outputField value="{!theAsset.SerialNumber}"/>
</apex:column>
<apex:column headervalue="Install Date">
<apex:outputField value="{!theAsset.InstallDate}"/>
</apex:column>
<apex:column headervalue="Expiry Date">
<apex:outputField value="{!theAsset.Account_Asset_Expiry_Date__c}"/>
</apex:column>
<apex:column headervalue="Expiry Type">
<apex:outputField value="{!theAsset.Account_Asset_Expiry_type__c}"/>
</apex:column>
<apex:column headervalue="Primary">
<apex:outputField value="{!theAsset.Primary_Type__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
public with sharing class AccountTestAndAssets_MR {
public ApexPages.StandardController stdController;
private Account account;
public List<Asset> lstAssets {get; set;}
// public Boolean globalMessages {get; set;} public Asset newAsset {get; set;} public Boolean renderAssets {get; set;} public Boolean renderlstAssets {get; set;}
public Integer Acc_IHC_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.IHC_Total__c)) && String.isNotBlank(String.valueOf(account.IHC_Dako__c))){
return Integer.valueOf(account.IHC_Total__c - account.IHC_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_ISH_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.ISH_Total__c)) && String.isNotBlank(String.valueOf(account.ISH_Dako__c))){
return Integer.valueOf(account.ISH_Total__c - account.ISH_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_HE_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.H_E_Total__c)) && String.isNotBlank(String.valueOf(account.H_E_Dako__c))){
return Integer.valueOf(account.H_E_Total__c - account.H_E_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_PhDx_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.PharmDx_Total__c)) && String.isNotBlank(String.valueOf(account.PharmDx_Dako__c))){
return Integer.valueOf(account.PharmDx_Total__c - account.PharmDx_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_SS_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.Special_Stains_Total__c)) && String.isNotBlank(String.valueOf(account.Special_Stains_Dako__c))){
return Integer.valueOf(account.Special_Stains_Total__c- account.Special_Stains_Dako__c);
}else {return null;}
}
set;}
/*******************************************************************************************
* @description Constructor. Initialization, populates asset lists
* @param controller The standard Controller. Which means Account
*/
public AccountTestAndAssets_MR (ApexPages.StandardController controller) {
stdController = controller;
this.account = (Account)controller.getRecord();
addEmptyAsset();
lstAssets = [
SELECT id, Name, Account_Asset_Type__c, Account_Asset_Manufacturer__c, Account_Asset_Model_name__c,
InstallDate, Account_Asset_Expiry_Date__c, Account_Asset_Expiry_type__c, Status, IsCompetitorProduct,
Product2.Name, SerialNumber, UsageEndDate, Quantity, Contract_Type__c, Primary_Type__c, Staining_Type__c
FROM Asset
WHERE AccountId = :account.Id Order by Account_Asset_Type__c, CreatedDate DESC ];
renderAssets = lstAssets.size() > 0;
renderlstAssets = lstAssets.size() > 0;
}
// start Test N Assets Edit Page logic methods
/** * @description Convenience method to initialize a new blank asset and set the fields which must be set * but which are not really relevant to the Test and Assets page. */ private void addEmptyAsset() { newAsset = new Asset(); newAsset.AccountId = account.Id; newAsset.Account_Asset_Manufacturer__c = null; }
/**
* @description Insert/updates a Competitor Asset. As it is possible to do simple edits
* of assets on the page, this method is essentially a "save asset"
* Also handles Asset Field Validation. As both Account and Asset fields are present on the
* page the test for "required" asset fields must be done here r it would not be possible
* to save the account data.
*/
public void addNewAsset() {
boolean inputError = false;
//validate correct field entries or throw errors
if (newAsset.Account_Asset_Type__c == null) {
newAsset.Account_Asset_Type__c.addError('Please select Type');
inputError = true;
return;
}
if (String.IsBlank(newAsset.Account_Asset_Manufacturer__c)) {
newAsset.Account_Asset_Manufacturer__c.addError('Please select Manufacturer');
inputError = true;
return;
}else{ //if there is a Manufacturer selected then validate if Competitor or Dako Asset and update field according
newAsset.IsCompetitorProduct =((String)newAsset.Account_Asset_Manufacturer__c).left(4)== 'Dako' ? false : true;
}
if (newAsset.Account_Asset_Model_name__c == null) {
newAsset.Account_Asset_Model_name__c.addError('Please select Model Name');
inputError = true;
return;
}
system.debug('###newAsset.Account_Asset_Type__c: ' + (newAsset.Account_Asset_Type__c == null));
if(newAsset.Account_Asset_Manufacturer__c.left(4).tolowerCase() == 'dako'){
if(newAsset.SerialNumber == null) {
newAsset.SerialNumber.addError('Serial Number is required for Dako Assets');
inputError = true;
return;
}
}
if (newAsset.InstallDate == null) {
newAsset.InstallDate.addError('Please select Install Date');
inputError = true;
return;
}
if (newAsset.Account_Asset_Expiry_Date__c == null) {
newAsset.Account_Asset_Expiry_Date__c.addError('Please select Expiry Date');
inputError = true;
return;
}
if (newAsset.Account_Asset_Expiry_type__c == null) {
newAsset.Account_Asset_Expiry_type__c.addError('Please select Expiry Type');
inputError = true;
return;
}
//TODO: update naming convention to match new Naming for Assets (Prod, type + number)
Boolean hasID = (newAsset.Id == null);
if (!hasID) newAsset.Name = newAsset.Account_Asset_Model_name__c;
//if input error: do not continue to upsert newAsset
if (inputError) return;
try {
upsert newAsset;
}catch(Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
return;
}
//reload Account to get updated info from triggers (Tests section)
loadAccount ();
if (hasID) lstAssets.add(newAsset);
addEmptyAsset();
renderAssets = lstAssets.size() > 0;
}
/**
* @description Handle edit of a listed Asset. This is simply a matter o assigning
* newAsset as this is the target for the input fields.
* Note that save is handled by the add button ie. addNewAsset()
*/
public void editAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
Integer rowIndex = 0;
for (Asset targetAsset: lstAssets) {
if (targetAsset.Id == objectId) {
newAsset = targetAsset;
break;
}
rowIndex++;
}
renderAssets = lstAssets.size() > 0;
}
public pageReference viewAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
PageReference newref = new PageReference('/'+ objectId);
newRef.setRedirect(true);
return newRef;
}
/**
* @description Handle page save. Ensure eny pageMessages will display and forward to standard controller.
* @return Which ever PageReference returned by the standard controller save() method.https://c.cs2.visual.force.com/s.gif
*/
public PageReference save() {
return stdController.save();
}
/**
* @description Handle delete of a listed Asset. Issue a delete to salesforce
* and remove the object from the list
*/
public void deleteAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
Integer rowIndex = 0;
//TODO: check if primary is checked for asset if so then nullify corresponding account fields
for (Asset targetAsset: lstAssets) {
if (targetAsset.Id == objectId) {
delete targetAsset;
lstAssets.remove(rowIndex);
break;
}
rowIndex++;
}
renderlstAssets = lstAssets.size() > 0;
}
private void loadAccount () { /String query = 'SELECT '; for(Schema.FieldSetMember f : this.getFields()) { query += f.getFieldPath() + ', '; } query += 'Id, Name FROM Account Where Id = '' + account.id + '' LIMIT 1'; account = Database.query(query);/ this.account = (Account)stdController.getRecord(); system.debug('### load Account: ' + account); }
public with sharing class AccountTestAndAssets_MR {
public ApexPages.StandardController stdController;
private Account account;
public List<Asset> lstAssets {get; set;}
public Asset newAsset {get; set;}
public Boolean renderAssets {get; set;}
public Boolean renderlstAssets {get; set;}
public Integer Acc_IHC_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.IHC_Total__c)) && String.isNotBlank(String.valueOf(account.IHC_Dako__c))){
return Integer.valueOf(account.IHC_Total__c - account.IHC_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_ISH_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.ISH_Total__c)) && String.isNotBlank(String.valueOf(account.ISH_Dako__c))){
return Integer.valueOf(account.ISH_Total__c - account.ISH_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_HE_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.H_E_Total__c)) && String.isNotBlank(String.valueOf(account.H_E_Dako__c))){
return Integer.valueOf(account.H_E_Total__c - account.H_E_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_PhDx_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.PharmDx_Total__c)) && String.isNotBlank(String.valueOf(account.PharmDx_Dako__c))){
return Integer.valueOf(account.PharmDx_Total__c - account.PharmDx_Dako__c);
}else {return null;}
}
set;}
public Integer Acc_SS_Competitor {
get{
if(String.isNotBlank(String.valueOf(account.Special_Stains_Total__c)) && String.isNotBlank(String.valueOf(account.Special_Stains_Dako__c))){
return Integer.valueOf(account.Special_Stains_Total__c- account.Special_Stains_Dako__c);
}else {return null;}
}
set;}
public AccountTestAndAssets_MR (ApexPages.StandardController controller) {
stdController = controller;
this.account = (Account)controller.getRecord();
addEmptyAsset();
lstAssets = [
SELECT id, Name, Account_Asset_Type__c, Account_Asset_Manufacturer__c, Account_Asset_Model_name__c,
InstallDate, Account_Asset_Expiry_Date__c, Account_Asset_Expiry_type__c, Status, IsCompetitorProduct,
Product2.Name, SerialNumber, UsageEndDate, Quantity, Contract_Type__c, Primary_Type__c, Staining_Type__c
FROM Asset
WHERE AccountId = :account.Id Order by Account_Asset_Type__c, CreatedDate DESC ];
renderAssets = lstAssets.size() > 0;
renderlstAssets = lstAssets.size() > 0;
}
private void addEmptyAsset() {
newAsset = new Asset();
newAsset.AccountId = account.Id;
newAsset.Account_Asset_Manufacturer__c = null;
}
public void addNewAsset() {
boolean inputError = false;
//validate correct field entries or throw errors
if (newAsset.Account_Asset_Type__c == null) {
newAsset.Account_Asset_Type__c.addError('Please select Type');
inputError = true;
return;
}
if (String.IsBlank(newAsset.Account_Asset_Manufacturer__c)) {
newAsset.Account_Asset_Manufacturer__c.addError('Please select Manufacturer');
inputError = true;
return;
}else{ //if there is a Manufacturer selected then validate if Competitor or Dako Asset and update field according
newAsset.IsCompetitorProduct =((String)newAsset.Account_Asset_Manufacturer__c).left(4)== 'Dako' ? false : true;
}
if (newAsset.Account_Asset_Model_name__c == null) {
newAsset.Account_Asset_Model_name__c.addError('Please select Model Name');
inputError = true;
return;
}
system.debug('###newAsset.Account_Asset_Type__c: ' + (newAsset.Account_Asset_Type__c == null));
if(newAsset.Account_Asset_Manufacturer__c.left(4).tolowerCase() == 'dako'){
if(newAsset.SerialNumber == null) {
newAsset.SerialNumber.addError('Serial Number is required for Dako Assets');
inputError = true;
return;
}
}
if (newAsset.InstallDate == null) {
newAsset.InstallDate.addError('Please select Install Date');
inputError = true;
return;
}
if (newAsset.Account_Asset_Expiry_Date__c == null) {
newAsset.Account_Asset_Expiry_Date__c.addError('Please select Expiry Date');
inputError = true;
return;
}
if (newAsset.Account_Asset_Expiry_type__c == null) {
newAsset.Account_Asset_Expiry_type__c.addError('Please select Expiry Type');
inputError = true;
return;
}
Boolean hasID = (newAsset.Id == null);
if (!hasID) newAsset.Name = newAsset.Account_Asset_Model_name__c;
//if input error: do not continue to upsert newAsset
if (inputError) return;
try {
upsert newAsset;
}catch(Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
return;
}
//reload Account to get updated info from triggers (Tests section)
loadAccount ();
if (hasID) lstAssets.add(newAsset);
addEmptyAsset();
renderAssets = lstAssets.size() > 0;
}
public void editAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
Integer rowIndex = 0;
for (Asset targetAsset: lstAssets) {
if (targetAsset.Id == objectId) {
newAsset = targetAsset;
break;
}
rowIndex++;
}
renderAssets = lstAssets.size() > 0;
}
public pageReference viewAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
PageReference newref = new PageReference('/'+ objectId);
newRef.setRedirect(true);
return newRef;
}
public PageReference save() {
return stdController.save();
}
public void deleteAsset() {
Id objectId = Id.valueOf(System.currentPagereference().getParameters().get('objectId'));
Integer rowIndex = 0;
//TODO: check if primary is checked for asset if so then nullify corresponding account fields
for (Asset targetAsset: lstAssets) {
if (targetAsset.Id == objectId) {
delete targetAsset;
lstAssets.remove(rowIndex);
break;
}
rowIndex++;
}
renderlstAssets = lstAssets.size() > 0;}
private void loadAccount () {
/*String query = 'SELECT ';
for(Schema.FieldSetMember f : this.getFields()) {
query += f.getFieldPath() + ', ';
}
query += 'Id, Name FROM Account Where Id = \'' + account.id + '\' LIMIT 1';
account = Database.query(query);*/
this.account = (Account)stdController.getRecord();
system.debug('### load Account: ' + account);
}
public List<Schema.FieldSetMember> getFields() {
return SObjectType.Account.FieldSets.TestAndAssets_Account.getFields();
}