public with sharing class SaveMaintenanceByCopyController {
    
    public String newid { get; set; }
    
    public void init() {
        String mid = ApexPages.currentPage().getParameters().get('mid');
        newid = ApexPages.currentPage().getParameters().get('newid');
        // 保有设备もコピー
        List<Maintenance_Contract_Asset__c> oldList = [select Asset__c from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :mid];
        List<Maintenance_Contract_Asset__c> newList = new List<Maintenance_Contract_Asset__c>();
        for (Maintenance_Contract_Asset__c mca : oldList) {
            newList.add(new Maintenance_Contract_Asset__c(
                Asset__c = mca.Asset__c,
                Maintenance_Contract__c = newid
            ));
        }
        
        if (newList.size() > 0) insert newList;
        // 维修合同更新
        Maintenance_Contract__c mc = [select Id from Maintenance_Contract__c where Id = :newid];
        mc.Contract_Conclusion_Date__c = null; //契約書締結日
        mc.Receipt_Date__c = null; //开发票日(最新)
        mc.Recycling_Predetermined_Day__c = null; //预计回款日
        mc.OCM_Print_request__c = null;//OCM盖章申請
        mc.Contract_print_completed__c = null; // 合同盖章完毕
        mc.HP_Dealer_print__c =null; //医院（经销商）印
        mc.Description__c = null; //説明
        mc.PA_Contrant_Cnt__c = null; //PB合同点检次数
        mc.PB_Contrant_Cnt__c =null; //PA合同点检次数
        mc.Service_contract_target_number__c = null; //合同约定点检次数
        mc.invoice_amount__c = null;
        mc.Recoverable_Amount__c = null;
        mc.Total_not_collect_amount__c = null;
        mc.Finally_Approved_Staff__c = null;
        mc.JingliApprovalManager__c = null;
        mc.BuchangApprovalManager__c = null;
        mc.ZongjianApprovalManager__c = null;
        mc.Estimate_Trial_Money__c = null;
        mc.Contract_Amount__c = null;
        mc.Service_contract_target_number__c = null;
        mc.Contract_Start_Date__c = null;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
        mc.Contract_End_Date__c = null;
        mc.Not_collect_money__c = null; //// 
        mc.Received_Date__c = null;   ////
        mc.NotUse_Oxygenated_Water__c = false;
        mc.CopyFlg__c = true;
        mc.TKZongjianApprovalManager__c = null;
        update mc;
    }
}