buli
2023-07-14 744f42c5496e656a1f9927740a3b37c0b97a6cba
force-app/main/default/classes/LexSummonsCreatController.cls
@@ -50,24 +50,15 @@
  private static List<ConsumableorderdetailsInfo> consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
  //明细2
  @AuraEnabled
  public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecords {
    get;
    set;
  }
    public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecords { get; set; }
  //错误明细
  @AuraEnabled
  public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecordserror {
    get;
    set;
  }
    public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecordserror { get; set; }
  @AuraEnabled
  public static List<ConsumableorderdetailsInfo> pageRecords { get; set; }
  public static List<ConsumableorderdetailsInfoLwc> pageRecordsLwc { get; set; }
  //public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview { get; set; }
  public static List<ConsumableorderdetailsInfo> consumableorderdetails2Records {
    get;
    set;
  }
    public static List<ConsumableorderdetailsInfo> consumableorderdetails2Records { get; set; }
  public static List<Consumable_order__c> consumableInvoiceRecords { get; set; }
  private static List<ConsumableorderdetailsInfo> consumableproductdetailsRecords = new List<ConsumableorderdetailsInfo>();
  private static List<Attachment> attachmentinfo = new List<Attachment>();
@@ -93,9 +84,7 @@
  //消耗品明细2数量
  public static Integer consumableorderdetails2Count {
    get {
      return consumableorderdetails2Records == null
        ? 0
        : consumableorderdetails2Records.size();
            return consumableorderdetails2Records == null ? 0 : consumableorderdetails2Records.size();
    }
  }
  //订货单号
