// xudan 20160106 Arrival_wh_time__c -> Arrival_wh_time2__c(回库はSet単位なので、積み上げ項目使わず) public without sharing class TransferShippmentReceived1Controller { public List esdList { get; set; } public Boolean saveBtnDisabled { get; private set; } public String SR_status { get; private set; } public String Step_status { get; private set; } public String open_type { get; private set; } public Boolean done_flg { get; set; } public String Raid {get;set;} private String Id; public Integer getEsdListSize() { return esdList.size(); } public TransferShippmentReceived1Controller() { Id = ApexPages.currentPage().getParameters().get('id'); if (SR_status == null) { SR_status = ApexPages.currentPage().getParameters().get('type'); } if (Step_status == null) { Step_status = ApexPages.currentPage().getParameters().get('step'); } if (open_type == null) { open_type = ApexPages.currentPage().getParameters().get('open'); } } // 画面初始化 public PageReference init() { esdList = new List(); done_flg = false; Set esIds = new Set(); saveBtnDisabled = false; if (Id != null) { //一览id分割 List ids = Id.split(','); // 当前User String userid = Userinfo.getUserId(); User user = [select Id,Name from User where Id = :userid]; // 备品set List esList = [select Yi_StockDown__c, Cancel_Select__c, TransferApply__c, Id, TAS_Status__c, Name, Shippment_loaner_time2__c from TransferApplySummary__c where (TransferApply__r.Name in :ids or Id in :Ids) AND Cancel_Select__c = False ]; if (esList.size() > 0) { for (TransferApplySummary__c raes : esList) { if (raes.Yi_StockDown__c > 0 || raes.Cancel_Select__c == false) { esIds.add(raes.Id); Raid = raes.TransferApply__c; } } } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '备品不存在')); saveBtnDisabled = true; return null; } } // 备品set明细 List eList = [ select SerialNumber_F__c, OneToOneAccessory__c, Main_OneToOne__c, TransferApplySummary__c , FSD_OneToOneAccessory_Cnt__c, Pre_After_Inspection_elapsed_days__c, Asset__r.WH_location__c , Approved_F__c, Fixture_Name_F__c, TransferApplySummary__r.Fixture_Set__r.Name , Fixture_QRCode_F__c, TransferApplySummary__r.Name, Pre_inspection_time__c, StockDown__c , StockDown_time__c, Id, Name, Asset__c, Asset__r.Name, Asset__r.SerialNumber, Asset__r.Product_Serial_No__c, Asset__r.Remark__c, Asset__r.ImageAsset__c, Asset__r.ImageSerial__c, Asset__r.ImageAssetUploadedTime__c, Asset__r.ImageSerialUploadedTime__c, Loaner_CDS_Info__c, Inspection_result__c, Check_lost_Item__c, Pre_disinfection__c, Water_leacage_check__c, Inspection_result_after__c, Arrival_in_wh__c, Asset__r.Pre_Reserve_TAES_Detail__c, Asset__r.Pre_Reserve_TAES_Detail__r.After_Inspection_time__c, Inspection_result_after_ng__c, Inspection_result_ng__c, Lost_item_giveup__c, CDS_complete__c, Loaner_accsessary__c from TransferApplyDetail__c where TransferApplySummary__c in :esIds AND Cancel_Select__c = False order by TransferApplySummary__r.Name, TransferApplySummary__c, Name ]; for (TransferApplyDetail__c esd : eList) { EsdInfo ei = new EsdInfo(esd); if(esd.Inspection_result__c == null) { ei.editable = esd.Approved_F__c; } esdList.add(ei); } Step_status = '下架'; if (esdList.size() <= 0) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '没有备品set明细')); saveBtnDisabled = true; return null; } system.debug('=====' + Step_status); system.debug('=====' + open_type); return null; } // Step 切り替えボタン、发货前-检测 public PageReference Shippment1() { Step_status = '发货前'; return new PageReference('/apex/TransferShippmentReceived2?id=' + this.Id + '&type=' + this.SR_status + '&step=' + this.Step_status + '&open=' + this.open_type); } // 保存按钮 public PageReference save() { //检查是否可以继续 TransferApply__c RaTar = [select Campaign__c,Repair__c,Status__c, Campaign__r.Status,repair__r.Return_Without_Repair_Date__c,Repair__r.Repair_Final_Inspection_Date__c,Repair__r.Repair_Shipped_Date__c from TransferApply__c where id=:Raid]; if( RaTar.Campaign__r.Status == '取消'){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '学会已取消,不能继续操作了')); return null; }else if( RaTar.Repair__r.Repair_Final_Inspection_Date__c!=null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '存在修理最终检测日,不能继续了')); return null; }else if( RaTar.repair__r.Return_Without_Repair_Date__c!=null&&RaTar.repair__c!=null ){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '未修理归还日不为空,不能出库')); return null; }else if( RaTar.Repair__r.Repair_Shipped_Date__c!=null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '存在RC修理返送日,不能继续了')); return null; } String userid = Userinfo.getUserId(); List eList = new List(); Map stockDownMap = new Map(); for (EsdInfo esdInfo : esdList) { if (!esdInfo.editable) continue; TransferApplyDetail__c esd = esdInfo.rec; eList.add(esd); stockDownMap.put(esd.Id, esd.StockDown__c); } Boolean needSaveSet = false; Boolean needSaveDetail = false; List updateList = [select Id, Approved_F__c from TransferApplyDetail__c where Id in :eList for update]; for (TransferApplyDetail__c upd : updateList) { if (!upd.Approved_F__c && stockDownMap.get(upd.Id)) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '明细未批准,不能下架')); break; } } if (ApexPages.hasMessages(ApexPages.severity.Error)) { done_flg = false; return null; } // TODO 没变化不存 List upsertList = new List(); Datetime now = System.Now(); if (Step_status == '下架') { for (TransferApplyDetail__c esd : eList) { if (esd.StockDown__c == true && esd.StockDown_time__c == null) { upsertList.add(new TransferApplyDetail__c(id = esd.id , Shipment_request_time2__c = now , StockDown__c = true , StockDown_time__c = now , StockDown_staff__c = userid )); } if (esd.StockDown__c == false) { upsertList.add(new TransferApplyDetail__c(id = esd.id , Shipment_request_time2__c = null , StockDown__c = false , StockDown_time__c = null , StockDown_staff__c = null )); } } needSaveDetail = true; } Savepoint sp = Database.setSavepoint(); try { if (needSaveDetail){ if(RaTar.Status__c != '已出库指示') { RaTar.Status__c = '已出库指示'; FixtureUtil.withoutUpdate(new List {RaTar}); } FixtureUtil.withoutUpsertObjects(upsertList); init(); } done_flg = true; } catch (Exception ex) { system.debug('=====' + ex.getMessage()); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()+'( '+Step_status+' )')); Database.rollback(sp); done_flg = false; } return null; } // Step 切り替えボタン、发货-发货运输单号 等 public PageReference Shippment2() { return new PageReference('/apex/TransferShippmentReceived2?id=' + this.Id); } public class EsdInfo { public TransferApplyDetail__c rec { get; set; } public String imageAssetUploadedTime { get; set; } public String imageSerialUploadedTime { get; set; } // 回库はSet単位で、明細一つ一つのquickCheck要らない public boolean quickCheck { get; set; } public boolean editable { get; set; } public String fsName {get;set;} public String tasId {get;set;} public EsdInfo(TransferApplyDetail__c rec) { this.rec = rec; this.editable = false; this.fsName = rec.TransferApplySummary__r.Name; if(String.isNotBlank(rec.TransferApplySummary__r.Fixture_Set__r.Name)){ this.fsName += ':' + rec.TransferApplySummary__r.Fixture_Set__r.Name; } this.tasId = rec.TransferApplySummary__r.Id; if (rec.Asset__r.Pre_Reserve_TAES_Detail__c != null && rec.Asset__r.Pre_Reserve_TAES_Detail__r.After_Inspection_time__c != null) { this.quickCheck = Datetime.now() < rec.Asset__r.Pre_Reserve_TAES_Detail__r.After_Inspection_time__c + 30 ? true : false; } else { this.quickCheck = false; } if (rec.Asset__r.ImageAssetUploadedTime__c != null) { imageAssetUploadedTime = rec.Asset__r.ImageAssetUploadedTime__c.format('yyyy/MM/dd HH:mm'); } if (rec.Asset__r.ImageSerialUploadedTime__c != null) { imageSerialUploadedTime = rec.Asset__r.ImageSerialUploadedTime__c.format('yyyy/MM/dd HH:mm'); } } } }