public without sharing class LoanerApplicationFlowController {
|
// 基础Url
|
public String baseUrl { get; private set; }
|
// 样机借出申请ID
|
public String laId { get; private set; }
|
public loaner_application__c la { get; private set; }
|
/* 画面步骤
|
* 下架:StockDown
|
*
|
*/
|
public String step { get; private set; }
|
// 明细Bean
|
public List<DataLineBean> dataLines { get; set; }
|
// 明细行数
|
public Integer getDatalineSize() {
|
return dataLines == null ? 0 : dataLines.size();
|
}
|
|
public LoanerApplicationFlowController() {
|
laId = System.currentPageReference().getParameters().get('id');
|
step = System.currentPageReference().getParameters().get('step');
|
}
|
|
public PageReference init() {
|
// 基础Url
|
baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
|
String path = URL.getCurrentRequestUrl().getPath();
|
if (path.indexOf('/apex') > 0) {
|
baseUrl += path.substring(0,path.indexOf('/apex'));
|
} else if (path.indexOf('production/') > 0) {
|
baseUrl += '/production';
|
}
|
// 明细Bean
|
dataLines = new List<DataLineBean>();
|
|
if (String.isBlank(laId) == true) {
|
return null;
|
}
|
if (String.isBlank(step) == true) {
|
return null;
|
}
|
// 样机借出申请取得
|
List<loaner_application__c> laList = [select Id,Status__c from loaner_application__c where Id = :laId];
|
if (laList.size() == 0) {
|
return null;
|
}
|
la = laList[0];
|
// 样机借出申请明细取得
|
String sql_select = 'select Id, SerialNumber__c, Internal_Asset_number__c, OTCODE__c, ECCode__c ';
|
String sql_where = ' where loaner_application__c = :laId ';
|
if (step == 'StockDown') {
|
sql_where += ' and RAESD_Status__c = \'已出库指示\'';
|
} else {
|
return null;
|
}
|
String sql_full = sql_select + ' from loaner_application_detail__c ' + sql_where;
|
|
List<loaner_application_detail__c> lads = Database.query(sql_full);
|
if (lads.size() == 0) {
|
return null;
|
}
|
// 明细Bean作成
|
Integer cnt = 0;
|
for (loaner_application_detail__c lad : lads) {
|
cnt += 1;
|
DataLineBean dataLine = new DataLineBean(cnt, lad);
|
dataLines.add(dataLine);
|
}
|
|
return null;
|
}
|
|
public PageReference saveBtn() {
|
// 根据step更新样机借出申请明细状态
|
List<loaner_application_detail__c> updList = new List<loaner_application_detail__c>();
|
for (DataLineBean dataLine : dataLines) {
|
if (dataLine.checkFlag == true) {
|
loaner_application_detail__c lad = dataLine.lad;
|
if (step == 'StockDown') {
|
lad.StockDown__c = true;
|
lad.StockDown_Date__c = Date.today();
|
lad.RAESD_Status__c = '已下架';
|
}
|
updList.add(lad);
|
}
|
}
|
|
Savepoint sp = Database.setSavepoint();
|
try {
|
if (updList.size() > 0) update updList;
|
|
/*List<loaner_application_detail__c> checkList = [select id,
|
loaner_application__c,
|
loaner_application__r.Detail_count__c,
|
loaner_application__r.Status__c
|
from loaner_application_detail__c
|
where loaner_application__c = :laId
|
and StockDown__c = true];
|
if (checkList.size() > 0) {
|
loaner_application_detail__c check = checkList[0];
|
if (check.loaner_application__r.Detail_count__c == checkList.size() &&
|
check.loaner_application__r.Status__c == '已出库指示') {
|
loaner_application__c upd = new loaner_application__c();
|
upd.id = check.loaner_application__c;
|
upd.Status__c = '已下架';
|
update upd;
|
}
|
}*/
|
if(la.Status__c != '完毕'){
|
la.Status__c = LoanerOrderState.getOrderStater(la.Id);
|
update la;
|
}
|
// 返回样机借出申请画面
|
String url = baseUrl;
|
url += '\\' + laId;
|
return new Pagereference(url);
|
} catch (Exception ex) {
|
Database.rollback(sp);
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage() + ' | Line:' + ex.getLineNumber()));
|
}
|
|
return null;
|
}
|
|
public PageReference cancelBtn() {
|
// 返回样机借出申请画面
|
String url = baseUrl;
|
url += '\\' + laId;
|
return new Pagereference(url);
|
}
|
|
public class DataLineBean {
|
// 是否选择
|
public boolean checkFlag { get; set; }
|
// 行号
|
public Integer lineNo { get; private set; }
|
// 样机借出申请明细
|
public loaner_application_detail__c lad { get; set; }
|
|
public DataLineBean(Integer in_no, loaner_application_detail__c in_lad) {
|
checkFlag = false;
|
lineNo = in_no;
|
lad = in_lad;
|
}
|
}
|
}
|