public with sharing class LexOPDSupplementaryController {
    @AuraEnabled
    public static OPDPlan__c init(String recordId){
        try{
            OPDPlan__c res = [SELECT id,OPDPlan_ImplementDate__c,Status__c,
            OriginalOpdPlanRental__c,Rental_Apply2__c,Account_Laboratory__c,Related_Opportunity1_ID__c,
            PlanProdDetail__c,Cnt_OPD_LastYear__c,Cnt_OPD_ThisYear__c,Cnt_Rentals__c,
            lastMonth_Plan__c,SalesManager__c,OPDType__c,OriginalOpdPlanApplication__c,
            BuchangApprovalManagerSales__c,SalesManager_Txt__c,
            Name,supplementaryApplication__c 
                FROM OPDPlan__c
                    Where Id = : recordId];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return null;
    }

    @AuraEnabled
    public static OPDPlan__c getTheOPDPlan(String Id){
        try{
            OPDPlan__c res = [Select Id, Name,supplementaryApplication__c 
                FROM OPDPlan__c 
                    WHERE supplementaryApplication__c = true 
                    AND OriginalOpdPlanApplication__c = :Id];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return null;
    }


    @AuraEnabled
    public static OPDPlan__c init2(String recordId){
        try{
            OPDPlan__c res = [SELECT id,Status__c,RentalReson__c,AttachmentCertificate__c,
            NeedReport__c,PlanProdDetail__c,Related_Opportunity1_ID__c,Related_Opportunity2_ID__c
                FROM OPDPlan__c
                    Where Id = : recordId];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return null;       

    }

    @AuraEnabled
    public static String NewAndUpdateOPDStatus(String Id){
    try{
        OPDPlan__c res =new OPDPlan__c();
        res.Id = Id;
        res.Status__c='提交';
        update res;
        return 'success';
    }
    catch (Exception e) {
        System.debug(LoggingLevel.INFO, '*** e: ' + e);
        return e.getMessage();
    }
    }

    @AuraEnabled
    public static OPDPlan__c init3(String recordId){
        OPDPlan__c res = new OPDPlan__c();
        try{ 
            res = [SELECT Id,Name,Status__c,DelayCancel_Reason__c
            ,Account_Laboratory__c,OPDType__c,RentalReson__c,
            Related_Opportunity1_ID__c,
            CorrespondingRepairNo__c,AdditionalSupport__c,Campaign__c,
            NoOpp_Reason__c,ModelLending__c,ModelLendingProduct__c,
            PlanProdDetail__c 
                FROM  OPDPlan__c  WHERE Id = :recordId];

        }
        catch(Exception e){
        System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;

    }

    @AuraEnabled
    public static OPDPlan__c reapplyFindOPD(String Id){
        OPDPlan__c res =new OPDPlan__c();
        try{
            res =[SELECT Id, Name,Reapply__c 
                    FROM OPDPlan__c 
                        WHERE Reapply__c = true AND OriginalOpdPlan__c = :Id];
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //新建OPD计划（科室）  客户上的按钮
    @AuraEnabled
    public static Account  initNewOPDButton(String recordId){
        Account res = new Account();
        try{
            res = [SELECT Id,Is_Active__c 
                FROM Account 
                    WHERE Id=:recordId];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            return null;
        }
    }
        //新建OPD计划（询价）  询价上的按钮
    @AuraEnabled
    public static Opportunity  initNewOPDButton2(String recordId){
        Opportunity res = new Opportunity();
        try{
            res = [SELECT Id,AccountId,Name ,StageName
                FROM Opportunity 
                    WHERE Id=:recordId];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            return null;
        }
    }
}