@isTest
public class SaleAndDeliveryControllerTest {
        static testMethod void SaleAndDeliveryTestinit(){
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectHos = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHos.size() == 0) {
            return;
        }
        Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id );
        Account myAccount2 = new Account(name='testaccount002',RecordTypeId = rectHos[0].Id );
        insert myAccount1;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id);
        insert core;
        user myUser_test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='testUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '北京');
        insert myUser_test;
        system.runAs(myUser_test){
            Consumable_order__c TestList5 = new Consumable_order__c(Name='Test5',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList6 = new Consumable_order__c(Name='Test6',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList7 = new Consumable_order__c(Name='Test7',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList3 = new Consumable_order__c(Name='Test3',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            Consumable_order__c TestList4 = new Consumable_order__c(Name='Test4',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Order_ProType__c = 'ET');
            TestList5.Order_date__c = Date.today().addDays(2);
            TestList6.Order_date__c = Date.today().addDays(2);
            TestList7.Order_date__c = Date.today().addDays(2);
            TestList1.Order_date__c = Date.today().addDays(2);
            TestList2.Order_date__c = Date.today().addDays(2);
            TestList3.Order_date__c = Date.today().addDays(2);
            TestList4.Order_date__c = Date.today();
            TestList5.Deliver_date__c=Date.today();
            TestList6.Deliver_date__c=Date.today();
            TestList7.Deliver_date__c=Date.today();
            TestList1.Deliver_date__c=Date.today();
            TestList2.Deliver_date__c=Date.today();
            TestList3.Deliver_date__c=Date.today();
            TestList4.Deliver_date__c=Date.today();
            insert new Consumable_order__c[]{TestList1,TestList2,TestList3,TestList4,TestList5,TestList6,TestList7};
            SaleAndDeliveryController CDC = new SaleAndDeliveryController();
            CDC.init1();
            CDC.SortLimited();
            System.assertEquals('Test1', CDC.raesList[0].name);
            System.assertEquals('Test2', CDC.raesList[1].name);
            System.assertEquals('Test3', CDC.raesList[2].name);
            System.assertEquals('Test4', CDC.raesList[3].name);
            System.assertEquals('Test5', CDC.raesList[4].name);
            System.assertEquals('Test6', CDC.raesList[5].name);
            System.assertEquals('Test7', CDC.raesList[6].name);
            CDC.cleanUp();
            System.assertEquals('Test1', CDC.raesList[0].name);
            System.assertEquals('Test2', CDC.raesList[1].name);
            System.assertEquals('Test3', CDC.raesList[2].name);
            System.assertEquals('Test4', CDC.raesList[3].name);
            System.assertEquals('Test5', CDC.raesList[4].name);
            System.assertEquals('Test6', CDC.raesList[5].name);
            System.assertEquals('Test7', CDC.raesList[6].name);
        }
    }
    static testMethod void SaleAndDeliveryTestOther(){
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectHos = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHos.size() == 0) {
            return;
        }
        Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id );
        Account myAccount2 = new Account(name='testaccount002',RecordTypeId = rectHos[0].Id );
        insert myAccount1;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id);
        insert core;
        user myUser_test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='testUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '北京');
        insert myUser_test;

        system.runAs(myUser_test){
            Consumable_order__c TestList5 = new Consumable_order__c(Name='Test5',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            Consumable_order__c TestList6 = new Consumable_order__c(Name='Test6',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            Consumable_order__c TestList7 = new Consumable_order__c(Name='Test7',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            Consumable_order__c TestList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            Consumable_order__c TestList3 = new Consumable_order__c(Name='Test3',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            Consumable_order__c TestList4 = new Consumable_order__c(Name='Test4',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true);
            TestList5.Order_date__c = Date.today().addDays(2);
            TestList6.Order_date__c = Date.today().addDays(2);
            TestList7.Order_date__c = Date.today().addDays(2);
            TestList1.Order_date__c = Date.today().addDays(2);
            TestList2.Order_date__c = Date.today().addDays(2);
            TestList3.Order_date__c = Date.today().addDays(2);
            TestList4.Order_date__c = Date.today();
            TestList5.Deliver_date__c=Date.today();
            TestList6.Deliver_date__c=Date.today();
            TestList7.Deliver_date__c=Date.today();
            TestList1.Deliver_date__c=Date.today();
            TestList2.Deliver_date__c=Date.today();
            TestList3.Deliver_date__c=Date.today();
            TestList4.Deliver_date__c=Date.today();
            insert new Consumable_order__c[]{TestList1,TestList2,TestList3,TestList4,TestList5,TestList6,TestList7};
            SaleAndDeliveryController CDC = new SaleAndDeliveryController();
            CDC.init1();
            CDC.category1='1';
            CDC.searchConsumableorderdetails();
            System.assertEquals('Test1', CDC.raesList[0].name);
            CDC.coc.Order_date__c = date.today();
            CDC.category1=null;
            CDC.searchConsumableorderdetails();
            CDC.SortLimited();
            System.assertEquals('Test1', CDC.raesList[0].name);
            CDC.neworderhead();
            SaleAndDeliveryController.getTitle();
        }
    }
    //已完成出库单检索
    static testMethod void SaleAndDeliveryTest_Finish(){
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectHos = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHos.size() == 0) {
            return;
        }
        Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id );
        Account myAccount2 = new Account(name='testaccount002',RecordTypeId = rectHos[0].Id );
        insert myAccount1;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id);
        insert core;
        user myUser_test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='testUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '北京');
        insert myUser_test;

        system.runAs(myUser_test){
            Consumable_order__c TestList5 = new Consumable_order__c(Name='Test5',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList6 = new Consumable_order__c(Name='Test6',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList7 = new Consumable_order__c(Name='Test7',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList3 = new Consumable_order__c(Name='Test3',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            Consumable_order__c TestList4 = new Consumable_order__c(Name='Test4',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Onchange_order__c = true,Order_ProType__c = 'ET');
            TestList5.Order_date__c = Date.today().addDays(2);
            TestList6.Order_date__c = Date.today().addDays(2);
            TestList7.Order_date__c = Date.today().addDays(2);
            TestList1.Order_date__c = Date.today().addDays(2);
            TestList2.Order_date__c = Date.today().addDays(2);
            TestList3.Order_date__c = Date.today().addDays(2);
            TestList4.Order_date__c = Date.today();
            TestList5.Deliver_date__c=Date.today();
            TestList6.Deliver_date__c=Date.today();
            TestList7.Deliver_date__c=Date.today();
            TestList1.Deliver_date__c=Date.today();
            TestList2.Deliver_date__c=Date.today();
            TestList3.Deliver_date__c=Date.today();
            TestList4.Deliver_date__c=Date.today();
            TestList5.Outbound_Date__c=Date.today().addDays(1);
            TestList6.Outbound_Date__c=Date.today().addDays(1);
            TestList7.Outbound_Date__c=Date.today().addDays(1);
            TestList1.Outbound_Date__c=Date.today().addDays(1);
            TestList2.Outbound_Date__c=Date.today().addDays(1);
            TestList3.Outbound_Date__c=Date.today().addDays(1);
            TestList4.Outbound_Date__c=Date.today().addDays(1);
            insert new Consumable_order__c[]{TestList1,TestList2,TestList3,TestList4,TestList5,TestList6,TestList7};
            SaleAndDeliveryController CDC = new SaleAndDeliveryController();
            CDC.init1();
            CDC.category1='Test';
            CDC.searchConsumableorFinish();
            CDC.SortLimited();
            System.assertEquals(5, CDC.raesList.size());
            CDC.neworderhead();
            CDC.sortKey='5';
            CDC.category2='Test02';
            CDC.searchConsumableorFinish();
            CDC.SortLimited();

        }
    }

    //未成出库单检索
    static testMethod void SaleAndDeliveryTest_Instatus(){
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectHos = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHos.size() == 0) {
            return;
        }
        Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id );
        Account myAccount2 = new Account(name='testaccount002',RecordTypeId = rectHos[0].Id );
        insert myAccount1;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id);
        insert core;
        user myUser_test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='testUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '北京');
        insert myUser_test;

        system.runAs(myUser_test){
            Consumable_order__c TestList5 = new Consumable_order__c(Name='Test5',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =1,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList6 = new Consumable_order__c(Name='Test6',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =2,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList7 = new Consumable_order__c(Name='Test7',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =3,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =4,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =5,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList3 = new Consumable_order__c(Name='Test3',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =6,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            Consumable_order__c TestList4 = new Consumable_order__c(Name='Test4',Summons_Sale_Status__c='出货',SummonsStatus_c__c='草案中',Order_ForHospital__c =myAccount2.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Dealer_info__c=myAccount1.Id,Total_Invoiced_Procount__c =7,InvoiceNotPro_total_amount__c =1,Order_ProType__c = 'ET');
            TestList5.Deliver_date__c = Date.today().addDays(2);
            TestList6.Deliver_date__c = Date.today().addDays(2);
            TestList7.Deliver_date__c = Date.today().addDays(2);
            TestList1.Deliver_date__c = Date.today().addDays(2);
            TestList2.Deliver_date__c = Date.today().addDays(2);
            TestList3.Deliver_date__c = Date.today().addDays(2);
            TestList4.Deliver_date__c = Date.today().addDays(2);
            TestList5.Order_date__c=Date.today();
            TestList6.Order_date__c=Date.today();
            TestList7.Order_date__c=Date.today();
            TestList1.Order_date__c=Date.today();
            TestList2.Order_date__c=Date.today();
            TestList3.Order_date__c=Date.today();
            TestList4.Order_date__c=Date.today();
            TestList5.Outbound_Date__c=Date.today().addDays(1);
            TestList6.Outbound_Date__c=Date.today().addDays(1);
            TestList7.Outbound_Date__c=Date.today().addDays(1);
            TestList1.Outbound_Date__c=Date.today().addDays(1);
            TestList2.Outbound_Date__c=Date.today().addDays(1);
            TestList3.Outbound_Date__c=Date.today().addDays(1);
            TestList4.Outbound_Date__c=Date.today().addDays(1);
            insert new Consumable_order__c[]{TestList1,TestList2,TestList3,TestList4,TestList5,TestList6,TestList7};
            SaleAndDeliveryController CDC = new SaleAndDeliveryController();
            CDC.init1();
            CDC.category1='Test';
            CDC.searchOrderInstatus();
            System.assertEquals(5, CDC.raesList.size());
            CDC.SortLimited();
            CDC.neworderhead();
            CDC.category2='Test02';
            CDC.searchOrderInstatus();
            CDC.sortKey='5';
            CDC.SortLimited();
        }
    }


}