/**
 * @description       : 
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             : 
 * @last modified on  : 04-21-2022
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@isTest
private class loanerAppTriggerHandlerTest {
	
	@isTest static void test_method_one() {

        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc111 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc112 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc113 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc114 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc115 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc116 = new OlympusCalendar__c(Date__c = Date.today().addDays(-6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc117 = new OlympusCalendar__c(Date__c = Date.today().addDays(-7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc118 = new OlympusCalendar__c(Date__c = Date.today().addDays(-8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc119 = new OlympusCalendar__c(Date__c = Date.today().addDays(-9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc1110 = new OlympusCalendar__c(Date__c = Date.today().addDays(-10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc1111 = new OlympusCalendar__c(Date__c = Date.today().addDays(-11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc1112 = new OlympusCalendar__c(Date__c = Date.today().addDays(-12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc221 = new OlympusCalendar__c(Date__c = Date.today().addDays(-13), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc222 = new OlympusCalendar__c(Date__c = Date.today().addDays(-14), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc223 = new OlympusCalendar__c(Date__c = Date.today().addDays(-15), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc224 = new OlympusCalendar__c(Date__c = Date.today().addDays(-16), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc225 = new OlympusCalendar__c(Date__c = Date.today().addDays(-17), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc226 = new OlympusCalendar__c(Date__c = Date.today().addDays(-18), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc227 = new OlympusCalendar__c(Date__c = Date.today().addDays(-19), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc228 = new OlympusCalendar__c(Date__c = Date.today().addDays(-20), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc229 = new OlympusCalendar__c(Date__c = Date.today().addDays(-21), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2210 = new OlympusCalendar__c(Date__c = Date.today().addDays(-22), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2211 = new OlympusCalendar__c(Date__c = Date.today().addDays(-23), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2212 = new OlympusCalendar__c(Date__c = Date.today().addDays(-24), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc331 = new OlympusCalendar__c(Date__c = Date.today().addDays(-25), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc332 = new OlympusCalendar__c(Date__c = Date.today().addDays(-26), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc333 = new OlympusCalendar__c(Date__c = Date.today().addDays(-27), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc334 = new OlympusCalendar__c(Date__c = Date.today().addDays(-28), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc335 = new OlympusCalendar__c(Date__c = Date.today().addDays(-29), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc336 = new OlympusCalendar__c(Date__c = Date.today().addDays(-30), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc337 = new OlympusCalendar__c(Date__c = Date.today().addDays(-31), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc338 = new OlympusCalendar__c(Date__c = Date.today().addDays(-32), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc339 = new OlympusCalendar__c(Date__c = Date.today().addDays(-33), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3310 = new OlympusCalendar__c(Date__c = Date.today().addDays(-34), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3311 = new OlympusCalendar__c(Date__c = Date.today().addDays(-35), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3312 = new OlympusCalendar__c(Date__c = Date.today().addDays(-36), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3313 = new OlympusCalendar__c(Date__c = Date.today().addDays(-37), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3314 = new OlympusCalendar__c(Date__c = Date.today().addDays(-38), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3315 = new OlympusCalendar__c(Date__c = Date.today().addDays(-39), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3316 = new OlympusCalendar__c(Date__c = Date.today().addDays(-40), ChangeToHoliday__c=false, ChangeToWorkday__c=true);

        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc111, oc112 ,oc113, oc114, oc115, oc116, oc117, oc118, oc119, oc1110,oc1111,oc1112,oc221, oc222, oc223, oc224, oc225, oc226, oc227, oc228, oc229, oc2210,oc2211,oc2212,oc331, oc332, oc333, oc334, oc335, oc336, oc337, oc338, oc339, oc3310,oc3311,oc3312,oc3313,oc3314,oc3315,oc3316};
		// Implement test code
		List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];   
      
       // 新建备品借出申请
        loaner_application__c loaner = new loaner_application__c();
        loaner.Name = 'TEST';
        loaner.RecordTypeId = rectLo[0].id;
        loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
        loaner.DEMO_PURPOSE__C = '演示';
        loaner.Request_shipping_Date__c = Date.today().addDays(4);
        loaner.Request_return_Date__c = Date.today().addDays(5);
        loaner.Status__c = '已出库指示';
        loaner.Return_Track_Company__c = '物流公司';
        //loaner.pickup_time__c = Date.today().addDays(3);
        //loaner.Return_Trake_Staff__c = '返品人';
        insert loaner;
	}
	
	@isTest static void test_method_two() {

		OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);

        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12};
		List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];   
       	List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        // 新建备品借出申请
        loaner_application__c loaner = new loaner_application__c();
        loaner.Name = 'TEST';
        loaner.RecordTypeId = rectLo[0].id;
        loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
        loaner.DEMO_PURPOSE__C = '演示';
        loaner.Request_shipping_Date__c = Date.today().addDays(10);
        loaner.Request_return_Date__c = Date.today().addDays(10);
        // loaner.Status__c = '已提交';
        loaner.Status__c = '申请中';
        loaner.Return_Track_Company__c = '物流公司';
        loaner.Loaner_receive_staff__c = '1';
        loaner.direct_shippment_address__c = '1';
        loaner.Loaner_receive_staff_phone__c = '1';
        loaner.Post_Code__c = '1';
        loaner.Follow_Opp__c = '0060T0000049Tm1QAE';
        //loaner.pickup_time__c = Date.today().addDays(3);
        //loaner.Return_Trake_Staff__c = '返品人';
        insert loaner;
        // 新建 客户
        Account acc = new Account();
        acc.RecordTypeId = rectCo[0].Id;
        acc.Name         = '客户テスト1';
        acc.DivisionName__c = 'DivisionName__c';
        acc.FacilityName__c = 'FacilityName__c';
        acc.PostCode__c='000000';
        insert acc;

        List<Asset> In_asset = new List<Asset>();

        Asset asset = new Asset();
        asset.Name = 'テスト機器1';
        asset.AccountId = acc.Id;
        asset.SerialNumber = 'testserial';
        asset.Status = '在库';
        In_asset.add(asset);

        asset = new Asset();
        asset.Name = 'テスト機器2';
        asset.AccountId = acc.Id;
        asset.SerialNumber = 'testserial';
        In_asset.add(asset);

        asset = new Asset();
        asset.Name = 'テスト機器3';
        asset.AccountId = acc.Id;
        asset.SerialNumber = 'testserial';
        In_asset.add(asset);

        insert In_asset;


        // 新建 借出明细
        List<loaner_application_detail__c> In_detail = new List<loaner_application_detail__c>();
        loaner_application_detail__c detail = new loaner_application_detail__c();

        detail.loaner_application__c = loaner.Id;
        detail.loaner__c = In_asset[0].id;
        detail.name = '000';
        detail.RAESD_STATUS__C = '已分配';
        In_detail.add(detail);

        detail = new loaner_application_detail__c();
        detail.loaner_application__c = loaner.Id;
        detail.loaner__c = In_asset[1].id;
        detail.name = '111';
        detail.RAESD_STATUS__C = '已分配';
		//detail.Shipment_Request_Date__c = Date.today();
        In_detail.add(detail);

        detail = new loaner_application_detail__c();
        detail.loaner_application__c = loaner.Id;
        detail.loaner__c = In_asset[2].id;
        detail.name = '222';
        detail.RAESD_STATUS__C = '已分配';
        In_detail.add(detail);

        insert In_detail;
System.Test.startTest();
        loaner.Status__c  = '申请中';
        loaner.Rental_End_Date__c = Date.today().addDays(10);
        update loaner;

        loaner.Status__c = '驳回';
        update loaner;

		loaner.Status__c  = '申请中';
        loaner.Rental_End_Date__c = Date.today().addDays(10);
        update loaner;

        loaner.Status__c = '销售担当批准';
        update loaner;

        loaner.Status__c = '已批准';
        loaner.Rental_Start_Date__c = Date.today().addDays(9);
        loaner.Rental_End_Date__c = Date.today().addDays(10);
        update loaner;

        loaner.Status__c = '取消';
        update loaner;

        loaner.Status__c = '草案中';
        loaner.Equipment_Type__c = 'BS';
        loaner.Follow_Opp__c = '0060T000003zTzNQAU';
        update loaner;

        loaner.Status__c = '申请中';
        update loaner;

        loaner.Status__c = '草案中';
        loaner.Equipment_Type__c = 'BS';
        loaner.Loaner_LendOrder__c = true;
        update loaner;

        loaner.Status__c = '申请中';
        loaner.Equipment_Type__c = 'BS';
        loaner.Loaner_LendOrder__c = true;
        update loaner;

        System.Test.stopTest();
	}
	
}