@isTest
private class OrdergoodsControllerTest {
    public String ProModel;
    static testMethod void testMethod1() {
        // 客户记录类型
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 办事处 recodetype');
        }
        Account account2 = new Account();
		account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        // 客户
        Account account = new Account();
        account.RecordTypeId = rectCo[0].Id;
        account.Phone = '13888888888';
        account.Name = 'Katsu テスト';
        account.Quolified_Approve_Status__c = 'Draft';
        account.If_Need_Quolified__c = true;
        account.ParentId = account2.Id;
        insert account;

        Product2 product = new Product2();
        product.Name = 'test01';
        product.ProductCode = 'n011';
        product.Packing_list_manual__c = 5;
        product.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product.Asset_Model_No__c = 'n01';
        product.Whether_Sample__c = true;
        product.StorageStatusNo__c = 10;
        product.SFDA_Status__c = '有効';
        insert product;
        product.StorageStatusNo__c = 20;
        update product;
        Product2 product1 = new Product2();
        product1.Name = 'test012';
        product1.ProductCode = 'n01112';
        product1.Packing_list_manual__c = 5;
        product1.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product1.Asset_Model_No__c = 'n011';
        product1.Whether_Sample__c = true;
        product1.StorageStatusNo__c = 10;
        product1.SFDA_Status__c = '有効';
        insert product1;
        product1.StorageStatusNo__c = 20;
        update product1;
        Product2 product2 = new Product2();
        product2.Name = 'test01222';
        product2.ProductCode = 'n0111212';
        product2.Packing_list_manual__c = 5;
        product2.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product2.Asset_Model_No__c = 'n0311';
        product2.Whether_Sample__c = true;
        product2.StorageStatusNo__c = 10;
        product2.SFDA_Status__c = '有効';
        insert product2;
        product2.StorageStatusNo__c = 20;
        update product2;

        // 订货单
        Sample_order_list__c samOrder = new Sample_order_list__c();
        samOrder.Status__c          = ''; 
        samOrder.DeliveryAddress__c = '';
        samOrder.DeliveryPhone__c   = '12312312';
        samOrder.DeliveryContact__c = 'thh';
        samOrder.ReceivePart__c     = '办事处';
        samOrder.Account__c         = account.Id;
        insert samOrder;
        Sample_order_list__c samOrder2 = new Sample_order_list__c();
        samOrder2.Status__c          = ''; 
        samOrder2.DeliveryAddress__c = '123213';
        samOrder2.DeliveryPhone__c   = '';
        samOrder2.DeliveryContact__c = 'thh';
        samOrder2.ReceivePart__c     = '办事处';
        samOrder2.Account__c         = account.Id;
        insert samOrder2;
        Sample_order_list__c samOrder3 = new Sample_order_list__c();
        samOrder3.Status__c          = ''; 
        samOrder3.DeliveryAddress__c = '123213';
        samOrder3.DeliveryPhone__c   = '12312312';
        samOrder3.DeliveryContact__c = '';
        samOrder3.ReceivePart__c     = '办事处';
        samOrder3.Account__c         = account.Id;
        insert samOrder3;
        Sample_order_list__c samOrder1 = new Sample_order_list__c();
        samOrder1.Status__c          = '暂存'; 
        samOrder1.DeliveryAddress__c = '12312';
        samOrder1.DeliveryPhone__c   = '12312312';
        samOrder1.DeliveryContact__c = 'thh';
        samOrder1.ReceivePart__c     = '办事处';
        samOrder1.Account__c         = account.Id;
        insert samOrder1;

        // 订货单明细
        Sample_order_list_detail__c samDetail = new Sample_order_list_detail__c();
        samDetail.Product__c           = product.Id;
        samDetail.Pro_model__c         = 'n01';
        samDetail.ItemQuantity__c      = 100;
        samDetail.Standards__c         = 1;
        samDetail.Sample_order_list__c = samOrder.Id;
        insert samDetail;
        Sample_order_list_detail__c samDetail1 = new Sample_order_list_detail__c();
        samDetail1.Product__c           = product1.Id;
        samDetail1.Pro_model__c         = 'n011';
        samDetail1.ItemQuantity__c      = 100;
        samDetail1.Standards__c         = 1;
        samDetail1.Sample_order_list__c = samOrder1.Id;
        insert samDetail1;

