/**
|
* wangweipeng 2021/11/22
|
* 备品:批量延期申请
|
*
|
* 只有批量延期的时候,才会进这个类
|
*/
|
public without sharing class RentalApplyMultiPostponeController {
|
|
/***************url传来的备品申请单id********************/
|
public String parentId{get;set;}
|
|
/***************表格数据*********************/
|
public List<getTableData> tableData { get; set; }
|
|
public RentalApplyMultiPostponeController() {
|
parentId = System.currentPageReference().getParameters().get('parentId');
|
//parentId = 'a0t1000000T3KpAAAV';
|
tableData = new List<getTableData>();
|
}
|
|
/**
|
* 开始方法
|
*/
|
public PageReference init(){
|
if(String.isNotBlank(parentId)){
|
getCanPostponeData(parentId);
|
}
|
return null;
|
}
|
|
/**
|
* [getCanPostponeData description]
|
* @param parentId [description]
|
* 获取所有的申请单并处理数据
|
*/
|
public void getCanPostponeData(String parentId){
|
if(String.isNotBlank(parentId)){
|
//获取所有的备品申请单
|
List<Rental_Apply__c> rentalApplyList = getAllRentalApply(parentId);
|
if(rentalApplyList != null && rentalApplyList.size() > 0){
|
Map<ID,Rental_Apply_Equipment_Set__c> raescMap = new Map<ID,Rental_Apply_Equipment_Set__c>();
|
Map<ID,Rental_Apply_Equipment_Set__c> raescMapTrue = new Map<ID,Rental_Apply_Equipment_Set__c>();
|
List<Rental_Apply_Equipment_Set__c> raesc = getExtend_Request(parentId);
|
//申请单任一个一览收货OK已回寄的,此单不满足延期条件
|
if(raesc != null && raesc.size() > 0){
|
for(Rental_Apply_Equipment_Set__c raes : raesc){
|
//申请单任一个一览收货OK已回寄的,此单不满足延期条件
|
if ((raes.Received_Confirm__c == 'OK' || raes.Received_Confirm__c == '默认签收-OK') && raes.Asset_return_time__c != null) {
|
raescMap.put(raes.Rental_Apply__c, raes);
|
}
|
if(RentalApplyTriggerHandler.checkCan_Extend_Request(raes,false)){
|
raescMapTrue.put(raes.Rental_Apply__c,raes);
|
}
|
}
|
}
|
for(Rental_Apply__c rac : rentalApplyList){
|
//如果申请单为取消和删除状态,那么就不可以勾选
|
//延期申请时间(最初) 不为空,证明他已经延期过一回了,不需要再次延期(产品试用只能延期一回)
|
if(rac.RA_Status__c == '取消' || rac.RA_Status__c == '删除' || rac.ExtensionApplicationTime_Initial__c != null){
|
//tableData.add(new getTableData(rac,false));
|
}else{
|
//③可延期的申请单应满足:已出库的--已回收(不含)之间状态,且最新预定归还日≥ 今天
|
//没有满足上面的条件,页面置灰,并且也不可以选中
|
//当前日期
|
Date today = Date.today();
|
//预定归还日不能为空
|
if(rac.Return_dadeline_final__c != null){
|
//最新预定归还日≥ 今天。
|
if(rac.Return_dadeline_final__c >= today){
|
//多条数据,证明他需要批量延期,所有特殊处理
|
//可延期的申请单应满足:已出库的--已回收(不含)之间状态,且最新预定归还日≥ 今天。
|
if(rac.RA_Status__c == '申请者已收货' || rac.RA_Status__c == '医院已装机确认' || rac.RA_Status__c == '已出库')
|
{
|
//申请单任一个一览收货OK已回寄的,此单不满足延期条件
|
if(raescMap.containsKey(rac.Id)){
|
//tableData.add(new getTableData(rac,false));
|
}else{
|
if(raescMapTrue.containsKey(rac.Id)){
|
tableData.add(new getTableData(rac,true));
|
}
|
}
|
|
}
|
/*else{
|
tableData.add(new getTableData(rac,false));
|
}*/
|
}
|
/*else{
|
tableData.add(new getTableData(rac,false));
|
}*/
|
}
|
/*else{
|
tableData.add(new getTableData(rac,false));
|
}*/
|
}
|
}
|
}
|
}
|
}
|
//返回按钮
|
public PageReference senBackPage(){
|
PageReference ref = new Pagereference('/' + parentId);
|
ref.setRedirect(true);
|
return ref;
|
}
|
/**
|
* 根据传过来的备品id获取所有的从单和原单
|
* @param parentId 备品id
|
* @param rentalApplyType 如果为办事处,那么只查 试用有询价和无询价的单子 0 备品中心,1 办事处
|
* @return 返回所有的原单和从单
|
* 参数有可能是原单id或从单id
|
* 因为我们新增了一这样的逻辑,
|
* 如果是原单,并且没有分割单,那么他只判断自己本身是否满足条件,
|
* 如果为原单,并且有分割单,那么他也需要判断他下面的分割单是否满足条件
|
* 如果为分割单,那么他需要找到他的原单,并且查询此原单下的所有分割单是否满足条件
|
*/
|
public static List<Rental_Apply__c> getAllRentalApply(String parentId){
|
String likeParentId = parentId+'%';
|
List<Rental_Apply__c> allRentalApply = [SELECT id,
|
Name,
|
RA_Status__c,
|
Request_return_day__c,
|
demo_purpose1__c,
|
demo_purpose2__c,
|
ExtensionApprovalTime_Final__c,
|
RC_Ordered_Date__c,
|
Bollow_Date_Add_10_WD__c,
|
Loaner_received_ng_num__c,
|
ExtensionApprovalTime_Initial__c,
|
next_action__c,
|
NewRepair__c,
|
NewRepair__r.Agreed_Date__c,
|
NewRepair__r.Status__c,
|
NewRepair__r.ReRepairObject_F__c,
|
NewRepair__r.Repair_Shipped_Date__c,
|
AgreementBorrowingExtensionDate__c,
|
Return_dadeline_final__c,
|
loaner_Status__c,
|
Account__r.Department_Name__c,
|
Account__r.Name,
|
Account__c,
|
Split_Apply_Reason__c,
|
ExtensionApplicationTime_Initial__c,
|
Root_Rental_Apply__c
|
FROM Rental_Apply__c WHERE id = :parentId OR Root_Rental_Apply__c like :likeParentId
|
order by Name asc];
|
return allRentalApply;
|
}
|
|
public static List<Rental_Apply_Equipment_Set__c> getExtend_Request(String parentId){
|
String likeParentId = parentId+'%';
|
List<Rental_Apply_Equipment_Set__c> raes = [SELECT Id,Name
|
, Rental_Apply__c
|
, Rental_Apply__r.Repair__r.Agreed_Date__c
|
, Rental_Apply__r.Repair__r.Repair_Estimated_date_formula__c
|
, Rental_Apply__r.NewRepair__c
|
, Rental_Apply__r.NewRepair__r.Agreed_Date__c
|
, Rental_Apply__r.NewRepair__r.Status__c
|
, Rental_Apply__r.NewRepair__r.ReRepairObject_F__c
|
, Rental_Apply__r.NewRepair__r.Repair_Shipped_Date__c
|
, Rental_Apply__r.QISRepair__r.Repair_Shipped_Date__c
|
, Rental_Apply__r.RC_return_to_office__c
|
, Rental_Apply__r.AgreementBorrowingExtensionDate__c
|
, Rental_Apply__r.ExtensionApprovalTime_Initial__c
|
, Rental_Apply__r.ExtensionApplicationTime_Final__c
|
, Rental_Apply__r.RcUnexpectExpiryDelay__c
|
, Final_reply_day__c
|
, Asset_return_time__c
|
, Bollow_Date__c
|
, demo_purpose2__c
|
, demo_purpose1__c
|
, Request_demo_time__c
|
, Loaner_received_time__c
|
, Received_Confirm__c
|
, Loaner_received_day2__c
|
, RcUnexpectExpiryDelay__c
|
FROM Rental_Apply_Equipment_Set__c
|
WHERE (Rental_Apply__c = :parentId OR Root_Rental_Apply__c like :likeParentId)
|
AND Cancel_Reason__c = null];
|
return raes;
|
}
|
/**
|
* 为了方便前段table获取值
|
*/
|
class getTableData {
|
//数据
|
public Rental_Apply__c rentalApplyTable { get; set; }
|
//是否可以勾选
|
public Boolean canCheck { get; private set; }
|
|
public getTableData(Rental_Apply__c rat,Boolean checkFlag) {
|
this.canCheck = checkFlag;
|
this.rentalApplyTable = rat;
|
}
|
}
|
}
|