@isTest
private class LexConInvoiceViewControllerTest { //新建发票 以及编辑发票 invoiceId<>null
  public static user myUser_test;
  public static Account myAccount1;
  public static Account hosp1;
  public static Account agency1;
  public static List<RecordType> rectHos;
  public static Account agency2;
  @testSetup
  static void setupTestData() {
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      // Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
      Profile prof = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET)'
      ];
      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;
      }
      //二级经销商SecondDealer
      agency1 = new Account(
        name = 'Testhosp001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id
      );
      agency2 = new Account(
        name = 'Testhosp002',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id
      );
      //经销商
      myAccount1 = new Account(
        name = 'Testaccount002',
        Dealer_discount__c = 20,
        RecordTypeId = rectCo[0].Id
      );
      insert agency1;
      insert agency2;
      insert myAccount1;
      //客户名HospitalInfo
      hosp1 = new Account(
        name = 'Testhosp001',
        Dealer_discount__c = 10,
        RecordTypeId = rectHos[0].Id
      );
      Account hosp2 = new Account(
        name = 'Testhosp002',
        Dealer_discount__c = 10,
        RecordTypeId = rectHos[0].Id
      );
      insert hosp1;

      Dealer_elationship__c dealerelationship = new Dealer_elationship__c(
        Dealer_principal__c = myAccount1.id,
        Dealer_subordinate__c = agency1.id
      );
      insert dealerelationship;
      Dealer_elationship__c dealerelationship1 = new Dealer_elationship__c(
        Dealer_principal__c = myAccount1.id,
        Dealer_subordinate__c = agency2.id
      );
      insert dealerelationship1;

      Agency_Hospital_Link__c agencyHospitalLink1 = new Agency_Hospital_Link__c(
        Hospital__c = hosp1.id,
        Agency__c = myAccount1.id
      );
      insert agencyHospitalLink1;

      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      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;
    }

  }
  static testMethod void conInvoiceViewTestedit_1() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];

    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      // invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      System.Test.startTest();
      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;

      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = invoiceorder.Id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3
      };

      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.saveAttachment(
        JSON.serialize(LexConInvoiceViewController.attachmentRecoeds),
        invoiceorder.Id
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      LexConInvoiceViewController.deleteButton(testList1.Id, testList1);
      LexConInvoiceViewController.deleteButton('234567', testList1);
      // LexConInvoiceViewController.saveFile(invoiceorder.Id,'Test','TmFtZSxTdW1tb25zRm9yRGlyY3Rpb25fX2MsSG9zcGl0YWxDb2RlLE9yZGVyX0Zvckhvc3BpdGFsX19jLE9yZGVyX0ZvckN1c3RvbWVyVGV4dF9fYyxPcmRlcl9Gb3JEZWFsZXJfX2MsQmFyX0NvZGVfX2MsU2hpcG1lbnRfQ291bnRfX2MsRGVsaXZlcnlfTGlzdF9STUJfX2MsQm94X1BpZWNlX19jLFVuaXRwcmljZV9Ub19hZ2VuY3lfX2MsT3V0Ym91bmRfRGF0ZV9fYyxMb3NlX3JlYXNvbl9fYw0KREItRlkyMDI0LTA2LVozMTAwMDIs55u05o6l6ZSA5ZSu57uZ5Yy76ZmiLDgxMDU2NDAs5a6955S45Lic5qGl5bq35aSN5Yy76ZmiLOa2iOWMluenkSwsMTY4NjIwMzI1NDQ2ODI1MFZWR0lVLDEsMjAwMCznm5IsMjAsMjAyMy82Lzgs5Lii5aSx5Y6f5ZugDQpEQi1GWTIwMjQtMDYtWjMxMDAwMyznm7TmjqXplIDllK7nu5nljLvpmaIsODEwNTY0MCzlrr3nlLjkuJzmoaXlurflpI3ljLvpmaIs5raI5YyW56eRLCwxNjg2MjAzMjU2MDk4MjUwUkVKT1EsMSwzMDAwLOebkiwyMCwyMDIzLzYvOCzkuKLlpLHljp%2Flm6ANCkRCLUZZMjAyNC0wNi1aMzEwMDA0LOebtOaOpemUgOWUrue7meWMu%2BmZoiw4MTA1NjQwLOWuveeUuOS4nOahpeW6t%2BWkjeWMu%2BmZoizmtojljJbnp5EsLDE2ODYyMDMyNTc2NTcyNTBHU0ZTQiwxLDQwMDAs55uSLDIwLDIwMjMvNi84LOS4ouWkseWOn%2BWboA0K');
      try {
        LexConInvoiceViewController.saveFile(invoiceorder.Id, 'Test', '');
      } catch (Exception e) {
        system.debug('Test');
      }
      LexConInvoiceViewController.outbound = testList2;
      LexConInvoiceViewController.getInvoiceName();
      // LexConInvoiceViewController.shipmentAccount = '222';
      Map<String, Decimal> ordermx1defaultMap = new Map<String, Decimal>();
      LexConInvoiceViewController.ordermx1defaultMap = ordermx1defaultMap;
      Map<String, String> deleteMap = new Map<String, String>();
      LexConInvoiceViewController.deleteOutboundorder(deleteMap, '');
      // LexConInvoiceViewController.invoiceOrderRecoedsCount
      LexConInvoiceViewController.orderby = new List<String>{
        'Outbound_Date__c',
        'Name',
        'ShipmentAccount__c'
      };
      LexConInvoiceViewController.sortKey = 'test';
      LexConInvoiceViewController.preSortKey = 'test';
      LexConInvoiceViewController.sortOrderAsc = false;
      LexConInvoiceViewController.sortOrder = new List<String>{
        'Outbound_Date__c',
        'Name',
        'ShipmentAccount__c'
      };
      List<LexConInvoiceViewController.InvoiceOrderInfo> test1 = new List<LexConInvoiceViewController.InvoiceOrderInfo>();
      List<String> chukudanID = new List<String>();
      chukudanID.add(testList2.Id);
      chukudanID.add(testList1.Id);
      LexConInvoiceViewController.newinvoicedetails1(chukudanID);
      Map<String, String> insertDetMap = new Map<String, String>();
      insertDetMap.put('Outboundorder_Code_link__c', testList1.Id);
      // LexConInvoiceViewController.outOrderchange(insertDetMap);
      LexConInvoiceViewController.getdefaultMapinfo(chukudanID);

      System.Test.stopTest();
    }
  }

  //新建发票 invoiceId=null

  static testMethod void conInvoiceViewTestedit_2() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      // invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      System.Test.startTest();
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );

      // LexConInvoiceViewController.HospitalInfo = hosp1.id;
      System.Test.stopTest();
    }
  }
  //新建发票 invoiceId=null error check

  static testMethod void conInvoiceViewTestedit_3() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      insert new List<Product2__c>{ pro1 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      PageReference page = new PageReference(
        '/apex/ConInvoiceView?invoiceId=' +
          invoiceorder.Id +
          '&KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);
      System.Test.startTest();

      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );

      // LexConInvoiceViewController.init();

      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      // LexConInvoiceViewController.coc.SummonsForDirction__c = '直接销售给医院';
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      System.debug('===>hosp1.id' + hosp1.id);
      LexConInvoiceViewController.invoiceId = null;
      System.Test.stopTest();
    }
  }

  //新建发票 以及编辑发票invoiceId== NULL and deliveryId== NULL
  static testMethod void conInvoiceViewTestinit() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];

    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单
      //Consumable_order__c testList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);
      //Consumable_order__c testList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      //insert new Consumable_order__c[]{testList1,testList2};

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable2',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable2;
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_002001';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Shipment_Count__c = 1;
      orderdet3.Consumable_product__c = pro2.Id;

      //出库单2明细2
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test1_002002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList2.id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Shipment_Count__c = 1;
      orderdet4.Consumable_product__c = pro2.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3,
        orderdet4
      };
      //附件
      Consumable_accessories_invoice__c caic = new Consumable_accessories_invoice__c();
      caic.Attachment_ID__c = acc.Id;
      caic.Accessories_type__c = '发票和明细';
      caic.Invoice_code__c = invoiceorder.id;
      insert caic;
      PageReference page = new PageReference(
        '/apex/ConInvoiceView?KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      //contest.deliveryId=testList1.id;
      System.Test.startTest();
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      System.Test.stopTest();
    }
  }

  //新建发票 以及编辑发票invoiceId== NULL and deliveryId<> NULL
  static testMethod void conInvoiceViewTestinit_1() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单
      //Consumable_order__c testList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);
      //Consumable_order__c testList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      //insert new Consumable_order__c[]{testList1,testList2};

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable2',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable2;
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_002001';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Shipment_Count__c = 1;
      orderdet3.Consumable_product__c = pro2.Id;

      //出库单2明细2
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test1_002002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList2.id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Shipment_Count__c = 1;
      orderdet4.Consumable_product__c = pro2.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3,
        orderdet4
      };
      //附件
      Consumable_accessories_invoice__c caic = new Consumable_accessories_invoice__c();
      caic.Attachment_ID__c = acc.Id;
      caic.Accessories_type__c = '发票和明细';
      caic.Invoice_code__c = invoiceorder.id;
      insert caic;
      PageReference page = new PageReference(
        '/apex/ConInvoiceView?invoiceId=' + invoiceorder.id
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      // contest.deliveryId=testList1.id;
      System.Test.startTest();
      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      System.Test.stopTest();
    }
  }

  //新建发票 以及编辑发票invoiceId<> NULL
  static testMethod void conInvoiceViewTestinit_2() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单
      //Consumable_order__c testList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);
      //Consumable_order__c testList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      //insert new Consumable_order__c[]{testList1,testList2};

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable2',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable2;
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_002001';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Shipment_Count__c = 1;
      orderdet3.Consumable_product__c = pro2.Id;

      //出库单2明细2
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test1_002002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList2.id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Shipment_Count__c = 1;
      orderdet4.Consumable_product__c = pro2.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3,
        orderdet4
      };
      //附件
      Consumable_accessories_invoice__c caic = new Consumable_accessories_invoice__c();
      caic.Attachment_ID__c = acc.Id;
      caic.Accessories_type__c = '发票和明细';
      caic.Invoice_code__c = invoiceorder.id;
      insert caic;
      // PageReference page = new PageReference('/apex/ConInvoiceView?KeyWords=Redirect');
      // page.setRedirect(true);
      // System.Test.setCurrentPage(page);

      // ConInvoiceViewController conTest = new ConInvoiceViewController();
      // contest.deliveryId=testList1.id;
      // conTest.invoiceId =invoiceorder.Id;
      System.Test.startTest();
      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );

      // conTest.init();

      //System.assertEquals(false, conTest.getdone());
      //System.assertEquals(false, conTest.getExistOutbound());
      //System.assertEquals('invoice01', conTest.getInvoiceName());
      //System.assertEquals(2, conTest.invoiceOrderRecoedsCount);
      // conTest.InvoiceorderSearch();

      // conTest.SortLimited();
      System.Test.stopTest();
    }
  }
  static testMethod void conInvoiceViewTestoutOrderchange() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      System.Test.startTest();
      insert testList1;
      insert testList2;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{ orderdet1, orderdet2 };

      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      System.Test.stopTest();
    }
  }

  static testMethod void conInvoiceViewTestgetdefaultMapinfo() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      // invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      System.Test.startTest();
      insert testList1;
      insert testList2;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{ orderdet1, orderdet2 };

      PageReference page = new PageReference(
        '/apex/ConInvoiceView?invoiceId=' +
          invoiceorder.Id +
          '&KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      System.Test.stopTest();
    }
  }

  //从出库单直接开票
  static testMethod void conInvoiceViewRedirectTest() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单
      //Consumable_order__c testList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);
      //Consumable_order__c testList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      testList1.Order_date__c = Date.today().addDays(2);
      testList2.Order_date__c = Date.today().addDays(2);
      testList1.Deliver_date__c = Date.today();
      testList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      //insert new Consumable_order__c[]{testList1,testList2};

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable2',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable2;
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_002001';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Shipment_Count__c = 1;
      orderdet3.Consumable_product__c = pro2.Id;

      //出库单2明细2
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test1_002002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList2.id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Shipment_Count__c = 1;
      orderdet4.Consumable_product__c = pro2.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3,
        orderdet4
      };
      //附件
      Consumable_accessories_invoice__c caic = new Consumable_accessories_invoice__c();
      caic.Attachment_ID__c = acc.Id;
      caic.Accessories_type__c = '发票和明细';
      caic.Invoice_code__c = invoiceorder.id;
      insert caic;
      PageReference page = new PageReference(
        '/apex/ConInvoiceView?deliveryId=' + testList1.Id + '&KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      System.Test.startTest();
      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      LexConInvoiceViewController.saveAttachment(
        JSON.serialize(LexConInvoiceViewController.attachmentRecoeds),
        invoiceorder.Id
      );
      // LexConInvoiceViewController.saveAttachment(JSON.serialize(caic),invoiceorder.Id);
      System.Test.stopTest();
    }
  }

  //提交
  static testMethod void conInvoiceViewTestapproval() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false,
        Packing_list_manual__c = 5
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单
      //Consumable_order__c testList1 = new Consumable_order__c(Name='Test1',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='草案中',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);
      //Consumable_order__c testList2 = new Consumable_order__c(Name='Test2',Summons_Sale_Status__c='出货',SummonsStatus_c__c='已完成',Order_ForHospital__c =hosp1.Id,SummonsForDirction__c='直接销售给医院',Order_status__c='已提交',Order_type__c='传票',Order_ForDealer__c = agency1.Id, Dealer_info__c=myAccount1.Id,ConInvoice_Code__c = invoiceorder.id);

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        RecordTypeId = System.Label.RT_ConOrder_Sale,
        Dealer_info__c = acc.Id
      );
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        RecordTypeId = System.Label.RT_ConOrder_Sale,
        Dealer_info__c = acc.Id
      );
      testList1.Order_date__c = Date.today().addDays(2);
      testList2.Order_date__c = Date.today().addDays(2);
      testList1.Deliver_date__c = Date.today();
      testList2.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      //insert new Consumable_order__c[]{testList1,testList2};

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable2',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable2;
      //出库单1明细1
      Consumable_Orderdetails__c orderdet1 = new Consumable_Orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      orderdet1.Invoiced_Count__c = 10;
      orderdet1.Delivery_List_RMB__c = 200;
      orderdet1.Box_Piece__c = '盒';
      orderdet1.Invoice_Unit__c = '个';
      // orderdet1.Shipment_Count__c = 50;
      // orderdet1.Invoiced_Procount__c = 5;
      // orderdet1.RrturnPro_count__c = 5;

      Consumable_Orderdetails__c orderdet12 = new Consumable_Orderdetails__c();
      orderdet12.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet12.Consumable_order__c = testList1.Id;
      orderdet12.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet12.Consumable_count__c = 1;
      orderdet12.Consumable_product__c = pro1.Id;
      orderdet12.Invoiced_Count__c = 30;
      orderdet12.Delivery_List_RMB__c = 200;
      //出库单1明细2
      Consumable_Orderdetails__c orderdet2 = new Consumable_Orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = invoiceorder.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      //出库单2明细1
      Consumable_Orderdetails__c orderdet3 = new Consumable_Orderdetails__c();
      orderdet3.Name = 'Test1_002001';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = invoiceorder.Id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Shipment_Count__c = 1;
      orderdet3.Consumable_product__c = pro2.Id;

      //出库单2明细2
      Consumable_Orderdetails__c orderdet4 = new Consumable_Orderdetails__c();
      orderdet4.Name = 'Test1_002002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList2.id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Shipment_Count__c = 1;
      orderdet4.Consumable_product__c = pro2.Id;
      insert new List<Consumable_Orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3,
        orderdet4,
        orderdet12
      };

      List<String> conorList = new List<String>();
      conorList.add(testList1.Id);

      // List<Consumable_Orderdetails__c> outOrderdet1List1 = new List<Consumable_Orderdetails__c>();
      // outOrderdet1List1.add(orderdet1);

      List<Consumable_Orderdetails__c> outOrderdet1List = [
        SELECT
          Id,
          Name,
          Consumable_order__c,
          Consumable_order__r.Name,
          Asset_Model_No__c,
          Consumable_Product__r.Asset_Model_No__c,
          Shipment_Count__c,
          RrturnPro_count__c,
          Delivery_List_RMB__c,
          InvoicedProCost_RMB__c,
          Invoiced_Procount__c,
          Invoiced_Count__c,
          Invoice_Unitprice__c,
          InvoiceProNot_count__c,
          Invoice_Cost_RMB__c,
          Invoice_No__c,
          Box_Piece__c,
          Invoice_Unit__c,
          ProductPacking_list_manual__c
        FROM Consumable_Orderdetails__c
        WHERE Id = :orderdet1.Id
      ];

      System.debug('outOrderdet1List' + outOrderdet1List);
      List<Consumable_Orderdetails__c> outOrderdet1List1 = [
        SELECT
          Id,
          Name,
          Consumable_order__c,
          Consumable_order__r.Name,
          Asset_Model_No__c,
          Consumable_Product__r.Asset_Model_No__c,
          Shipment_Count__c,
          RrturnPro_count__c,
          Delivery_List_RMB__c,
          InvoicedProCost_RMB__c,
          Invoiced_Procount__c,
          Invoiced_Count__c,
          Invoice_Unitprice__c,
          InvoiceProNot_count__c,
          Invoice_Cost_RMB__c,
          Invoice_No__c,
          Box_Piece__c,
          Invoice_Unit__c,
          ProductPacking_list_manual__c
        FROM Consumable_Orderdetails__c
        WHERE Id = :orderdet12.Id
      ];

      Map<String, Consumable_Orderdetails__c> tempCocMap = new Map<String, Consumable_Orderdetails__c>();
      Map<String, Consumable_Orderdetails__c> tempCocMap1 = new Map<String, Consumable_Orderdetails__c>();
      for (Consumable_Orderdetails__c cocTemp : outOrderdet1List) {
        if (cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c != null) {
          tempCocMap.put(
            cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c,
            cocTemp
          );
        }
      }
      for (Consumable_Orderdetails__c cocTemp : outOrderdet1List1) {
        if (cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c != null) {
          tempCocMap1.put(
            cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c,
            cocTemp
          );
        }
      }

      System.debug('tempCocMap===>' + tempCocMap);
      //附件
      Consumable_accessories_invoice__c caic = new Consumable_accessories_invoice__c();
      caic.Attachment_ID__c = acc.Id;
      caic.Accessories_type__c = '发票和明细';
      caic.Invoice_code__c = invoiceorder.id;
      insert caic;

      System.Test.startTest();
      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      LexConInvoiceViewController.approval(
        conorList,
        tempCocMap,
        invoiceorder.id
      );
      LexConInvoiceViewController.approval(
        conorList,
        tempCocMap1,
        invoiceorder.id
      );
      System.Test.stopTest();
    }
  }

  //提交发票
  static testMethod void conInvoice_approval() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Oly_TriggerHandler.bypass('ConsumableAssetHander');
    Oly_TriggerHandler.bypass('Oly_TriggerHandler');
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };

      //出库单1
      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        recordtypeid = System.Label.RT_ConOrder_Sale,
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        // Order_ForHospital__c=hosp1.Id,
        Dealer_Info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      insert testList1;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001';
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Sale;
      orderdet1.Shipment_Count__c = 1;
      orderdet1.Delivery_List_RMB__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      orderdet1.Shipment_Count__c = 50;
      orderdet1.Invoiced_Procount__c = 5;
      orderdet1.RrturnPro_count__c = 5;
      insert orderdet1;
      List<String> conorList = new List<String>();
      conorList.add(testList1.Id);
      //出库单1明细2
      Consumable_order_details2__c orderdet2 = new Consumable_order_details2__c();
      orderdet2.Name = 'Test1_001001';
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
      orderdet2.Consumable_Sale_order__c = testList1.Id;
      orderdet2.Deliver_date__c = Date.today();
      orderdet2.Arrive_date__c = Date.today();
      orderdet2.Used_date__c = Date.today();
      orderdet2.Consumable_product__c = pro1.Id;
      insert orderdet2;

      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      // invoiceorder.Order_ForHospital__c =hosp1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      insert invoiceorder;

      //发票明细1
      Consumable_orderdetails__c invoicedet1 = new Consumable_orderdetails__c();
      invoicedet1.Name = 'invoice01_01';
      invoicedet1.Consumable_order__c = invoiceorder.Id;
      invoicedet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      invoicedet1.Invoiced_Count__c = 1;
      invoicedet1.Invoice_Unitprice__c = 1;
      invoicedet1.Consumable_product__c = pro1.Id;
      invoicedet1.Invoicedet1_OD_link__c = testList1.Id;
      insert invoicedet1;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      List<Consumable_Orderdetails__c> outOrderdet1List = [
        SELECT
          Id,
          Name,
          Consumable_order__c,
          Consumable_order__r.Name,
          Asset_Model_No__c,
          Consumable_Product__r.Asset_Model_No__c,
          Shipment_Count__c,
          RrturnPro_count__c,
          Delivery_List_RMB__c,
          InvoicedProCost_RMB__c,
          Invoiced_Procount__c,
          Invoiced_Count__c,
          Invoice_Unitprice__c,
          InvoiceProNot_count__c,
          Invoice_Cost_RMB__c,
          Invoice_No__c,
          Box_Piece__c,
          Invoice_Unit__c,
          ProductPacking_list_manual__c
        FROM Consumable_Orderdetails__c
        WHERE Id = :orderdet1.Id
      ];
      Map<String, Consumable_Orderdetails__c> tempCocMap1 = new Map<String, Consumable_Orderdetails__c>();
      for (Consumable_Orderdetails__c cocTemp : outOrderdet1List) {
        if (cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c != null) {
          tempCocMap1.put(
            cocTemp.Consumable_order__c + cocTemp.Asset_Model_No__c,
            cocTemp
          );
        }
      }

      System.Test.startTest();

      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        orderdet1.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = acc.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        acc.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        acc.id,
        invoiceOrderRecoeds
      );
      LexConInvoiceViewController.approval(
        conorList,
        tempCocMap1,
        invoiceorder.id
      );
      LexConInvoiceViewController.approval(conorList, tempCocMap1, '2345678');

      // conTest.init();

      // System.assertEquals(1, conTest.invoiceOrderRecoeds.size());
      // conTest.approval();
      System.Test.stopTest();
    }
  }

  //CHAN-BSS5SQ    update by rentongxiao 2020-08-26  start
  //新建发票 以及编辑发票 invoiceId<>null
  static testMethod void rentestreopen() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '提交';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList3 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList3.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      TestList3.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      insert testList3;
      System.Test.startTest();
      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      Consumable_order_LinkTable__c order_LinkTable3 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList3.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      insert order_LinkTable2;
      insert order_LinkTable3;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{ orderdet1, orderdet2 };

      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test3_001002';
      //orderdet3.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.Id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Consumable_product__c = pro1.Id;
      insert orderdet3;

      //出库单3明细1
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test3_001002';
      //orderdet4.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList3.Id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Consumable_product__c = pro1.Id;
      insert orderdet4;

      PageReference page = new PageReference(
        '/apex/ConInvoiceView?invoiceId=' +
          invoiceorder.Id +
          '&reopen=isreopen&KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );

      // ConInvoiceViewController conTest = new ConInvoiceViewController();

      // conTest.init();

      // conTest.invoiceId =invoiceorder.Id;
      // conTest.coc.SummonsForDirction__c = '直接销售给医院';
      // conTest.HospitalInfo = hosp1.id;
      // //conTest.SecondDealer = agency1.id;
      // //conTest.coc.Order_ForDealer__c = agency1.id;
      // conTest.coc.Name = 'invoice002';
      // conTest.coc.Order_ForCustomerText__c = 'AA';
      // conTest.coc.Order_ForHospital__c = hosp1.id;
      // conTest.coc.Invoice_Date__c = Date.today();

      // //conTest.SortLimited();
      // //conTest.InvoiceorderSearch();
      // System.assertEquals(3, conTest.invoiceOrderRecoeds.size());
      // conTest.invoiceOrderRecoeds[0].esd.Order_ForCustomerText__c = 'AA';
      // conTest.invoiceOrderRecoeds[0].esd.Order_ForHospital__c =hosp1.Id;
      // conTest.invoiceOrderRecoeds[0].esd.Order_ForDealer__c = agency1.id;

      // conTest.invoiceOrderRecoeds[1].esd.Order_ForCustomerText__c = 'AA';
      // conTest.invoiceOrderRecoeds[1].esd.Order_ForHospital__c =hosp1.Id;
      // conTest.invoiceOrderRecoeds[1].esd.Order_ForDealer__c = agency1.id;

      // conTest.invoiceOrderRecoeds[2].esd.Order_ForCustomerText__c = 'AA';
      // conTest.invoiceOrderRecoeds[2].esd.Order_ForHospital__c =hosp1.Id;
      // conTest.invoiceOrderRecoeds[2].esd.Order_ForDealer__c = agency1.id;

      // conTest.invoiceOrderRecoeds[0].check= true;
      // conTest.invoiceOrderRecoeds[1].check= false;
      // conTest.invoiceOrderRecoeds[2].check= true;

      // conTest.save();
      // //System.assertEquals('123',conTest.testTmp);
      // conTest.nvoiceorderremind();
      // conTest.saveAttachment();

      // conTest.getdone();
      // conTest.getExistOutbound();
      // conTest.getInvoiceName();
      System.Test.stopTest();
    }
  }

  //CHAN-BSS5SQ    update by rentongxiao 2020-08-26  end
  //CHAN-BSS5SQ    update by rentongxiao 2020-08-26  start
  //新建发票 以及编辑发票 invoiceId<>null
  static testMethod void rentestreopen001() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '提交';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      //invoiceorder.Order_ForHospital__c =hosp1.Id;
      //invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList3 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList3.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();
      TestList3.Deliver_date__c = Date.today();
      insert testList1;
      insert testList2;
      insert testList3;
      System.Test.startTest();
      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      Consumable_order_LinkTable__c order_LinkTable2 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList2.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      Consumable_order_LinkTable__c order_LinkTable3 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList3.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;
      insert order_LinkTable2;
      insert order_LinkTable3;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{ orderdet1, orderdet2 };

      //出库单2明细1
      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test3_001002';
      //orderdet3.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = testList2.Id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Consumable_product__c = pro1.Id;
      insert orderdet3;

      //出库单3明细1
      Consumable_orderdetails__c orderdet4 = new Consumable_orderdetails__c();
      orderdet4.Name = 'Test3_001002';
      //orderdet4.Consumable_principal__c = testList2.Id;
      orderdet4.Consumable_order__c = testList3.Id;
      orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet4.Consumable_count__c = 1;
      orderdet4.Consumable_product__c = pro1.Id;
      insert orderdet4;

      PageReference page = new PageReference(
        '/apex/ConInvoiceView?invoiceId=' +
          invoiceorder.Id +
          '&reopen=isreopen&KeyWords=Redirect'
      );
      page.setRedirect(true);
      System.Test.setCurrentPage(page);

      LexConInvoiceViewController.init(
        invoiceorder.id,
        'Redirect',
        testList2.Id
      );
      LexConInvoiceViewController conTest = new LexConInvoiceViewController();
      LexConInvoiceViewController.HospitalInfo = hosp1.id;
      LexConInvoiceViewController.SecondDealer = agency1.id;
      LexConInvoiceViewController.invoiceId = invoiceorder.Id;
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        '济宁任城儒济医院',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.InvoiceorderSearch(
        testList1,
        invoiceorder.Id,
        acc.Id,
        '重庆',
        'ET',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds
      );
      System.Test.stopTest();
    }
  }
  //新建发票 以及编辑发票 invoiceId<>null
  static testMethod void allinit() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //准备数据
      // Consumable_order__c  Id = deliveryId  //出库单
      // Consumable_order__c
      // WHERE Id = :invoiceId AND Order_type__c = '发票'
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      // invoiceorder.Order_ForHospital__c =hosp1.Id;
      // invoiceorder.Order_ForDealer__c = agency1.Id;
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      invoiceorder = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :invoiceorder.id
      ];
      //出库单

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test2',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '已提交',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Order_ForCustomerText__c = ''
      );
      TestList1.Order_date__c = Date.today().addDays(2);
      TestList2.Order_date__c = Date.today().addDays(2);
      TestList1.Deliver_date__c = Date.today();
      TestList2.Deliver_date__c = Date.today();

      Consumable_order__c testList3 = new Consumable_order__c();
      testList3.Summons_Sale_Status__c = '出货';
      testList3.SummonsStatus_c__c = '已完成';
      testList3.SummonsForDirction__c = '直接销售给医院';
      testList3.Order_status__c = '草案中';
      testList3.Order_type__c = '传票';
      testList3.Dealer_info__c = acc.Id;
      testList3.Order_ForCustomerText__c = '消化科';

      insert testList1;
      insert testList2;
      insert testList3;

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder.Id
      );
      insert order_LinkTable1;

      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;

      //出库单1明细2
      Consumable_orderdetails__c orderdet2 = new Consumable_orderdetails__c();
      orderdet2.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet2.Consumable_order__c = testList1.Id;
      orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet2.Consumable_count__c = 1;
      orderdet2.Consumable_product__c = pro1.Id;

      Consumable_orderdetails__c orderdet3 = new Consumable_orderdetails__c();
      orderdet3.Name = 'Test1_001002';
      //orderdet2.Consumable_principal__c = testList2.Id;
      orderdet3.Consumable_order__c = invoiceorder.Id;
      orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet3.Consumable_count__c = 1;
      orderdet3.Consumable_product__c = pro1.Id;
      insert new List<Consumable_orderdetails__c>{
        orderdet1,
        orderdet2,
        orderdet3
      };

      //发票附件
      Consumable_accessories_invoice__c cai = new Consumable_accessories_invoice__c();
      cai.Invoice_code__c = invoiceorder.Id;
      insert cai;

      System.Test.startTest();

      LexConInvoiceViewController.init(invoiceorder.Id, '', testList1.Id);
      LexConInvoiceViewController.init('', '', testList1.Id);
      LexConInvoiceViewController.init(invoiceorder.Id, '', '');
      LexConInvoiceViewController.init('', '', '');
      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList1.Id
      );
      LexConInvoiceViewController.init('', 'Redirect', '');
      LexConInvoiceViewController.init('', 'Redirect', testList1.Id);
      System.debug(
        'order==>' + LexConInvoiceViewController.invoiceOrderRecoeds
      );

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList2,
        'Testhosp001',
        '',
        '',
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList3,
        'Testhosp001',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList2,
        'Testhosp001',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );

      //保存
      // LexConInvoiceViewController.save(testList1,'测试医院',hosp1.Id,agency1.Id,'',testList1.Id,invoiceorder.Id,myAccount1.Id,'ET');
      System.Test.stopTest();
    }
  }
  static testMethod void allsave() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      // invoiceorder.Order_ForHospital__c = '';
      // invoiceorder.Order_ForDealer__c = '';
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      // LexConInvoiceViewController.init(invoiceorder.Id,'Redirect',testList1.Id);
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        null,
        null,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.saveAttachment(
        JSON.serialize(LexConInvoiceViewController.attachmentRecoeds),
        invoiceorder.Id
      );
    }
  }
  static testMethod void allsave1() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      // invoiceorder.Order_ForHospital__c = '';
      // invoiceorder.Order_ForDealer__c = '';
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today(),
        Order_ForCustomerText__c = '消化科'
      );
      insert testList1;
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today(),
        Order_ForDealerText__c = 'Test'
      );
      insert testList2;

      LexConInvoiceViewController.init(
        invoiceorder.Id,
        'Redirect',
        testList2.Id
      );
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      String invoiceOrderRecoeds = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoeds
      );
      List<LexConInvoiceViewController.InvoiceOrderInfo> test1 = new List<LexConInvoiceViewController.InvoiceOrderInfo>();
      for (
        LexConInvoiceViewController.InvoiceOrderInfo ass : LexConInvoiceViewController.invoiceOrderRecoeds
      ) {
        ass.check = true;
        test1.add(ass);
      }
      System.debug('test1==>' + test1);
      System.debug(
        'invoiceOrderRecoedschangeLwc==>' + invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        hosp1.id,
        agency1.id,
        invoiceOrderRecoeds,
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        '',
        '',
        JSON.serialize(test1),
        testList1.Id,
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        'Testhosp001',
        '',
        '',
        JSON.serialize(test1),
        '',
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        '青岛盈海医院',
        hosp1.id,
        agency1.id,
        '[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false}]',
        '',
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        testList1,
        '青岛盈海医院',
        hosp1.id,
        agency1.id,
        '[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false}]',
        '',
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
    }
  }

  static testMethod void allsave2() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = 'invoice01';
      invoiceorder.Order_type__c = '发票';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.RecordTypeid = System.Label.RT_ConOrder_Invoice;
      // invoiceorder.Order_ForHospital__c = '';
      // invoiceorder.Order_ForDealer__c = '';
      invoiceorder.Dealer_Info__c = acc.Id;
      //invoiceorder.Order_ProType__c = 'ET';
      insert invoiceorder;

      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today(),
        Order_ForDealerText__c = 'Test'
      );
      insert testList2;
      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      insert testList1;
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      //选择开票单
      LexConInvoiceViewController.save(
        testList2,
        '青岛盈海医院',
        '',
        agency2.id,
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false}]',
        '',
        invoiceorder.Id,
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
    }

  }

  static testMethod void allsave3() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };

      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = '202306164590';
      invoiceorder.Invoice_Date__c = Date.today();
      invoiceorder.Order_ForCustomerText__c = '消化科';
      invoiceorder.Invoice_Note__c = '4444';
      invoiceorder.RecordTypeid = '012100000006JxEAAU';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      insert invoiceorder;
      // invoiceorder = [select id,Name from Consumable_order__c where id =:invoiceorder.id];
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );
      insert testList2;

      List<Consumable_orderdetails__c> conList = new List<Consumable_orderdetails__c>();
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = invoiceorder.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      orderdet1.Shipment_Count__c = 10;
      orderdet1.Invoiced_Procount__c = 4;
      orderdet1.RrturnPro_count__c = 2;
      conList.add(orderdet1);

      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      LexConInvoiceViewController.save(
        invoiceorder,
        '潍城现代门诊部',
        '0011000001g0uyhAAA',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}, {"check": true,"esd": {"Id": "a2K0l000000xAnwEAE","Order_ForHospital__c": "0011000001g0uyhAAA","Name": "a2K0l000000xAnw","Outbound_Date__c": "2023-05-12","ShipmentAccount__c": "潍城现代门诊部", "Shipment_total_amount__c": 2300,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 2300,"InvoiceNotPro_money__c": 2300,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "潍城现代门诊部","Id": "0011000001g0uyhAAA"} }, "needInvoiceCount": 0,"oldCheck": false, "Id": "a2K0l000000xAnwEAE"}]',
        '',
        '',
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
      LexConInvoiceViewController.save(
        invoiceorder,
        '潍城现代门诊部',
        '0011000001g0uyhAAA',
        agency1.Id,
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}, {"check": true,"esd": {"Id": "a2K0l000000xAnwEAE","Order_ForHospital__c": "0011000001g0uyhAAA","Name": "a2K0l000000xAnw","Outbound_Date__c": "2023-05-12","ShipmentAccount__c": "潍城现代门诊部", "Shipment_total_amount__c": 2300,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 2300,"InvoiceNotPro_money__c": 2300,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "潍城现代门诊部","Id": "0011000001g0uyhAAA"} }, "needInvoiceCount": 0,"oldCheck": false, "Id": "a2K0l000000xAnwEAE"}]',
        testList2.Id,
        '',
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );

      List<LexConInvoiceViewController.InvoiceOrderInfo> test1 = new List<LexConInvoiceViewController.InvoiceOrderInfo>();
      for (
        LexConInvoiceViewController.InvoiceOrderInfo ass : LexConInvoiceViewController.invoiceOrderRecoeds
      ) {
        ass.check = true;
        test1.add(ass);
      }
      System.debug('test1==>' + test1);
      LexConInvoiceViewController.save(
        invoiceorder,
        '潍城现代门诊部',
        '0011000001g0uyhAAA',
        '',
        JSON.serialize(test1),
        '',
        '',
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );
    }

  }

  static testMethod void allsave4() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    Account hosp1 = [SELECT Id FROM Account WHERE name = 'Testhosp001' LIMIT 1];
    Account agency1 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp001'
      LIMIT 1
    ];
    Account agency2 = [
      SELECT Id
      FROM Account
      WHERE name = 'Testhosp002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = '202306164590';
      invoiceorder.Invoice_Date__c = Date.today();
      // invoiceorder.Order_ForCustomerText__c = '消化科';
      invoiceorder.Invoice_Note__c = '4444';
      invoiceorder.RecordTypeid = '012100000006JxEAAU';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      insert invoiceorder;
      //发票信息
      Consumable_order__c invoiceorder1 = new Consumable_order__c();
      invoiceorder1.Name = '202306164590';
      invoiceorder1.Invoice_Date__c = Date.today();
      invoiceorder1.Order_ForCustomerText__c = '消化科';
      invoiceorder1.Invoice_Note__c = '4444';
      invoiceorder1.RecordTypeid = '012100000006JxEAAU';
      invoiceorder1.Invoice_status__c = '草案中';
      invoiceorder1.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      insert invoiceorder1;

      // invoiceorder = [select id,Name from Consumable_order__c where id =:invoiceorder.id];
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );

      insert testList2;
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      //不需要输入科室
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '',
        agency1.Id,
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}, {"check": true,"esd": {"Id": "a2K0l000000xAnwEAE","Order_ForHospital__c": "0011000001g0uyhAAA","Name": "a2K0l000000xAnw","Outbound_Date__c": "2023-05-12","ShipmentAccount__c": "潍城现代门诊部", "Shipment_total_amount__c": 2300,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 2300,"InvoiceNotPro_money__c": 2300,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "潍城现代门诊部","Id": "0011000001g0uyhAAA"} }, "needInvoiceCount": 0,"oldCheck": false, "Id": "a2K0l000000xAnwEAE"}]',
        testList2.Id,
        '',
        acc.Id,
        'ET',
        '',
        invoiceOrderRecoedschangeLwc
      );

      //LexConInvoiceViewController.save(invoiceorder,'潍城现代门诊部','',agency2.Id,'[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}, {"check": false,"esd": {"Id": "a2K0l000000xAnwEAE","Order_ForHospital__c": "0011000001g0uyhAAA","Name": "a2K0l000000xAnw","Outbound_Date__c": "2023-05-12","ShipmentAccount__c": "潍城现代门诊部", "Shipment_total_amount__c": 2300,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 2300,"InvoiceNotPro_money__c": 2300,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "潍城现代门诊部","Id": "0011000001g0uyhAAA"} }, "needInvoiceCount": 0,"oldCheck": false, "Id": "a2K0l000000xAnwEAE"}]',testList2.Id,invoiceorder.Id,myAccount1.Id,'ET','isreopen',invoiceOrderRecoedschangeLwc);
      //  LexConInvoiceViewController.save(invoiceorder1,'潍城现代门诊部','',agency2.Id,'[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}, {"check": false,"esd": {"Id": "a2K0l000000xAnwEAE","Order_ForHospital__c": "0011000001g0uyhAAA","Name": "a2K0l000000xAnw","Outbound_Date__c": "2023-05-12","ShipmentAccount__c": "潍城现代门诊部", "Shipment_total_amount__c": 2300,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 2300,"InvoiceNotPro_money__c": 2300,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "潍城现代门诊部","Id": "0011000001g0uyhAAA"} }, "needInvoiceCount": 0,"oldCheck": false, "Id": "a2K0l000000xAnwEAE"}]',testList2.Id,invoiceorder1.Id,myAccount1.Id,'ET','isreopen',invoiceOrderRecoedschangeLwc);
    }
  }

  static testMethod void allsave5() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      List<Consumable_order__c> orderList = new List<Consumable_order__c>();
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = '202306164590';
      invoiceorder.Invoice_Date__c = Date.today();
      // invoiceorder.Order_ForCustomerText__c = '消化科';
      invoiceorder.Invoice_Note__c = '4444';
      invoiceorder.RecordTypeid = '012100000006JxEAAU';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder);
      //发票信息
      Consumable_order__c invoiceorder1 = new Consumable_order__c();
      invoiceorder1.Name = '202306164590';
      invoiceorder1.Invoice_Date__c = Date.today();
      invoiceorder1.Order_ForCustomerText__c = '消化科';
      invoiceorder1.Invoice_Note__c = '4444';
      invoiceorder1.RecordTypeid = '012100000006JxEAAU';
      invoiceorder1.Invoice_status__c = '草案中';
      invoiceorder1.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder1);
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );
      orderList.add(testList2);
      //出库单
      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      orderList.add(testList1);
      insert orderList;
      List<Consumable_orderdetails__c> conList = new List<Consumable_orderdetails__c>();
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = invoiceorder1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      orderdet1.Shipment_Count__c = 10;
      orderdet1.Invoiced_Procount__c = 4;
      orderdet1.RrturnPro_count__c = 2;
      conList.add(orderdet1);

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = testList1.Id,
        Invoice_Code_link__c = invoiceorder1.Id
      );
      insert order_LinkTable1;
      Consumable_Orderdetails__c upDateform = new Consumable_Orderdetails__c();
      upDateform.Name = 'Test1_001001';
      upDateform.Consumable_order__c = invoiceorder1.Id;
      upDateform.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      upDateform.Consumable_count__c = 1;
      upDateform.Consumable_product__c = pro1.Id;
      upDateform.Consumable_order__c = order_LinkTable1.Outboundorder_Code_link__c;
      conList.add(upDateform);
      insert conList;
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '0011000001k1K9ZAAU',
        '',
        '[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]',
        testList1.Id,
        invoiceorder1.Id,
        acc.Id,
        'ET',
        'isreopen',
        invoiceOrderRecoedschangeLwc
      );
      // LexConInvoiceViewController.save(invoiceorder1,'潍城现代门诊部','0011000001k1K9ZAAU','','[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]',testList1.Id,'',myAccount1.Id,'ET','isreopen',invoiceOrderRecoedschangeLwc);
    }
  }

  static testMethod void allsave6() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      List<Consumable_order__c> orderList = new List<Consumable_order__c>();
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = '202306164590';
      invoiceorder.Invoice_Date__c = Date.today();
      // invoiceorder.Order_ForCustomerText__c = '消化科';
      invoiceorder.Invoice_Note__c = '4444';
      invoiceorder.RecordTypeid = '012100000006JxEAAU';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder);
      //发票信息
      Consumable_order__c invoiceorder1 = new Consumable_order__c();
      invoiceorder1.Name = '202306164590';
      invoiceorder1.Invoice_Date__c = Date.today();
      invoiceorder1.Order_ForCustomerText__c = '消化科';
      invoiceorder1.Invoice_Note__c = '4444';
      invoiceorder1.RecordTypeid = '012100000006JxEAAU';
      invoiceorder1.Invoice_status__c = '草案中';
      invoiceorder1.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder1);
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );
      orderList.add(testList2);
      //出库单
      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      orderList.add(testList1);
      insert orderList;
      List<Consumable_orderdetails__c> conList = new List<Consumable_orderdetails__c>();
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      conList.add(orderdet1);

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = invoiceorder1.Id,
        Invoice_Code_link__c = invoiceorder1.Id
      );
      insert order_LinkTable1;
      Consumable_Orderdetails__c upDateform = new Consumable_Orderdetails__c();
      upDateform.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      upDateform.Consumable_order__c = invoiceorder1.Id;
      upDateform.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      upDateform.Consumable_count__c = 1;
      upDateform.Consumable_product__c = pro1.Id;
      upDateform.Consumable_order__c = order_LinkTable1.Outboundorder_Code_link__c;
      upDateform.RrturnPro_count__c = 10;
      conList.add(upDateform);
      insert conList;
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '0011000001k1K9ZAAU',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]',
        testList1.Id,
        invoiceorder1.Id,
        acc.Id,
        'ET',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]'
      );
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '0011000001k1K9ZAAU',
        '',
        '[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]',
        '',
        invoiceorder1.Id,
        acc.Id,
        'ET',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]'
      );
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '0011000001k1K9ZAAU',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]',
        '',
        invoiceorder1.Id,
        acc.Id,
        'ET',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]'
      );
    }
  }

  static testMethod void allsave7() {
    user curUser = [SELECT Id FROM User WHERE LastName = 'TestUser' LIMIT 1];
    Account acc = [
      SELECT Id
      FROM Account
      WHERE name = 'Testaccount002'
      LIMIT 1
    ];
    System.runAs(curUser) {
      //产品信息
      Product2 prod01 = new Product2(
        Name = 'Test01',
        ProductCode = 'Test01',
        Asset_Model_No__c = 'Test01',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      Product2 prod02 = new Product2(
        Name = 'Test02',
        ProductCode = 'Test02',
        Asset_Model_No__c = 'Test02',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod01, prod02 };

      Product2__c pro1 = new Product2__c(
        Name = 'Pro001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod01.Id
      );
      Product2__c pro2 = new Product2__c(
        Name = 'Pro002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod02.Id
      );
      insert new List<Product2__c>{ pro1, pro2 };
      List<Consumable_order__c> orderList = new List<Consumable_order__c>();
      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c();
      invoiceorder.Name = '202306164590';
      invoiceorder.Invoice_Date__c = Date.today();
      // invoiceorder.Order_ForCustomerText__c = '消化科';
      invoiceorder.Invoice_Note__c = '4444';
      invoiceorder.RecordTypeid = '012100000006JxEAAU';
      invoiceorder.Invoice_status__c = '草案中';
      invoiceorder.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder);
      //发票信息
      Consumable_order__c invoiceorder1 = new Consumable_order__c();
      invoiceorder1.Name = '202306164590';
      invoiceorder1.Invoice_Date__c = Date.today();
      invoiceorder1.Order_ForCustomerText__c = '消化科';
      invoiceorder1.Invoice_Note__c = '4444';
      invoiceorder1.RecordTypeid = '012100000006JxEAAU';
      invoiceorder1.Invoice_status__c = '草案中';
      invoiceorder1.Order_type__c = '发票';
      // invoiceorder.Order_ForHospital__c = hosp1.Id;
      orderList.add(invoiceorder1);
      Consumable_order__c testList2 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id,
        Invoice_Date__c = Date.today()
      );
      orderList.add(testList2);
      //出库单
      Consumable_order__c testList1 = new Consumable_order__c(
        Name = 'Test1',
        Summons_Sale_Status__c = '出货',
        SummonsStatus_c__c = '已完成',
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Order_type__c = '传票',
        Dealer_info__c = acc.Id
      );
      orderList.add(testList1);
      insert orderList;
      List<Consumable_orderdetails__c> conList = new List<Consumable_orderdetails__c>();
      //出库单1明细1
      Consumable_orderdetails__c orderdet1 = new Consumable_orderdetails__c();
      orderdet1.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      orderdet1.Consumable_order__c = testList1.Id;
      orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      orderdet1.Consumable_count__c = 1;
      orderdet1.Consumable_product__c = pro1.Id;
      conList.add(orderdet1);

      Consumable_order_LinkTable__c order_LinkTable1 = new Consumable_order_LinkTable__c(
        Name = 'order_LinkTable1',
        Outboundorder_Code_link__c = invoiceorder1.Id,
        Invoice_Code_link__c = invoiceorder1.Id
      );
      insert order_LinkTable1;
      Consumable_Orderdetails__c upDateform = new Consumable_Orderdetails__c();
      upDateform.Name = 'Test1_001001';
      //orderdet1.Consumable_principal__c = testList1.Id;
      upDateform.Consumable_order__c = invoiceorder1.Id;
      upDateform.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      upDateform.Consumable_count__c = 1;
      upDateform.Consumable_product__c = pro1.Id;
      upDateform.Consumable_order__c = order_LinkTable1.Outboundorder_Code_link__c;
      upDateform.RrturnPro_count__c = 10;
      conList.add(upDateform);
      insert conList;
      String invoiceOrderRecoedschangeLwc = JSON.serialize(
        LexConInvoiceViewController.invoiceOrderRecoedschange
      );
      LexConInvoiceViewController.save(
        invoiceorder1,
        '潍城现代门诊部',
        '0011000001k1K9ZAAU',
        '',
        '[{"check": true,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"},{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848,"Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false}]',
        '',
        invoiceorder1.Id,
        acc.Id,
        'ET',
        '',
        '[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]'
      );
      // LexConInvoiceViewController.save(invoiceorder1,'潍城现代门诊部','0011000001k1K9ZAAU','','[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]','',invoiceorder1.Id,myAccount1.Id,'ET','','[{"check": false,"esd": {"Id": "a2K0l000000x1KXEAY","Order_ForHospital__c": "0011000001k1K9ZAAU","Name": "DB-FY2024-04-Z316244","Outbound_Date__c": "2023-06-09","ShipmentAccount__c": "青岛盈海医院","Shipment_total_amount__c": 848,"RrturnPro_total_amount__c": 0,"Total_Invoiced_Procount__c": 0,"InvoiceNotPro_total_amount__c": 848,"InvoiceNotPro_money__c": 848, "Invoice_total_amount__c": 0,"Billed_Status__c": "还没开票","Order_ForHospital__r": {"Name": "青岛盈海医院","Id": "0011000001k1K9ZAAU"}},"needInvoiceCount": 0,"oldCheck": false,"Id": "a2K0l000000x1KXEAY"}]');
    }
  }
}