        // 页面获取的订货单Id
        PageReference ref1 = new PageReference('/apex/Ordergoods?id=' + samOrder.id);
        Test.setCurrentPage(ref1);
        OrdergoodsController controller1 = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller1.init();
        controller1.save();
        controller1.confirmBtn();
        PageReference ref3 = new PageReference('/apex/Ordergoods?id=' + samOrder2.id);
        Test.setCurrentPage(ref3);
        OrdergoodsController controller3 = new OrdergoodsController(new ApexPages.StandardController(samOrder2));
        controller3.init();
        controller3.save();
        PageReference ref4 = new PageReference('/apex/Ordergoods?id=' + samOrder3.id);
        Test.setCurrentPage(ref4);
        OrdergoodsController controller5 = new OrdergoodsController(new ApexPages.StandardController(samOrder3));
        controller5.init();
        controller5.save();
        PageReference ref2 = new PageReference('/apex/Ordergoods?id=' + samOrder1.id);
        Test.setCurrentPage(ref2);
        OrdergoodsController controller2 = new OrdergoodsController(new ApexPages.StandardController(samOrder1));
        controller2.init();
        controller2.save();
        controller2.confirmBtn();

        // 页面获取的客户Id
        PageReference ref = new PageReference('/apex/Ordergoods?accid=' + account.id);
        Test.setCurrentPage(ref);
        OrdergoodsController controller = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller.init();
        //controller.productInfoList[0].check = true;
        //controller.productInfoList[0].SOLDel.ItemQuantity__c = 5;
        // controller.save();
        // controller.confirmBtn();
        //controller.productInfoList = new List<OrdergoodsController.ProductInfo>();
        // controller.productInfoList.add(new OrdergoodsController.ProductInfo(0,product)); 
    }

    static testMethod void testMethod2() {
        // 客户记录类型
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 办事处 recodetype');
        }
        // 客户
        Account account2 = new Account();
		account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        Account account = new Account();
        account.RecordTypeId = rectCo[0].Id;
        account.Phone = '13888888888';
        account.Name = 'Katsu テスト';
        account.Quolified_Approve_Status__c = 'Draft';
        account.If_Need_Quolified__c = true;
        account.ParentId = account2.Id;
        insert account;
        //查不出任何样本品,SFDA_Status__c会被触发器修改为停止
        Product2 product = new Product2();
        product.Name = 'test01';
        product.ProductCode = 'n011';
        product.Packing_list_manual__c = 5;
        product.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product.Asset_Model_No__c = 'n01';
        product.Whether_Sample__c = true;
        product.StorageStatusNo__c = 10;
        product.SFDA_Status__c = '有効';
        insert product;
        product.StorageStatusNo__c = 20;
        update product;

        Sample_order_list__c samOrder = new Sample_order_list__c();
        samOrder.Status__c          = '暂存'; 
        samOrder.DeliveryAddress__c = '12332';
        samOrder.DeliveryPhone__c   = '12312312';
        samOrder.DeliveryContact__c = 'thh';
        samOrder.ReceivePart__c     = '办事处';
        samOrder.Account__c         = account.Id;
        insert samOrder;

        //选中保存
        Sample_order_list_detail__c samDetail = new Sample_order_list_detail__c();
        samDetail.Product__c           = product.Id;
        samDetail.Pro_model__c         = 'n01';
        // samDetail.ItemQuantity__c      = 100;
        samDetail.Standards__c         = 1;
        samDetail.Sample_order_list__c = samOrder.Id;
        insert samDetail;

        PageReference ref2 = new PageReference('/apex/Ordergoods?id=' + samOrder.id);
        Test.setCurrentPage(ref2);
        OrdergoodsController controller2 = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller2.init();
        controller2.save();
        controller2.confirmBtn();
    }
}