@@ -256,13 +245,7 @@
  // 画面初始化
  @AuraEnabled
  public static ResponseBodyLWC init(
    String ESetidJs,
    String statusEdit,
    Integer pageSizeLWC,
    Integer pageTokenLWC,
    String arriveorderLWC
  ) {
    public static ResponseBodyLWC init(String ESetidJs, String statusEdit, Integer pageSizeLWC, Integer pageTokenLWC,String arriveorderLWC) {
    try {
      firstInit(ESetidJs);
      statusEdit = statusEdit;
@@ -288,39 +271,17 @@
      //cate1ForSort = '';
      sumPrice = 0;
      IdCheck = EsetId;
      if (
        ESetId != null &&
        ESetId != '' &&
        (statusEdit == '' ||
        statusEdit == null)
      ) {
            if (ESetId != null && ESetId != '' && (statusEdit == '' || statusEdit == null)) {
        editAble = false;
      } else if (
        (ESetId == null || ESetId == '') &&
        (statusEdit == '' ||
        statusEdit == null)
      ) {
            } else if ((ESetId == null || ESetId == '') && (statusEdit == '' || statusEdit == null)) {
        editAble = true;
      } else if (
        ESetId != null &&
        ESetId != '' &&
        statusEdit != '' &&
        statusEdit != null
      ) {
            } else if (ESetId != null && ESetId != '' && statusEdit != '' && statusEdit != null) {
        editAble = true;
      }
      userId = UserInfo.getUserId();
      localuser = [
        SELECT id, State_Hospital__c
        FROM User
        WHERE id = :UserInfo.getUserId()
      ];
            localuser = [SELECT id, State_Hospital__c FROM User WHERE id = :UserInfo.getUserId()];
      //userId = '00510000005QO75';
      user Useracc = [
        SELECT accountid, Work_Location__c, UserPro_Type__c
        FROM user
        WHERE id = :userId
      ];
            user Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
      accountid = Useracc.accountid;
      userWorkLocation = Useracc.Work_Location__c;
      agencyProType = Useracc.UserPro_Type__c;
@@ -338,19 +299,11 @@
      ];
      List<Agency_Hospital_Link__c> AgencyHospitalLink = new List<Agency_Hospital_Link__c>();
      AgencyHospitalLink = [
        SELECT Id, Hospital__c, Hospital__r.Name
        FROM Agency_Hospital_Link__c
        WHERE Agency__c = :accountid
      ];
            AgencyHospitalLink = [SELECT Id, Hospital__c, Hospital__r.Name FROM Agency_Hospital_Link__c WHERE Agency__c = :accountid];
      //add by rentx 2021-3-1 start
      //判断当前经销商下是否有特价医院
      List<hospitalprice__c> hlist = [
        SELECT id, product__c
        FROM hospitalprice__c
        WHERE account__c = :accountid
      ];
            List<hospitalprice__c> hlist = [SELECT id, product__c FROM hospitalprice__c WHERE account__c = :accountid];
      if (hlist == null || hlist.size() == 0) {
        hasHos = false;
      } else {
@@ -390,6 +343,7 @@
      for (AggregateResult orderdetail : orderdetailCount) {
        zaikuId.add(String.valueOf(orderdetail.get('cpc')));
      }
            System.debug('orderdetailCount = ' + orderdetailCount);
      System.debug('sqlagencyProType = ' + sqlagencyProType);
      System.debug('userWorkLocation = ' + userWorkLocation);
      System.debug('accountName = ' + accountName);
@@ -431,11 +385,9 @@
        if (String.isBlank(arriveorder)) {
          EditDelCommitBtnDisabled = true;
          for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(
              product2Selected[i].Id,
              new ConsumableorderdetailsInfo(product2Selected[i])
            );
                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          }
                    System.debug('MidMap = ' + MidMap);
          for (Integer i = 0; i < CountDel.size(); i++) {
            String str = '';
            if (CountDel[i].hospitalSpecialOffer__c) {
@@ -443,15 +395,13 @@
            } else {
              str = 'notHos';
            }
                        System.debug('CountDel[i].Consumable_Product__c= ' + CountDel[i].Consumable_Product__c);
                        System.debug('CountDel[i].Consumable_Product__c + str= ' + CountDel[i].Consumable_Product__c + str);
            //明细2对应的产品存在于MidMap中
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
              //设置map中key的后缀 用于区分医院特价和非医院特价
              if (
                MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)
              ) {
                ConsumableorderdetailsInfo Jstage = MidMap2.get(
                  CountDel[i].Consumable_Product__c + str
                );
                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -469,10 +419,7 @@
                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
              } else {
                //midmap2中没有对应的产品
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                    CountDel[i].Consumable_Product__c
                  )
                  .clone();
                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -519,9 +466,7 @@
          for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
            //update by rentx 2021-01-29
            //if(bss.allnumber>0){
            bss.packinglist = Integer.valueOf(
              bss.Prod.Product2__r.Packing_list_manual__c
            );
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
            bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
            bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
            consumableorderdetailsSelectRecords.add(bss);
@@ -529,9 +474,7 @@
          }
          Integer ishosnum = 0;
          for (
            ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords
          ) {
                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
            //ass.sortBy = sortOrderAsc;
            //add by rentx 2021-3-10
            if (ass.hospitalSpecialOffer) {
@@ -630,9 +573,7 @@
            WHERE Consumable_order__c = :coc.Arrive_Order__c
            ORDER BY Name
          ];
          for (
            Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
          ) {
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
            orderzaikuId.add(cdc1.Consumable_Product__c);
          }
          msoql = makeSoqlorderdet();
@@ -640,10 +581,7 @@
          size = product2Selected.size();
          initStandardController(msoql);
          for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(
              product2Selected[i].Id,
              new ConsumableorderdetailsInfo(product2Selected[i])
            );
                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          }
          //update by rentx 2021-01-29
          /*for(Integer i = 0 ; i< CountDel.size();i++){
@@ -671,12 +609,8 @@
            //明细2对应的产品存在于MidMap中
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
              //设置map中key的后缀 用于区分医院特价和非医院特价
              if (
                MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)
              ) {
                ConsumableorderdetailsInfo Jstage = MidMap2.get(
                  CountDel[i].Consumable_Product__c + str
                );
                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -695,10 +629,7 @@
                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
              } else {
                //midmap2中没有对应的产品
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                    CountDel[i].Consumable_Product__c
                  )
                  .clone();
                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -725,9 +656,7 @@
          // for(ConsumableorderdetailsInfo bss : MidMap.values()){
          for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
            //update by rentx 2021-01-29
            bss.packinglist = Integer.valueOf(
              bss.Prod.Product2__r.Packing_list_manual__c
            );
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
            bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
            bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
            consumableorderdetailsSelectRecords.add(bss);
@@ -736,13 +665,9 @@
          //return;
          Integer ishosnum = 0;
          for (
            ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords
          ) {
                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
            //ass.sortBy = sortOrderAsc;
            for (
              Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
            ) {
                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
              cdc1.Shipment_Count__c = cdc1.Consumable_count__c;
              if (ass.prod.Id == cdc1.Consumable_Product__c) {
                ass.check = true;
@@ -798,25 +723,14 @@
              AND Dealer_Arrive__c = TRUE
            ORDER BY Name
          ];
          for (
            Integer i = 0;
            i < consumablearriveproductdetailsSelected.size();
            i++
          ) {
                    for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
            if (
              consumablearriveproductdetailsSelected[i]
                .hospitalSpecialOffer__c &&
              HosProMap.containsKey(
                consumablearriveproductdetailsSelected[i].Consumable_product__c
              )
                            consumablearriveproductdetailsSelected[i].hospitalSpecialOffer__c &&
                            HosProMap.containsKey(consumablearriveproductdetailsSelected[i].Consumable_product__c)
            ) {
              coc.OutPattern__c = true;
            }
            consumableproductdetailsRecords.add(
              new ConsumableorderdetailsInfo(
                consumablearriveproductdetailsSelected[i]
              )
            );
                        consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
          }
        }
      } else {
@@ -824,20 +738,10 @@
        SummonsFlag = 'visible';
        // update start by vivek 2019-7-15 add “NoConfirmedPrice__c” in select
        consumableInvoiceRecords = [
          SELECT
            Id,
            Name,
            Invoice_Date__c,
            NoConfirmedPrice__c,
            Invoice_total_amount__c,
            Invoice_status__c
                    SELECT Id, Name, Invoice_Date__c, NoConfirmedPrice__c, Invoice_total_amount__c, Invoice_status__c
          FROM Consumable_order__c
          WHERE
            Id IN (
              SELECT Invoice_Code_link__c
              FROM Consumable_order_LinkTable__c
              WHERE Outboundorder_Code_link__c = :ESetId
            )
                        Id IN (SELECT Invoice_Code_link__c FROM Consumable_order_LinkTable__c WHERE Outboundorder_Code_link__c = :ESetId)
            AND Invoice_status__c != '草案中'
        ];
@@ -870,10 +774,7 @@
            Onchange_order__c,
            OutPattern__c
          FROM Consumable_order__c
          WHERE
            Id = :ESetId
            AND Order_Owner_WorkLocal__c = :userWorkLocation
            AND Order_type__c = '传票'
                    WHERE Id = :ESetId AND Order_Owner_WorkLocal__c = :userWorkLocation AND Order_type__c = '传票'
        ];
        // update start by vivek 2019-7-15
        if (getExistarrive()) {
@@ -884,10 +785,7 @@
          if (editAble) {
            alertMessage = '到货订单直接出库,出库单明细不可编辑';
          }
          if (
            coc.SummonsStatus_c__c == '已提交' ||
            coc.SummonsStatus_c__c == '批准'
          ) {
                    if (coc.SummonsStatus_c__c == '已提交' || coc.SummonsStatus_c__c == '批准') {
            system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
            saveBtnDisabled = true;
            SorderBtnDisabled = true;
@@ -896,10 +794,7 @@
          //医院二级经销商分类
          Integer io = 0;
          while (io < Dealerelationship.size()) {
            if (
              coc.Order_ForDealer__c ==
              Dealerelationship[io].Dealer_subordinate__c
            ) {
                        if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
              SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
              coc.Order_ForDealer__c = null;
              io = io + Dealerelationship.size();
@@ -909,9 +804,7 @@
          Integer ik = 0;
          while (ik < AgencyHospitalLink.size()) {
            if (
              coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c
            ) {
                        if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
              HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
              HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
              coc.Order_ForHospital__c = null;
@@ -948,16 +841,12 @@
              Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
              isOutPattern__c
            FROM Consumable_orderdetails__c
            WHERE
              Consumable_order__c = :ESetId
              AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
                        WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
            ORDER BY Name
          ];
          Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
          for (
            Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
          ) {
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
            sumPrice += cdc1.Shipment_amount__c;
            orderzaikuId.add(cdc1.Consumable_Product__c);
            //add by rentx 2021-2-26
@@ -975,10 +864,7 @@
          initStandardController(msoql);
          for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(
              product2Selected[i].Id,
              new ConsumableorderdetailsInfo(product2Selected[i])
            );
                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          }
          //update by rentx 2021-01-29
          /*for(Integer i = 0 ; i< CountDel.size();i++){
@@ -1006,12 +892,8 @@
            //明细2对应的产品存在于MidMap中
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
              //设置map中key的后缀 用于区分医院特价和非医院特价
              if (
                MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)
              ) {
                ConsumableorderdetailsInfo Jstage = MidMap2.get(
                  CountDel[i].Consumable_Product__c + str
                );
                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1030,10 +912,7 @@
                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
              } else {
                //midmap2中没有对应的产品
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                    CountDel[i].Consumable_Product__c
                  )
                  .clone();
                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1063,22 +942,14 @@
            //if(bss.allnumber > 0){
            //bss.UnitpriceToagency = bss.orderdetails1.Unitprice_To_agency__c == null  || bss.orderdetails1.Unitprice_To_agency__c == 0 ? '' :bss.orderdetails1.Unitprice_To_agency__c.format();
            bss.packinglist = Integer.valueOf(
              bss.Prod.Product2__r.Packing_list_manual__c
            );
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
            bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
            bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
            //update by rentx 2021-2-26 start
            if (
              cocMap.containsKey(bss.Prod.Id + 'ishos') &&
              bss.hospitalSpecialOffer == true
            ) {
                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
              consumableorderdetailsSelectRecords.add(bss);
            } else if (
              cocMap.containsKey(bss.Prod.Id + 'nothos') &&
              bss.hospitalSpecialOffer == false
            ) {
                        } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
              consumableorderdetailsSelectRecords.add(bss);
            }
            //update by rentx 2021-2-26 end
@@ -1086,21 +957,14 @@
            //}
          }
          Integer ishosnum = 0;
          for (
            ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords
          ) {
            for (
              Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
            ) {
                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
              //update by rentx 2012-3-1 start
              // if(ass.prod.Id == cdc1.Consumable_Product__c){
              //     ass.check = true;
              //     ass.orderdetails1 = cdc1;
              // }
              if (
                ass.Prod.Id == cdc1.Consumable_Product__c &&
                ass.hospitalSpecialOffer == cdc1.isOutPattern__c
              ) {
                            if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
                ass.check = true;
                ass.orderdetails1 = cdc1;
              }
@@ -1147,14 +1011,8 @@
            WHERE Consumable_ZS_order__c = :ESetId
            ORDER BY Name
          ];
          for (
            Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++
          ) {
            consumableorderdetails2Records.add(
              new ConsumableorderdetailsInfo(
                consumableorderdetails2RecordsList[i]
              )
            );
                    for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
                        consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
          }
          //产品明细取得
          consumablearriveproductdetailsSelected = [
@@ -1181,23 +1039,12 @@
            WHERE Consumable_ZS_order__c = :ESetId
            ORDER BY Name
          ];
          for (
            Integer i = 0;
            i < consumablearriveproductdetailsSelected.size();
            i++
          ) {
            consumableproductdetailsRecords.add(
              new ConsumableorderdetailsInfo(
                consumablearriveproductdetailsSelected[i]
              )
            );
                    for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
                        consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
          }
        } else {
          // 不是到货订单来的时候
          if (
            coc.SummonsStatus_c__c == '已提交' ||
            coc.SummonsStatus_c__c == '批准'
          ) {
                    if (coc.SummonsStatus_c__c == '已提交' || coc.SummonsStatus_c__c == '批准') {
            system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
            saveBtnDisabled = true;
            SorderBtnDisabled = true;
@@ -1206,10 +1053,7 @@
          //医院二级经销商分类
          Integer io = 0;
          while (io < Dealerelationship.size()) {
            if (
              coc.Order_ForDealer__c ==
              Dealerelationship[io].Dealer_subordinate__c
            ) {
                        if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
              SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
              coc.Order_ForDealer__c = null;
              io = io + Dealerelationship.size();
@@ -1218,9 +1062,7 @@
          }
          Integer ik = 0;
          while (ik < AgencyHospitalLink.size()) {
            if (
              coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c
            ) {
                        if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
              HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
              HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
              coc.Order_ForHospital__c = null;
@@ -1257,17 +1099,13 @@
              Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
              isOutPattern__c
            FROM Consumable_orderdetails__c
            WHERE
              Consumable_order__c = :ESetId
              AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
                        WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
            ORDER BY Name
          ];
          //add by rentx 202-2-26
          Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
          for (
            Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
          ) {
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
            sumPrice += cdc1.Shipment_amount__c;
            orderzaikuId.add(cdc1.Consumable_Product__c);
            //add by rentx 2021-2-26
@@ -1285,10 +1123,7 @@
          size = product2Selected.size();
          initStandardController(msoql);
          for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(
              product2Selected[i].Id,
              new ConsumableorderdetailsInfo(product2Selected[i])
            );
                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          }
          for (Integer i = 0; i < CountDel.size(); i++) {
@@ -1301,12 +1136,8 @@
            //明细2对应的产品存在于MidMap中
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
              //设置map中key的后缀 用于区分医院特价和非医院特价
              if (
                MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)
              ) {
                ConsumableorderdetailsInfo Jstage = MidMap2.get(
                  CountDel[i].Consumable_Product__c + str
                );
                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1324,10 +1155,7 @@
                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
              } else {
                //midmap2中没有对应的产品
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                    CountDel[i].Consumable_Product__c
                  )
                  .clone();
                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                Jstage.allnumber = Jstage.allnumber + 1;
                if (CountDel[i].Box_Piece__c == '盒') {
                  Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1356,22 +1184,14 @@
            //update by rentx 2021-01-29
            //if(bss.allnumber>0){
            bss.packinglist = Integer.valueOf(
              bss.Prod.Product2__r.Packing_list_manual__c
            );
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
            bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
            bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
            //update by rentx 2021-2-26 start
            if (
              cocMap.containsKey(bss.Prod.Id + 'ishos') &&
              bss.hospitalSpecialOffer == true
            ) {
                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
              consumableorderdetailsSelectRecords.add(bss);
            } else if (
              cocMap.containsKey(bss.Prod.Id + 'nothos') &&
              bss.hospitalSpecialOffer == false
            ) {
                        } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
              consumableorderdetailsSelectRecords.add(bss);
            }
            // consumableorderdetailsSelectRecords.add(bss);
@@ -1379,22 +1199,15 @@
          }
          // return null;
          Integer ishosnum = 0;
          for (
            ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords
          ) {
                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
            //ass.sortBy = sortOrderAsc;
            for (
              Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected
            ) {
                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
              //update by rentx 2012-3-1 start
              // if(ass.prod.Id == cdc1.Consumable_Product__c){
              //     ass.check = true;
              //     ass.orderdetails1 = cdc1;
              // }
              if (
                ass.Prod.Id == cdc1.Consumable_Product__c &&
                ass.hospitalSpecialOffer == cdc1.isOutPattern__c
              ) {
                            if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
                ass.check = true;
                ass.orderdetails1 = cdc1;
              }
@@ -1445,14 +1258,8 @@
            WHERE Consumable_ZS_order__c = :ESetId
            ORDER BY Name
          ];
          for (
            Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++
          ) {
            consumableorderdetails2Records.add(
              new ConsumableorderdetailsInfo(
                consumableorderdetails2RecordsList[i]
              )
            );
                    for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
                        consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
          }
        }
      }
@@ -1462,15 +1269,9 @@
        provinceOptsMap.put('', '-无-');
        for (Integer i = 0; i < Dealerelationship.size(); i++) {
          provinceOpts.add(
            new SelectOption(
              Dealerelationship[i].Dealer_subordinate__c,
              Dealerelationship[i].Dealer_subordinate__r.Name
            )
                        new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
          );
          provinceOptsMap.put(
            Dealerelationship[i].Dealer_subordinate__c,
            Dealerelationship[i].Dealer_subordinate__r.Name
          );
                    provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
        }
      } else {
        provinceOpts.add(new SelectOption('', '-无-'));
@@ -1478,29 +1279,17 @@
        for (Integer i = 0; i < Dealerelationship.size(); i++) {
          if (Dealerelationship[i].Dealer_subordinate__c == SecondDealer) {
            provinceOpts.add(
              new SelectOption(
                Dealerelationship[i].Dealer_subordinate__c,
                Dealerelationship[i].Dealer_subordinate__r.Name
              )
                            new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
            );
            provinceOptsMap.put(
              Dealerelationship[i].Dealer_subordinate__c,
              Dealerelationship[i].Dealer_subordinate__r.Name
            );
                        provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
          }
        }
        for (Integer i = 0; i < Dealerelationship.size(); i++) {
          if (Dealerelationship[i].Dealer_subordinate__c != SecondDealer) {
            provinceOpts.add(
              new SelectOption(
                Dealerelationship[i].Dealer_subordinate__c,
                Dealerelationship[i].Dealer_subordinate__r.Name
              )
                            new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
            );
            provinceOptsMap.put(
              Dealerelationship[i].Dealer_subordinate__c,
              Dealerelationship[i].Dealer_subordinate__r.Name
            );
                        provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
          }
        }
      }
@@ -1512,16 +1301,10 @@
      // 显示数据条数信息
      //    makeMessage();
      //附件
      attachmentinfo = [
        SELECT Id, Name, OwnerId
        FROM Attachment
        WHERE parentid = :ESetId
      ];
            attachmentinfo = [SELECT Id, Name, OwnerId FROM Attachment WHERE parentid = :ESetId];
      if (attachmentinfo.size() > 0) {
        for (Integer i = 0; i < attachmentinfo.size(); i++) {
          attachmentRecoeds.add(
            new ConsumableorderdetailsInfo(attachmentinfo[i])
          );
                    attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
        }
      }
      AggregateResult[] categoryList = [
@@ -1561,18 +1344,12 @@
      System.debug('pageToken = ' + pageToken);
      System.debug('pageSize = ' + pageSize);
      System.debug('totalCount = ' + totalCount);
      paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount)
        ? pageToken + pageSize
        : null;
      System.debug(
        'paginatedAccounts.nextPageToken = ' + paginatedAccounts.nextPageToken
      );
            paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
            System.debug('paginatedAccounts.nextPageToken = ' + paginatedAccounts.nextPageToken);
      paginatedAccounts.recordStart = pageToken + 1;
      paginatedAccounts.pageNumber = pageToken / pageSize + 1;
      Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
      paginatedAccounts.recordEnd = totalCount >= recordEnd
        ? recordEnd
        : totalCount;
            paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
      paginatedAccounts.totalRecords = totalCount;
      Integer startIdx;
@@ -1589,17 +1366,12 @@
      Boolean Existarrive = (coc.Arrive_Order__c != null);
      String ConsumableOut_report = System.Label.ConsumableOut_report;
      System.debug(
        'consumableproductdetailsRecords = ' + consumableproductdetailsRecords
      );
            System.debug('consumableproductdetailsRecords = ' + consumableproductdetailsRecords);
      data.put('paginatedAccounts', paginatedAccounts);
      data.put('ConsumableOut_report', ConsumableOut_report);
      data.put('accountid', accountid);
      data.put(
        'consumableproductdetailsRecords',
        consumableproductdetailsRecords
      );
            data.put('consumableproductdetailsRecords', consumableproductdetailsRecords);
      data.put('agencyProType', agencyProType);
      data.put('accountName', accountName);
      data.put('userWorkLocation', userWorkLocation);
@@ -1619,22 +1391,14 @@
      data.put('pageRecords', pageRecordsTemp);
      data.put('arriveorder', arriveorder);
      data.put('consumableorderdetails2Count', consumableorderdetails2Count);
      data.put(
        'consumableorderdetails2Records',
        consumableorderdetails2Records
      );
            data.put('consumableorderdetails2Records', consumableorderdetails2Records);
      data.put('HospitalInfo', HospitalInfo);
      res.status = 'Success';
      res.code = 200;
      System.debug('res = ' + res);
      return res;
    } catch (Exception e) {
      return new ResponseBodyLWC(
        'Error',
        500,
        e.getMessage() + e.getLineNumber(),
        ''
      );
            return new ResponseBodyLWC('Error',500, e.getMessage() + e.getLineNumber(), '');
    }
  }
@@ -1648,12 +1412,10 @@
    AggregateResult[] category4List = [
      SELECT Count(id), Category4_text__c c4c
      FROM Product2__c
      WHERE
        Category3_text__c = :category3
        AND Category4_text__c != NULL
        AND Category5_text__c != NULL
            WHERE Category3_text__c = :category3 AND Category4_text__c != NULL AND Category5_text__c != NULL
      GROUP BY Category4_text__c
    ];
        System.debug('category4List ' + category4List);
    category4OptionList = new List<SelectOption>();
    category4OptionList.add(new SelectOption('', '-无-'));
    category4OptionMap = new Map<String, String>();
@@ -1667,13 +1429,11 @@
    AggregateResult[] category5List = [
      SELECT Count(id), Category5_text__c c5c
      FROM Product2__c
      WHERE
        Category3_text__c = :category3
        AND Category4_text__c != NULL
        AND Category5_text__c != NULL
            WHERE Category3_text__c = :category3 AND Category4_text__c != NULL AND Category5_text__c != NULL
      GROUP BY Category5_text__c
    ];
        System.debug('category5List ' + category5List);
    category5OptionList = new List<SelectOption>();
    category5OptionList.add(new SelectOption('', '-无-'));
    category5OptionMap = new Map<String, String>();
@@ -1692,10 +1452,7 @@
  }
  @AuraEnabled
  public static ResponseBodyLWC categoryload(
    String category3Lwc,
    String category4Lwc
  ) {
    public static ResponseBodyLWC categoryload(String category3Lwc, String category4Lwc) {
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
    res.entity = data;
@@ -1705,12 +1462,10 @@
    AggregateResult[] category4List = [
      SELECT Count(id), Category4_text__c c4c
      FROM Product2__c
      WHERE
        Category3_text__c = :category3
        AND Category4_text__c != NULL
        AND Category5_text__c != NULL
            WHERE Category3_text__c = :category3 AND Category4_text__c != NULL AND Category5_text__c != NULL
      GROUP BY Category4_text__c
    ];
        System.debug('category4List ' + category4List);
    category4OptionList = new List<SelectOption>();
    category4OptionList.add(new SelectOption('', '-无-'));
    category4OptionMap = new Map<String, String>();
@@ -1724,13 +1479,11 @@
    AggregateResult[] category5List = [
      SELECT Count(id), Category5_text__c c5c
      FROM Product2__c
      WHERE
        Category3_text__c = :category3
        AND Category4_text__c = :category4
        AND Category5_text__c != NULL
            WHERE Category3_text__c = :category3 AND Category4_text__c = :category4 AND Category5_text__c != NULL
      GROUP BY Category5_text__c
    ];
        System.debug('category5List ' + category5List);
    category5OptionList = new List<SelectOption>();
    category5OptionList.add(new SelectOption('', '-无-'));
    category5OptionMap = new Map<String, String>();
@@ -1798,6 +1551,8 @@
        AND Arrive_Owner_Work_Location__c = :userWorkLocationLwc
      GROUP BY Consumable_Product__c, Box_Piece__c
    ];
        System.debug('orderdetailCount = ' + orderdetailCount);
    for (AggregateResult orderdetail : orderdetailCount) {
      zaikuId.add(String.valueOf(orderdetail.get('cpc')));
    }
@@ -1814,9 +1569,7 @@
    String countdelSoql = 'SELECT Id,Bar_Code__c,Name,Inventory_date__c,Consumable_Product__c,Consumable_Product__r.Asset_Model_No__c,Recordtypeid,Box_Piece__c,ProductPacking_list_manual__c,hospitalSpecialOffer__c FROM Consumable_order_details2__c WHERE  Dealer_Arrive__c = true AND Dealer_Shipment__c = false AND Dealer_Saled__c = false AND Dealer_Returned__c = false AND Lose_Flag__c = false AND Bar_Code__c != null AND Isoverdue__c = 1 AND Arrive_Owner_Work_Location__c =  :userWorkLocation AND Dealer_Info_text__c = :accountName ';
    if (String.isNotBlank(outOutPattern) && outOutPattern.equals('ishos')) {
      countdelSoql += ' AND hospitalSpecialOffer__c = true';
    } else if (
      String.isNotBlank(outOutPattern) && outOutPattern.equals('nothos')
    ) {
        } else if (String.isNotBlank(outOutPattern) && outOutPattern.equals('nothos')) {
      countdelSoql += ' AND hospitalSpecialOffer__c = false';
    }
    System.debug('countdelSoql = ' + countdelSoql);
@@ -1832,10 +1585,7 @@
    System.debug('soql = ' + soql);
    product2Selected = Database.query(soql);
    for (Integer i = 0; i < product2Selected.size(); i++) {
      MidMap.put(
        product2Selected[i].Id,
        new ConsumableorderdetailsInfo(product2Selected[i])
      );
            MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
    }
    for (Integer i = 0; i < CountDel.size(); i++) {
@@ -1850,9 +1600,7 @@
      if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
        //设置map中key的后缀 用于区分医院特价和非医院特价
        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
          ConsumableorderdetailsInfo Jstage = MidMap2.get(
            CountDel[i].Consumable_Product__c + str
          );
                    ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
          Jstage.allnumber = Jstage.allnumber + 1;
          if (CountDel[i].Box_Piece__c == '盒') {
            Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1870,10 +1618,7 @@
          MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
        } else {
          //midmap2中没有对应的产品
          ConsumableorderdetailsInfo Jstage = MidMap.get(
              CountDel[i].Consumable_Product__c
            )
            .clone();
                    ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
          Jstage.allnumber = Jstage.allnumber + 1;
          if (CountDel[i].Box_Piece__c == '盒') {
            Jstage.Boxnumber = Jstage.Boxnumber + 1;
@@ -1900,9 +1645,7 @@
        continue;
      } else {
        bss.sortBy = false;
        bss.packinglist = Integer.valueOf(
          bss.Prod.Product2__r.Packing_list_manual__c
        );
                bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
        consumableorderdetailsSelectRecords.add(bss);
@@ -1923,15 +1666,11 @@
    //分页
    PaginatedAccounts paginatedAccounts = new PaginatedAccounts();
    totalCount = pageRecords.size();
    paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount)
      ? pageToken + pageSize
      : null;
        paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
    paginatedAccounts.recordStart = pageToken + 1;
    paginatedAccounts.pageNumber = pageToken / pageSize + 1;
    Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
    paginatedAccounts.recordEnd = totalCount >= recordEnd
      ? recordEnd
      : totalCount;
        paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
    paginatedAccounts.totalRecords = totalCount;
    System.debug('addSize = ' + addSize);
@@ -1954,10 +1693,7 @@
    System.debug('pageRecords = ' + pageRecords.size());
    String hos = '';
    for (Integer i = startIdx; i < endIdx; i++) {
      System.debug(
        'skipData.get(pageRecords.get(i).Prod.Id) = ' +
        skipData.get(pageRecords.get(i).Prod.Id)
      );
            System.debug('skipData.get(pageRecords.get(i).Prod.Id) = ' + skipData.get(pageRecords.get(i).Prod.Id));
      if (pageRecords.get(i).hospitalSpecialOffer == true) {
        hos = 'ishos';
      } else {
@@ -1979,12 +1715,7 @@
    return res;
  }
  private static String makeSoql(
    String CateName,
    String Category3,
    String Category4,
    String Category5
  ) {
    private static String makeSoql(String CateName, String Category3, String Category4, String Category5) {
    String sqlTail1 = '(\'';
    for (Integer i = 0; i < zaikuId.size(); i++) {
      if (zaikuId[i] != null) {
@@ -2088,19 +1819,12 @@
    //Integer pageendNo = (setCon.getPageNumber() * size)>noOfRecords ? noOfRecords :(setCon.getPageNumber() * size-1);
    Integer addNo = 0;
    //update by rentx 2021-2-26 start
    System.debug(
      'consumableorderdetailsSelectRecords.size() = ' +
      consumableorderdetailsSelectRecords.size()
    );
    for (
      ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords
    ) {
        System.debug('consumableorderdetailsSelectRecords.size() = ' + consumableorderdetailsSelectRecords.size());
        for (ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords) {
      Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
      if (
        (info.hospitalSpecialOffer &&
        selectedIdMap.containsKey(info.Prod.Id + 'ishos')) ||
        (info.hospitalSpecialOffer == false &&
        selectedIdMap.containsKey(info.Prod.Id + 'nothos'))
                (info.hospitalSpecialOffer && selectedIdMap.containsKey(info.Prod.Id + 'ishos')) ||
                (info.hospitalSpecialOffer == false && selectedIdMap.containsKey(info.Prod.Id + 'nothos'))
      ) {
        addNo++;
      } else {
@@ -2177,19 +1901,12 @@
    //Integer pageendNo = (setCon.getPageNumber() * size)>noOfRecords ? noOfRecords :(setCon.getPageNumber() * size-1);
    Integer addNo = 0;
    //update by rentx 2021-2-26 start
    System.debug(
      'consumableorderdetailsSelectRecords.size() = ' +
      consumableorderdetailsSelectRecords.size()
    );
    for (
      ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords
    ) {
        System.debug('consumableorderdetailsSelectRecords.size() = ' + consumableorderdetailsSelectRecords.size());
        for (ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords) {
      Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
      if (
        (info.hospitalSpecialOffer &&
        selectedIdMap.containsKey(info.Prod.Id + 'ishos')) ||
        (info.hospitalSpecialOffer == false &&
        selectedIdMap.containsKey(info.Prod.Id + 'nothos'))
                (info.hospitalSpecialOffer && selectedIdMap.containsKey(info.Prod.Id + 'ishos')) ||
                (info.hospitalSpecialOffer == false && selectedIdMap.containsKey(info.Prod.Id + 'nothos'))
      ) {
        System.debug('去掉的id : ' + info.Prod.Id);
        addNo++;
@@ -2238,9 +1955,7 @@
    System.debug('SecondDealer = ' + SecondDealer);
    System.debug('pageRecordsLwc = ' + pageRecordsLwc);
    System.debug('accountid = ' + accountid);
    System.debug(
      'consumableproductdetailsRecords = ' + consumableproductdetailsRecords
    );
        System.debug('consumableproductdetailsRecords = ' + consumableproductdetailsRecords);
    System.debug('ESetId = ' + ESetId);
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
@@ -2260,18 +1975,10 @@
        // coc.Order_ForCustomerText__c.addError('请输入科室');
        // return null;
        return new ResponseBodyLWC('Error', 500, '请输入科室', '');
      } else if (
        String.isNotBlank(SecondDealer) ||
        String.isNotBlank(coc.Order_ForDealerText__c)
      ) {
            } else if (String.isNotBlank(SecondDealer) || String.isNotBlank(coc.Order_ForDealerText__c)) {
        // coc.addError('不需要二级经销商和经销商(录入)信息' );
        // return null;
        return new ResponseBodyLWC(
          'Error',
          500,
          '不需要二级经销商和经销商(录入)信息',
          ''
        );
                return new ResponseBodyLWC('Error', 500, '不需要二级经销商和经销商(录入)信息', '');
      }
    } else if (coc.SummonsForDirction__c == '医院试用') {
      if (String.isBlank(HospitalInfo) || String.isBlank(HospitalName)) {
@@ -2285,18 +1992,10 @@
        return new ResponseBodyLWC('Error', 500, '请输入科室', '');
      }
    } else if (coc.SummonsForDirction__c == '销售给二级经销商') {
      if (
        String.isBlank(SecondDealer) &&
        String.isBlank(coc.Order_ForDealerText__c)
      ) {
            if (String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)) {
        // coc.addError('必须输入二级经销商或经销商(录入)');
        // return null;
        return new ResponseBodyLWC(
          'Error',
          500,
          '必须输入二级经销商或经销商(录入)',
          ''
        );
                return new ResponseBodyLWC('Error', 500, '必须输入二级经销商或经销商(录入)', '');
      }
      if (String.isBlank(HospitalInfo) || String.isBlank(HospitalName)) {
        // coc.addError('请输入医院');
@@ -2319,18 +2018,10 @@
        // return null;
        return new ResponseBodyLWC('Error', 500, '不需要输入科室', '');
      }
      if (
        String.isBlank(SecondDealer) &&
        String.isBlank(coc.Order_ForDealerText__c)
      ) {
            if (String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)) {
        // coc.addError('必须输入二级经销商或经销商(录入)');
        // return null;
        return new ResponseBodyLWC(
          'Error',
          500,
          '必须输入二级经销商或经销商(录入)',
          ''
        );
                return new ResponseBodyLWC('Error', 500, '必须输入二级经销商或经销商(录入)', '');
      }
    }
@@ -2374,11 +2065,7 @@
    //特价医院出库非本医院维护的特价商品时,报错 非特价医院出库维护在医院特价关系表的产品时 报错
    if (coc.SummonsForDirction__c != '互相调货') {
      //非特价医院出库特价产品时 报错(当前经销商下没有特价医院除外)
      List<hospitalprice__c> hopList = [
        SELECT id, hospital__c, product__c
        FROM hospitalprice__c
        WHERE account__c = :accountid
      ];
            List<hospitalprice__c> hopList = [SELECT id, hospital__c, product__c FROM hospitalprice__c WHERE account__c = :accountid];
      //经销商对应医院下的所有特价产品
      Map<String, String> proMap = new Map<String, String>();
      //经销商下的所有特价产品
@@ -2410,12 +2097,7 @@
                //用户选中非当前医院维护的特价产品
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '当前医院没有维护 消耗品:'+ ass.Prod.Name__c +' 的特价'));
                // return null;
                return new ResponseBodyLWC(
                  'Error',
                  500,
                  '当前医院没有维护 消耗品:' + ass.Prod.Name__c + '的特价',
                  ''
                );
                                return new ResponseBodyLWC('Error', 500, '当前医院没有维护 消耗品:' + ass.Prod.Name__c + '的特价', '');
              }
            } //非医院特价产品可以出库给任意医院,所以不需要判断
          }
@@ -2472,9 +2154,7 @@
      p.Name = '*';
      p.Order_type__c = '传票';
      p.Order_ProType__c = agencyProType;
      if (
        coc.SummonsStatus_c__c == null || String.isBlank(coc.SummonsStatus_c__c)
      )
            if (coc.SummonsStatus_c__c == null || String.isBlank(coc.SummonsStatus_c__c))
        coc.SummonsStatus_c__c = '草案中';
      // update strat by vivek 2019-7-12
      p.NoConfirmedPrice__c = coc.NoConfirmedPrice__c;
@@ -2486,14 +2166,10 @@
      p.Offers_Price__c = coc.Offers_Price__c;
      p.Dealer_Info__c = accountid;
      if (String.isBlank(SecondDealer)) {
        p.Order_ForHospital__c = String.isNotBlank(HospitalInfo)
          ? HospitalInfo
          : null;
                p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
        p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
      } else {
        p.Order_ForHospital__c = String.isNotBlank(HospitalInfo)
          ? HospitalInfo
          : null;
                p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
        p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
        p.Order_ForDealer__c = SecondDealer;
      }
@@ -2512,29 +2188,12 @@
      for (ConsumableorderdetailsInfoLwc ass : pageRecordsLwc) {
        if (ass.check == true) {
          if (ass.orderdetails1.Delivery_List_RMB__c < 0) {
            return new ResponseBodyLWC(
              'Error',
              500,
              '请输入正确的出货单价 (元)',
              ''
            );
                        return new ResponseBodyLWC('Error', 500, '请输入正确的出货单价 (元)', '');
          }
          if (
            ass.orderdetails1.Delivery_List_RMB__c == null &&
            coc.SummonsForDirction__c != '医院试用'
          ) {
            return new ResponseBodyLWC(
              'Error',
              500,
              '请输入正确的出货单价 (元)',
              ''
            );
                    if (ass.orderdetails1.Delivery_List_RMB__c == null && coc.SummonsForDirction__c != '医院试用') {
                        return new ResponseBodyLWC('Error', 500, '请输入正确的出货单价 (元)', '');
          }
          if (
            (ass.orderdetails1.Delivery_List_RMB__c == null ||
            ass.orderdetails1.Delivery_List_RMB__c == 0) &&
            coc.SummonsForDirction__c != '医院试用'
          ) {
                    if ((ass.orderdetails1.Delivery_List_RMB__c == null || ass.orderdetails1.Delivery_List_RMB__c == 0) && coc.SummonsForDirction__c != '医院试用') {
            return new ResponseBodyLWC('Error', 500, '请输入出货单价 (元)', '');
          }
          if (
@@ -2544,19 +2203,13 @@
          ) {
            return new ResponseBodyLWC('Error', 500, '请输入出货单价 (元)', '');
          }
          if (
            ass.orderdetails1.Shipment_Count__c == null ||
            ass.orderdetails1.Shipment_Count__c == 0
          ) {
                    if (ass.orderdetails1.Shipment_Count__c == null || ass.orderdetails1.Shipment_Count__c == 0) {
            // ass.orderdetails1.Shipment_Count__c.addError('请输入出货数量');
            // return null;
            return new ResponseBodyLWC('Error', 500, '请输入出货数量', '');
          }
          if (
            ass.orderdetails1.Box_Piece__c == null ||
            ass.orderdetails1.Box_Piece__c == ''
          ) {
                    if (ass.orderdetails1.Box_Piece__c == null || ass.orderdetails1.Box_Piece__c == '') {
            // ass.orderdetails1.Box_Piece__c.addError('请输入单位');
            // return null;
            return new ResponseBodyLWC('Error', 500, '请输入单位', '');
@@ -2566,12 +2219,7 @@
              //ass.orderdetails1.Shipment_Count__c.addError('库存不足');
              if (ass.oldCheck == false) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                return new ResponseBodyLWC(
                  'Error',
                  500,
                  '消耗品' + ass.Prod.Name__c + '库存不足',
                  ''
                );
                                return new ResponseBodyLWC('Error', 500, '消耗品' + ass.Prod.Name__c + '库存不足', '');
              } else {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                return new ResponseBodyLWC(
@@ -2589,12 +2237,7 @@
              //ass.orderdetails1.Shipment_Count__c.addError('库存不足');
              if (ass.oldCheck == false) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                return new ResponseBodyLWC(
                  'Error',
                  500,
                  '消耗品' + ass.Prod.Name__c + '库存不足',
                  ''
                );
                                return new ResponseBodyLWC('Error', 500, '消耗品' + ass.Prod.Name__c + '库存不足', '');
              } else {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                return new ResponseBodyLWC(
@@ -2613,11 +2256,7 @@
      insert p;
      ESetId = p.id;
      List<Consumable_order__c> detailName = new List<Consumable_order__c>();
      detailName = [
        SELECT id, Name
        FROM Consumable_order__c
        WHERE id = :ESetId
      ];
            detailName = [SELECT id, Name FROM Consumable_order__c WHERE id = :ESetId];
      Integer i = 1;
      for (ConsumableorderdetailsInfoLwc ass : pageRecordsLwc) {
        if (ass.check == true) {
@@ -2668,14 +2307,7 @@
      List<Consumable_order__c> cocinfo = new List<Consumable_order__c>();
      // update start by vivek 2019-7-15 add "NoConfirmedPrice__c" in select
      cocinfo = [
        SELECT
          Id,
          Name,
          SummonsStatus_c__c,
          NoConfirmedPrice__c,
          Dealer_Info__c,
          Order_ForHospital__c,
          SummonsForDirction__c
                SELECT Id, Name, SummonsStatus_c__c, NoConfirmedPrice__c, Dealer_Info__c, Order_ForHospital__c, SummonsForDirction__c
        FROM Consumable_order__c
        WHERE Id = :ESetId
      ];
@@ -2687,16 +2319,12 @@
      p.Dealer_Info__c = accountid;
      p.Order_ProType__c = agencyProType;
      if (String.isEmpty(SecondDealer)) {
        p.Order_ForHospital__c = String.isNotBlank(HospitalInfo)
          ? HospitalInfo
          : null;
                p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
        p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
        System.debug('SecondDealer = ' + SecondDealer);
        p.Order_ForDealer__c = null;
      } else {
        p.Order_ForHospital__c = String.isNotBlank(HospitalInfo)
          ? HospitalInfo
          : null;
                p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
        p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
        p.Order_ForDealer__c = SecondDealer;
      }
@@ -2720,19 +2348,10 @@
      for (ConsumableorderdetailsInfoLwc ass : pageRecordsLwc) {
        if (ass.check == true) {
          if (ass.orderdetails1.Delivery_List_RMB__c < 0) {
            return new ResponseBodyLWC(
              'Error',
              500,
              '请输入正确的出货单价 (元)',
              ''
            );
                        return new ResponseBodyLWC('Error', 500, '请输入正确的出货单价 (元)', '');
          }
          Consumable_orderdetails__c InsAfterDel = new Consumable_orderdetails__c();
          if (
            (ass.orderdetails1.Delivery_List_RMB__c == null ||
            ass.orderdetails1.Delivery_List_RMB__c == 0) &&
            coc.SummonsForDirction__c != '医院试用'
          ) {
                    if ((ass.orderdetails1.Delivery_List_RMB__c == null || ass.orderdetails1.Delivery_List_RMB__c == 0) && coc.SummonsForDirction__c != '医院试用') {
            return new ResponseBodyLWC('Error', 500, '请输入出货单价 (元)', '');
          }
          if (
@@ -2742,10 +2361,7 @@
          ) {
            return new ResponseBodyLWC('Error', 500, '请输入出货单价 (元)', '');
          }
          if (
            ass.orderdetails1.Box_Piece__c == null ||
            ass.orderdetails1.Box_Piece__c == ''
          ) {
                    if (ass.orderdetails1.Box_Piece__c == null || ass.orderdetails1.Box_Piece__c == '') {
            // ass.orderdetails1.Box_Piece__c.addError('请输入单位');
            // return null;
            return new ResponseBodyLWC('Error', 500, '请输入单位', '');
@@ -2755,12 +2371,7 @@
              //ass.orderdetails1.Shipment_Count__c.addError('库存不足');
              if (ass.oldCheck == false) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                return new ResponseBodyLWC(
                  'Error',
                  500,
                  '消耗品' + ass.Prod.Name__c + '库存不足',
                  ''
                );
                                return new ResponseBodyLWC('Error', 500, '消耗品' + ass.Prod.Name__c + '库存不足', '');
              } else {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                return new ResponseBodyLWC(
@@ -2777,12 +2388,7 @@
            if (ass.orderdetails1.Shipment_Count__c > ass.Piecenumber) {
              if (ass.oldCheck == false) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                return new ResponseBodyLWC(
                  'Error',
                  500,
                  '消耗品' + ass.Prod.Name__c + '库存不足',
                  ''
                );
                                return new ResponseBodyLWC('Error', 500, '消耗品' + ass.Prod.Name__c + '库存不足', '');
              } else {
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                return new ResponseBodyLWC(
@@ -2796,10 +2402,7 @@
              }
            }
          }
          if (
            ass.orderdetails1.Shipment_Count__c == null ||
            ass.orderdetails1.Shipment_Count__c == 0
          ) {
                    if (ass.orderdetails1.Shipment_Count__c == null || ass.orderdetails1.Shipment_Count__c == 0) {
            // ass.orderdetails1.Shipment_Count__c.addError('请输入出货数量');
            // return null;
            return new ResponseBodyLWC('Error', 500, '请输入出货数量', '');
@@ -2811,6 +2414,7 @@
            InsAfterDel.Name = p.name + '-' + str;
            InsAfterDel.Shipment_Count__c = ass.orderdetails1.Shipment_Count__c;
            InsAfterDel.Consumable_order__c = ESetId;
                        System.debug('ass.Prod.id:' + ass.Prod.id);
            InsAfterDel.Consumable_Product__c = ass.Prod.id;
            InsAfterDel.Intra_Trade_List_RMB__c = ass.Prod.Intra_Trade_List_RMB__c;
            InsAfterDel.Delivery_List_RMB__c = ass.orderdetails1.Delivery_List_RMB__c;
@@ -2829,11 +2433,7 @@
      }
      update p;
      List<Consumable_orderdetails__c> qs = new List<Consumable_orderdetails__c>();
      qs = [
        SELECT Id
        FROM Consumable_orderdetails__c
        WHERE Consumable_order__c = :ESetId
      ];
            qs = [SELECT Id FROM Consumable_orderdetails__c WHERE Consumable_order__c = :ESetId];
      if (qs.size() > 0) {
        delete qs;
      }
@@ -2872,10 +2472,7 @@
  //打印PDF
  @AuraEnabled
  public static ResponseBodyLWC PraseToPDF(
    Consumable_order__c cocLwc,
    String ESetId
  ) {
    public static ResponseBodyLWC PraseToPDF(Consumable_order__c cocLwc, String ESetId) {
    System.debug('cocLwc = ' + cocLwc);
    System.debug('ESetId = ' + ESetId);
    coc = cocLwc;
@@ -2919,10 +2516,7 @@
  public static List<LookupSearchResult> search(String searchTerm) {
    System.debug('searchTerm = ' + searchTerm);
    String nameCondition = '';
    nameCondition +=
      '%' +
      String.escapeSingleQuotes(searchTerm.replaceAll('%', '\\%')) +
      '%';
        nameCondition += '%' + String.escapeSingleQuotes(searchTerm.replaceAll('%', '\\%')) + '%';
    List<Account> accs = new List<Account>();
    System.debug('nameCondition = ' + nameCondition);
    //查询条件修改
@@ -2978,6 +2572,7 @@
    //     ];
    // }
    Date today = Date.today();
    //Date today = Date.newInstance(2023, 3, 1);
    Integer thisMonth = today.month();
@@ -2996,11 +2591,7 @@
    System.debug('thisDatetime2 = ' + thisDatetime2);
    System.debug('nextDatetime = ' + nextDatetime);
    System.debug('UserInfo.getUserId() = ' + UserInfo.getUserId());
    User UserProTypecTemp = [
      SELECT UserPro_Type__c
      FROM User
      WHERE id = :UserInfo.getUserId()
    ];
        User UserProTypecTemp = [select UserPro_Type__c from User where id =: UserInfo.getUserId()];
    String sql = 'SELECT id, Parentid FROM Account WHERE Parent.Name LIKE :nameCondition ';
    if (thisMonth < 4) {
@@ -3025,14 +2616,7 @@
    }
    accs = [
      SELECT
        Id,
        Name,
        Department_Class__c,
        Department_Class__r.Name,
        Hospital__c,
        Hospital__r.Name,
        BillingCity
            SELECT Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name, BillingCity
      FROM Account
      WHERE
        (Id IN :pids
@@ -3073,18 +2657,8 @@
    List<LookupSearchResult> results = new List<LookupSearchResult>();
    String accountIcon = 'standard:account';
    for (Account account : accs) {
      String subtitle = account.BillingCity == null
        ? 'Account'
        : 'Account • ' + account.BillingCity;
      results.add(
        new LookupSearchResult(
          account.Id,
          'Account',
          accountIcon,
          account.Name,
          subtitle
        )
      );
            String subtitle = account.BillingCity == null ? 'Account' : 'Account • ' + account.BillingCity;
            results.add(new LookupSearchResult(account.Id, 'Account', accountIcon, account.Name, subtitle));
    }
    results.sort();
    System.debug('results = ' + results);
@@ -3093,11 +2667,7 @@
  //保存附件
  @AuraEnabled
  public static String saveFile(
    Id recordId,
    String fileName,
    String base64Data
  ) {
    public static String saveFile(Id recordId, String fileName, String base64Data) {
    base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
    ContentVersion cv = new ContentVersion();
    cv.Title = fileName;
@@ -3116,17 +2686,30 @@
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
    res.entity = data;
    List<ContentVersion> cvList = [
      SELECT
        id,
        Title,
        CreatedBy.Name,
        PathOnClient,
        CreatedDate,
        ContentDocumentId
        List<ContentVersion> cvList = new List<ContentVersion>();
        List<ContentDocumentLink> links = [SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :recordId];
        if (links != null && links.size() > 0) {
            List<String> documentIds = new List<String>();
            for (ContentDocumentLink link : links) {
                documentIds.add(link.ContentDocumentId);
            }
            List<ContentVersion> cvInfo = [
                SELECT Id, Title, OwnerId, Owner.Name, CreatedDate, ContentDocumentId
      FROM ContentVersion
      WHERE FirstPublishLocationId = :recordId
                WHERE ContentDocumentId IN :documentIds
    ];
            if (cvInfo.size() > 0) {
                for (Integer i = 0; i < cvInfo.size(); i++) {
                    cvList.add(cvInfo[i]);
                }
            }
        }
        // List<ContentVersion> cvList = [
        //     SELECT id, Title, CreatedBy.Name, PathOnClient, CreatedDate, ContentDocumentId
        //     FROM ContentVersion
        //     WHERE FirstPublishLocationId = :recordId
        // ];
    data.put('cvList', cvList);
    res.status = 'Success';
    res.code = 200;
@@ -3138,26 +2721,13 @@
  @AuraEnabled
  public static ResponseBodyLWC deleteAtt(String contentVersionId) {
    try {
      ContentVersion conVersion = [
        SELECT ContentDocumentId
        FROM ContentVersion
        WHERE Id = :contentVersionId
      ];
            ContentVersion conVersion = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionId];
      String contentDocumentId = conVersion.ContentDocumentId;
      ContentDocument conDocument = [
        SELECT Id
        FROM ContentDocument
        WHERE Id = :contentDocumentId
      ];
            ContentDocument conDocument =  [SELECT Id FROM ContentDocument where Id = :contentDocumentId];
      delete conDocument;
      return new ResponseBodyLWC('Success', 200, '', '');
    } catch (Exception e) {
      return new ResponseBodyLWC(
        'Error',
        500,
        e.getMessage() + e.getLineNumber(),
        ''
      );
            return new ResponseBodyLWC('Error',500, e.getMessage() + e.getLineNumber(), '');
    }
  }
@@ -3178,9 +2748,7 @@
      List<Account> accList = [
        SELECT Id
        FROM Account
        WHERE
          Name = :coc.Order_ForDealerText__c
          AND RecordType.DeveloperName = 'Agency'
                WHERE Name = :coc.Order_ForDealerText__c AND RecordType.DeveloperName = 'Agency'
      ];
      if (accList.size() < 1) {
        // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请输入二级经销商全称!'));
@@ -3197,14 +2765,7 @@
      if (ass.orderdetails1.Shipment_Count__c > ass.allnumber) {
        // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
        // return null;
        return new ResponseBodyLWC(
          'Error',
          500,
          '消耗品' +
            ass.orderdetails1.Consumable_Product__r.Name__c +
            '库存不足',
          ''
        );
                return new ResponseBodyLWC('Error', 500, '消耗品' + ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足', '');
      }
    }
    data.put('ESetid', ESetid);
@@ -3227,11 +2788,7 @@
    try {
      List<Consumable_order__c> qs = new List<Consumable_order__c>();
      List<Consumable_orderdetails__c> Dqs = new List<Consumable_orderdetails__c>();
      Dqs = [
        SELECT Id
        FROM Consumable_orderdetails__c
        WHERE Consumable_order__c = :ESetId
      ];
            Dqs = [SELECT Id FROM Consumable_orderdetails__c WHERE Consumable_order__c = :ESetId];
      qs = [SELECT Id FROM Consumable_order__c WHERE Id = :ESetId];
      if (Dqs.size() > 0 || qs.size() > 0) {
        delete Dqs;
@@ -3339,6 +2896,7 @@
    }
    //附件
        @TestVisible
    public ConsumableorderdetailsInfo(Attachment e) {
      concc = e;
      hospitalSpecialOffer = false;