buli
2023-07-14 744f42c5496e656a1f9927740a3b37c0b97a6cba
force-app/main/default/classes/LexConInvoiceViewController.cls
@@ -40,10 +40,7 @@
  public static List<Consumable_order__c> invoiceOrderSelectedList { get; set; }
  public static Map<String, Decimal> ordermx1defaultMap { get; set; }
  public static Map<String, Decimal> outorderMoneytMap { get; set; }
  public static Map<String, Consumable_Orderdetails__c> outordercountMap {
    get;
    set;
  }
    public static Map<String, Consumable_Orderdetails__c> outordercountMap { get; set; }
  public static List<String> outOrderStringList { get; set; }
  public static List<SelectOption> provinceOpts { get; set; }
  public static Map<String, String> provinceOptsMap { get; set; }
@@ -58,11 +55,7 @@
  }
  public static list<Dealer_elationship__c> Dealerelationship { get; set; }
  public static String[] orderby = new List<String>{
    'Outbound_Date__c',
    'Name',
    'ShipmentAccount__c'
  };
    public static String[] orderby = new List<String>{ 'Outbound_Date__c', 'Name', 'ShipmentAccount__c' };
  public static String sortKey { get; set; }
  public static String preSortKey { get; set; }
  public static Boolean sortOrderAsc { get; set; }
@@ -71,11 +64,7 @@
  //页面初始化
  @AuraEnabled
  public static ResponseBodyLWC init(
    String invoiceId,
    String statusEdit,
    String deliveryId
  ) {
    public static ResponseBodyLWC init(String invoiceId, String statusEdit, String deliveryId) {
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
    res.entity = data;
@@ -104,34 +93,16 @@
    statusEdit = statusEdit;
    deliveryId = deliveryId;
    if (
      invoiceId != null &&
      invoiceId != '' &&
      (statusEdit == '' ||
      statusEdit == null)
    ) {
        if (invoiceId != null && invoiceId != '' && (statusEdit == '' || statusEdit == null)) {
      editAble = false;
    } else if (
      (invoiceId == null || invoiceId == '') &&
      (statusEdit == '' ||
      statusEdit == null)
    ) {
        } else if ((invoiceId == null || invoiceId == '') && (statusEdit == '' || statusEdit == null)) {
      editAble = true;
    } else if (
      invoiceId != null &&
      invoiceId != '' &&
      statusEdit != '' &&
      statusEdit != null
    ) {
        } else if (invoiceId != null && invoiceId != '' && statusEdit != '' && statusEdit != null) {
      editAble = true;
    }
    userId = UserInfo.getUserId();
    List<user> Useracc = new List<user>();
    Useracc = [
      SELECT accountid, Work_Location__c, UserPro_Type__c
      FROM user
      WHERE id = :userId
    ];
        Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
    accountid = Useracc[0].accountid;
    userWorkLocation = Useracc[0].Work_Location__c;
    agencyProType = Useracc[0].UserPro_Type__c;
@@ -224,9 +195,7 @@
          ORDER BY Name
        ];
        for (Integer i = 0; i < invoiceOrderSelectedList.size(); i++) {
          invoiceOrderRecoeds.add(
            new InvoiceOrderInfo(invoiceOrderSelectedList[i])
          );
                    invoiceOrderRecoeds.add(new InvoiceOrderInfo(invoiceOrderSelectedList[i]));
        }
      }
    } else {
@@ -289,16 +258,12 @@
          Invoice_total_amount__c,
          Billed_Status__c
        FROM Consumable_order__c
        WHERE
          Id IN :outOrderStringList
          AND Order_Owner_WorkLocal__c = :userWorkLocation
                WHERE Id IN :outOrderStringList AND Order_Owner_WorkLocal__c = :userWorkLocation
        ORDER BY Name
      ];
      for (Integer i = 0; i < invoiceOrderSelectedList.size(); i++) {
        outorderMoneytMap.put(invoiceOrderSelectedList[i].id, 0);
        invoiceOrderRecoeds.add(
          new InvoiceOrderInfo(invoiceOrderSelectedList[i])
        );
                invoiceOrderRecoeds.add(new InvoiceOrderInfo(invoiceOrderSelectedList[i]));
      }
      if (String.isNotBlank(deliveryId)) {
        //发票关联出库单取得(出库单)
@@ -320,19 +285,13 @@
            Invoice_total_amount__c,
            Billed_Status__c
          FROM Consumable_order__c
          WHERE
            Id = :deliveryId
            AND Order_Owner_WorkLocal__c = :userWorkLocation
                    WHERE Id = :deliveryId AND Order_Owner_WorkLocal__c = :userWorkLocation
          ORDER BY Name
        ];
        for (Integer i = 0; i < invoiceOrderSelectedList.size(); i++) {
          if (!outorderMoneytMap.containsKey(invoiceOrderSelectedList[i].Id)) {
            invoiceOrderRecoeds.add(
              new InvoiceOrderInfo(invoiceOrderSelectedList[i])
            );
            invoiceOrderRecoedschange.add(
              new InvoiceOrderInfo(invoiceOrderSelectedList[i])
            );
                        invoiceOrderRecoeds.add(new InvoiceOrderInfo(invoiceOrderSelectedList[i]));
                        invoiceOrderRecoedschange.add(new InvoiceOrderInfo(invoiceOrderSelectedList[i]));
          }
        }
      }
@@ -362,17 +321,11 @@
      ];
      if (countDel.size() > 0) {
        for (Integer i = 0; i < countDel.size(); i++) {
          outordercountMap.put(
            countDel[i].Invoicedet1_OD_link__c + countDel[i].Asset_Model_No__c,
            countDel[i]
          );
          if (
            outorderMoneytMap.containsKey(countDel[i].Invoicedet1_OD_link__c)
          ) {
                    outordercountMap.put(countDel[i].Invoicedet1_OD_link__c + countDel[i].Asset_Model_No__c, countDel[i]);
                    if (outorderMoneytMap.containsKey(countDel[i].Invoicedet1_OD_link__c)) {
            outorderMoneytMap.put(
              countDel[i].Invoicedet1_OD_link__c,
              outorderMoneytMap.get(countDel[i].Invoicedet1_OD_link__c) +
              countDel[i].InvoicedProCost_RMB__c
                            outorderMoneytMap.get(countDel[i].Invoicedet1_OD_link__c) + countDel[i].InvoicedProCost_RMB__c
            );
          }
          invoiceOrderdetail1Recoeds.add(new InvoiceOrderInfo(countDel[i]));
@@ -391,45 +344,25 @@
      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('', '-无-'));
      provinceOptsMap.put('', '-无-');
      for (Integer i = 0; i < Dealerelationship.size(); i++) {
        if (Dealerelationship[i].Dealer_subordinate__r.Name == SecondDealer) {
          provinceOpts.add(
            new SelectOption(
              Dealerelationship[i].Dealer_subordinate__c,
              SecondDealer
            )
          );
          provinceOptsMap.put(
            Dealerelationship[i].Dealer_subordinate__c,
            SecondDealer
          );
                    provinceOpts.add(new SelectOption(Dealerelationship[i].Dealer_subordinate__c, SecondDealer));
                    provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, SecondDealer);
        }
      }
      for (Integer i = 0; i < Dealerelationship.size(); i++) {
        if (Dealerelationship[i].Dealer_subordinate__r.Name != 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);
        }
      }
    }
@@ -444,14 +377,8 @@
    System.debug('consumableaccessories = ' + consumableaccessories);
    if (consumableaccessories.size() > 0) {
      for (Integer i = 0; i < consumableaccessories.size(); i++) {
        consumableaccessoriesMap.put(
          consumableaccessories[i].Attachment_ID__c,
          consumableaccessories[i].Accessories_type__c
        );
        invorceOrderIdMap.put(
          consumableaccessories[i].Attachment_ID__c,
          consumableaccessories[i].Id
        );
                consumableaccessoriesMap.put(consumableaccessories[i].Attachment_ID__c, consumableaccessories[i].Accessories_type__c);
                invorceOrderIdMap.put(consumableaccessories[i].Attachment_ID__c, consumableaccessories[i].Id);
      }
    }
@@ -461,11 +388,7 @@
    //         attachmentRecoeds.add(new InvoiceOrderInfo(attachmentinfo[i]));
    //     }
    // }
    List<ContentDocumentLink> links = [
      SELECT Id, ContentDocumentId
      FROM ContentDocumentLink
      WHERE LinkedEntityId = :invoiceId
    ];
        List<ContentDocumentLink> links = [SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :invoiceId];
    if (links != null && links.size() > 0) {
      List<String> documentIds = new List<String>();
      for (ContentDocumentLink link : links) {
@@ -551,18 +474,12 @@
    SecondDealer = SecondDealerLwc;
    errorMsg = '';
    deliveryId = deliveryIdLwc;
    invoiceOrderRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(
      invoiceOrderRecoedsLwc,
      List<InvoiceOrderInfo>.class
    );
        invoiceOrderRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(invoiceOrderRecoedsLwc, List<InvoiceOrderInfo>.class);
    invoiceId = invoiceIdLwc;
    accountid = accountidLwc;
    agencyProType = agencyProTypeLwc;
    reopen = reopenLwc;
    invoiceOrderRecoedschange = (List<InvoiceOrderInfo>) JSON.deserialize(
      invoiceOrderRecoedschangeLwc,
      List<InvoiceOrderInfo>.class
    );
        invoiceOrderRecoedschange = (List<InvoiceOrderInfo>) JSON.deserialize(invoiceOrderRecoedschangeLwc, List<InvoiceOrderInfo>.class);
    List<String> chukudanID = new List<String>();
    if (coc.Name == '' || coc.Name == null) {
@@ -578,18 +495,9 @@
    if (String.isBlank(HospitalInfo) && String.isBlank(SecondDealer)) {
      // coc.addError('必须输入客户名或者二级经销商');
      // return null;
      return new ResponseBodyLWC(
        'Error',
        500,
        '必须输入客户名或者二级经销商',
        ''
      );
            return new ResponseBodyLWC('Error', 500, '必须输入客户名或者二级经销商', '');
    }
    if (
      HospitalInfo != null &&
      HospitalInfo != '' &&
      String.isNotEmpty(SecondDealer)
    ) {
        if (HospitalInfo != null && HospitalInfo != '' && String.isNotEmpty(SecondDealer)) {
      //coc.addError('请输入客户名、二级经销商只可输入一个');
      errorMsg += '请输入客户名、二级经销商只可输入一个';
    }
@@ -612,9 +520,7 @@
    } else if (String.isNotEmpty(SecondDealer)) {
      shipmentAccountString = SecondDealer;
    } else {
      shipmentAccountString = coc.Order_ForDealerText__c == null
        ? ''
        : coc.Order_ForDealerText__c;
            shipmentAccountString = coc.Order_ForDealerText__c == null ? '' : coc.Order_ForDealerText__c;
    }
    Integer x = 0;
@@ -637,14 +543,9 @@
              invoiceOrderAccountList.add(ass.esd.Name);
            }
          }
                    if (coc.Order_ForDealerText__c != null && (HospitalInfo == null || HospitalInfo == '')) {
          if (
            coc.Order_ForDealerText__c != null &&
            (HospitalInfo == null ||
            HospitalInfo == '')
          ) {
            if (
              (ass.esd.Order_ForDealerText__c != null ||
              ass.esd.Order_ForDealerText__c != '') &&
                            (ass.esd.Order_ForDealerText__c != null || ass.esd.Order_ForDealerText__c != '') &&
              ass.esd.ShipmentAccount__c != shipmentAccountString
            ) {
              invoiceOrderAccountList.add(ass.esd.Name);
@@ -653,36 +554,22 @@
        }
      } else {
        if (HospitalInfo != null && HospitalInfo != '') {
          System.debug(
            '++++++++++++' +
              ass.esd.Order_ForHospital__c +
              '   ' +
              shipmentAccountString
          );
                    System.debug('++++++++++++' + ass.esd.Order_ForHospital__c + '   ' + shipmentAccountString);
          if (ass.esd.Order_ForHospital__c != shipmentAccountString) {
            System.debug(
              'HospitalInfo != null ass.esd.Order_ForHospital__c != shipmentAccountString'
            );
                        System.debug('HospitalInfo != null ass.esd.Order_ForHospital__c != shipmentAccountString');
            invoiceOrderAccountList.add(ass.esd.Name);
          }
        }
        //if (String.isNotEmpty(SecondDealer)) {
        if (String.isNotEmpty(SecondDealer)) {
          if (ass.esd.Order_ForDealer__c != shipmentAccountString) {
            System.debug(
              'String.isNotEmpty(SecondDealer) ass.esd.Order_ForHospital__c != shipmentAccountString'
            );
                        System.debug('String.isNotEmpty(SecondDealer) ass.esd.Order_ForHospital__c != shipmentAccountString');
            invoiceOrderAccountList.add(ass.esd.Name);
          }
        }
                if (coc.Order_ForDealerText__c != null && (HospitalInfo == null || HospitalInfo == '')) {
        if (
          coc.Order_ForDealerText__c != null &&
          (HospitalInfo == null ||
          HospitalInfo == '')
        ) {
          if (
            (ass.esd.Order_ForDealerText__c != null ||
            ass.esd.Order_ForDealerText__c != '') &&
                        (ass.esd.Order_ForDealerText__c != null || ass.esd.Order_ForDealerText__c != '') &&
            ass.esd.ShipmentAccount__c != shipmentAccountString
          ) {
            System.debug(
@@ -695,16 +582,10 @@
    }
    // invoiceOrderAccountList.add('12345');
    if (invoiceOrderAccountList.size() > 0) {
      orderRemind =
        invoiceOrderAccountList + '出库单客户名与发票客户名不一致!';
            orderRemind = invoiceOrderAccountList + '出库单客户名与发票客户名不一致!';
      // coc.addError(invoiceOrderAccountList + '出库单客户名与发票客户名不一致!');
      // return null;
      return new ResponseBodyLWC(
        'Error',
        500,
        invoiceOrderAccountList + '出库单客户名与发票客户名不一致!',
        ''
      );
            return new ResponseBodyLWC('Error', 500, invoiceOrderAccountList + '出库单客户名与发票客户名不一致!', '');
    } else {
      orderRemind = '';
    }
@@ -712,12 +593,7 @@
      if (x < 1) {
        // coc.addError('请选择需要开发票的出库单!');
        // return null;
        return new ResponseBodyLWC(
          'Error',
          500,
          '请选择需要开发票的出库单!',
          ''
        );
                return new ResponseBodyLWC('Error', 500, '请选择需要开发票的出库单!', '');
      }
    }
    Consumable_order__c invoiceHead = new Consumable_order__c();
@@ -730,9 +606,7 @@
    try {
      if (String.isBlank(invoiceId)) {
        invoiceHead.Name = coc.Name;
        if (
          coc.Invoice_status__c == null || String.isBlank(coc.Invoice_status__c)
        )
                if (coc.Invoice_status__c == null || String.isBlank(coc.Invoice_status__c))
          coc.Invoice_status__c = '草案中';
        invoiceHead.Order_type__c = '发票';
        invoiceHead.Invoice_Date__c = coc.Invoice_Date__c;
@@ -819,9 +693,7 @@
            List<Consumable_order_LinkTable__c> existLinkinfo = [
              SELECT Id
              FROM Consumable_order_LinkTable__c
              WHERE
                Outboundorder_Code_link__c = :field
                AND Invoice_Code_link__c = :insertDetMap.get(field)
                            WHERE Outboundorder_Code_link__c = :field AND Invoice_Code_link__c = :insertDetMap.get(field)
            ];
            if (existLinkinfo.size() < 1) {
              Consumable_order_LinkTable__c invoiceLink = new Consumable_order_LinkTable__c();
@@ -833,11 +705,7 @@
          }
          upsert invoiceLinkList;
        }
      } else if (
        String.isNotBlank(reopen) &&
        reopen.equals('isreopen') &&
        String.isNotBlank(invoiceId)
      ) {
            } else if (String.isNotBlank(reopen) && reopen.equals('isreopen') && String.isNotBlank(invoiceId)) {
        System.debug('进入reopen');
        invoiceHead.Name = coc.Name;
        invoiceHead.Order_type__c = '发票';
@@ -902,10 +770,7 @@
        ];
        for (Consumable_Orderdetails__c cocTemp : tempCountList) {
          cocTemp.Consumable_order__c = invoiceHead.Id;
          tempCocMap.put(
            cocTemp.Invoicedet1_OD_link__c + cocTemp.Asset_Model_No__c,
            cocTemp
          );
                    tempCocMap.put(cocTemp.Invoicedet1_OD_link__c + cocTemp.Asset_Model_No__c, cocTemp);
        }
        System.debug('tempCountList = ' + tempCountList);
        update tempCountList;
@@ -930,25 +795,15 @@
          WHERE Consumable_order__c IN :updateChukudanId
        ];
        for (Consumable_Orderdetails__c corderc : updateFromList) {
          String tempStr =
            corderc.Consumable_order__c + corderc.Asset_Model_No__c;
                    String tempStr = corderc.Consumable_order__c + corderc.Asset_Model_No__c;
          if (tempCocMap.get(tempStr) != null) {
            //设置已发票金额 出库单的已发票金额 - 发票的发票金额
            corderc.InvoicedProCost_RMB__c =
              corderc.InvoicedProCost_RMB__c -
              tempCocMap.get(tempStr).InvoicedProduct_RMB__c;
                        corderc.InvoicedProCost_RMB__c = corderc.InvoicedProCost_RMB__c - tempCocMap.get(tempStr).InvoicedProduct_RMB__c;
            //设置已发票数量  出库单的已发票数量 - 发票的发票数量(盒)
            corderc.Invoiced_Procount__c =
              corderc.Invoiced_Procount__c -
              tempCocMap.get(tempStr).Invoiced_BoxCount__c;
                        corderc.Invoiced_Procount__c = corderc.Invoiced_Procount__c - tempCocMap.get(tempStr).Invoiced_BoxCount__c;
            //设置发票单价
            if (
              corderc.Box_Piece__c == '盒' &&
              corderc.Invoice_Unit__c == '个'
            ) {
              corderc.Invoice_Unitprice__c =
                corderc.Delivery_List_RMB__c /
                corderc.ProductPacking_list_manual__c;
                        if (corderc.Box_Piece__c == '盒' && corderc.Invoice_Unit__c == '个') {
                            corderc.Invoice_Unitprice__c = corderc.Delivery_List_RMB__c / corderc.ProductPacking_list_manual__c;
            } else {
              corderc.Invoice_Unitprice__c = corderc.Delivery_List_RMB__c;
            }
@@ -979,9 +834,7 @@
          List<Consumable_order_LinkTable__c> existLinkinfo = [
            SELECT Id, Invoice_Code_link__c, Outboundorder_Code_link__c
            FROM Consumable_order_LinkTable__c
            WHERE
              Outboundorder_Code_link__c IN :insertDetMap.keySet()
              AND Invoice_Code_link__c = :invoiceHead.Id
                        WHERE Outboundorder_Code_link__c IN :insertDetMap.keySet() AND Invoice_Code_link__c = :invoiceHead.Id
          ];
          //存在没有与发票建立关联关系的出库单
          List<String> templist2 = new List<String>();
@@ -1010,15 +863,10 @@
          List<Consumable_order_LinkTable__c> existLinkinfo = [
            SELECT Id, Outboundorder_Code_link__c, Invoice_Code_link__c
            FROM Consumable_order_LinkTable__c
            WHERE
              Outboundorder_Code_link__c IN :deleteDetMap.keySet()
              AND Invoice_Code_link__c = :invoiceHead.Id
                        WHERE Outboundorder_Code_link__c IN :deleteDetMap.keySet() AND Invoice_Code_link__c = :invoiceHead.Id
          ];
          for (Consumable_order_LinkTable__c colctemp : existLinkinfo) {
            if (
              deleteDetMap.get(colctemp.Outboundorder_Code_link__c) ==
              colctemp.Invoice_Code_link__c
            ) {
                        if (deleteDetMap.get(colctemp.Outboundorder_Code_link__c) == colctemp.Invoice_Code_link__c) {
              //存在与该发票关联的出库单
              invoiceLinkdetList.add(colctemp);
            }
@@ -1093,10 +941,7 @@
            WHERE Consumable_order__c = :deliveryId
          ];
          for (Consumable_Orderdetails__c changeOD : detaliFromList) {
            needchangeOrderProcountMap.put(
              changeOD.Asset_Model_No__c,
              changeOD.Shipment_Count__c
            );
                        needchangeOrderProcountMap.put(changeOD.Asset_Model_No__c, changeOD.Shipment_Count__c);
          }
          //发票返品信息
          List<Consumable_Orderdetails__c> returnCountList = [
@@ -1125,14 +970,10 @@
              if (returnProcountMap.containsKey(changeOD.Asset_Model_No__c)) {
                returnProcountMap.put(
                  changeOD.Asset_Model_No__c,
                  returnProcountMap.get(changeOD.Asset_Model_No__c) +
                  changeOD.RrturnPro_count__c
                                    returnProcountMap.get(changeOD.Asset_Model_No__c) + changeOD.RrturnPro_count__c
                );
              } else {
                returnProcountMap.put(
                  changeOD.Asset_Model_No__c,
                  changeOD.RrturnPro_count__c
                );
                                returnProcountMap.put(changeOD.Asset_Model_No__c, changeOD.RrturnPro_count__c);
              }
            }
          }
@@ -1166,10 +1007,7 @@
              AND Consumable_order__c != :deliveryId
          ];
          for (Consumable_Orderdetails__c changeOD : returnCount1List) {
            changeOrderProcountMap.put(
              changeOD.Asset_Model_No__c,
              changeOD.Shipment_Count__c
            );
                        changeOrderProcountMap.put(changeOD.Asset_Model_No__c, changeOD.Shipment_Count__c);
          }
          outOrderchange(insertDetMap);
        } else {
@@ -1190,9 +1028,7 @@
          } else {
            invoiceHead.Order_ForHospital__c = null;
          }
          invoiceHead.Order_ForDealer__c = SecondDealer == ''
            ? null
            : SecondDealer;
                    invoiceHead.Order_ForDealer__c = SecondDealer == '' ? null : SecondDealer;
          invoiceHead.Order_ForDealerText__c = coc.Order_ForDealerText__c;
          update invoiceHead;
          for (InvoiceOrderInfo ass : invoiceOrderRecoeds) {
@@ -1212,9 +1048,7 @@
            List<Consumable_order_LinkTable__c> existLinkinfo = [
              SELECT Id, Invoice_Code_link__c, Outboundorder_Code_link__c
              FROM Consumable_order_LinkTable__c
              WHERE
                Outboundorder_Code_link__c IN :insertDetMap.keySet()
                AND Invoice_Code_link__c = :invoiceHead.Id
                            WHERE Outboundorder_Code_link__c IN :insertDetMap.keySet() AND Invoice_Code_link__c = :invoiceHead.Id
            ];
            //存在没有与发票建立关联关系的出库单
            List<String> templist2 = new List<String>();
@@ -1241,15 +1075,10 @@
            List<Consumable_order_LinkTable__c> existLinkinfo = [
              SELECT Id, Outboundorder_Code_link__c, Invoice_Code_link__c
              FROM Consumable_order_LinkTable__c
              WHERE
                Outboundorder_Code_link__c IN :deleteDetMap.keySet()
                AND Invoice_Code_link__c = :invoiceHead.Id
                            WHERE Outboundorder_Code_link__c IN :deleteDetMap.keySet() AND Invoice_Code_link__c = :invoiceHead.Id
            ];
            for (Consumable_order_LinkTable__c colctemp : existLinkinfo) {
              if (
                deleteDetMap.get(colctemp.Outboundorder_Code_link__c) ==
                colctemp.Invoice_Code_link__c
              ) {
                            if (deleteDetMap.get(colctemp.Outboundorder_Code_link__c) == colctemp.Invoice_Code_link__c) {
                //存在与该发票关联的出库单
                invoiceLinkdetList.add(colctemp);
              }
@@ -1324,33 +1153,19 @@
      invoiceInsert1.Name =
        coc.Name +
        '-' +
        detaliFromList[i]
          .Name.substring(
            detaliFromList[i].Name.length() - 7,
            detaliFromList[i].Name.length()
          );
      invoiceInsert1.Shipment_Count__c = detaliFromList[i]
        .InvoiceProNot_count__c;
      invoiceInsert1.Consumable_Product__c = detaliFromList[i]
        .Consumable_Product__c;
      invoiceInsert1.Intra_Trade_List_RMB__c = detaliFromList[i]
        .Intra_Trade_List_RMB__c;
      invoiceInsert1.Delivery_List_RMB__c = detaliFromList[i]
        .Delivery_List_RMB__c;
      invoiceInsert1.Dealer_Custom_Price__c = detaliFromList[i]
        .Dealer_Custom_Price__c;
                detaliFromList[i].Name.substring(detaliFromList[i].Name.length() - 7, detaliFromList[i].Name.length());
            invoiceInsert1.Shipment_Count__c = detaliFromList[i].InvoiceProNot_count__c;
            invoiceInsert1.Consumable_Product__c = detaliFromList[i].Consumable_Product__c;
            invoiceInsert1.Intra_Trade_List_RMB__c = detaliFromList[i].Intra_Trade_List_RMB__c;
            invoiceInsert1.Delivery_List_RMB__c = detaliFromList[i].Delivery_List_RMB__c;
            invoiceInsert1.Dealer_Custom_Price__c = detaliFromList[i].Dealer_Custom_Price__c;
      invoiceInsert1.RecordTypeId = System.Label.RT_ConOrderDetail1_Invoice;
      if (
        detaliFromList[i].Box_Piece__c == '盒' &&
        detaliFromList[i].Invoice_Unit__c == '个'
      ) {
            if (detaliFromList[i].Box_Piece__c == '盒' && detaliFromList[i].Invoice_Unit__c == '个') {
        invoiceInsert1.Invoice_Unitprice__c =
          detaliFromList[i].Delivery_List_RMB__c /
          detaliFromList[i].ProductPacking_list_manual__c;
                    detaliFromList[i].Delivery_List_RMB__c / detaliFromList[i].ProductPacking_list_manual__c;
      } else {
        invoiceInsert1.Invoice_Unitprice__c = detaliFromList[i]
          .Delivery_List_RMB__c;
                invoiceInsert1.Invoice_Unitprice__c = detaliFromList[i].Delivery_List_RMB__c;
      }
      invoiceInsert1.Box_Piece__c = detaliFromList[i].Box_Piece__c;
      invoiceInsert1.Invoice_Unit__c = detaliFromList[i].Box_Piece__c;
@@ -1358,15 +1173,12 @@
        detaliFromList[i].Invoiced_Procount__c = 0;
      if (detaliFromList[i].RrturnPro_count__c == null)
        detaliFromList[i].RrturnPro_count__c = 0;
      invoiceInsert1.Invoiced_Count__c = detaliFromList[i]
        .InvoiceProNot_count__c;
            invoiceInsert1.Invoiced_Count__c = detaliFromList[i].InvoiceProNot_count__c;
      if (detaliFromList[i].InvoicedProCost_RMB__c == null)
        detaliFromList[i].InvoicedProCost_RMB__c = 0;
      invoiceInsert1.InvoicedProCost_RMB__c =
        invoiceInsert1.Invoiced_Count__c * invoiceInsert1.Delivery_List_RMB__c;
            invoiceInsert1.InvoicedProCost_RMB__c = invoiceInsert1.Invoiced_Count__c * invoiceInsert1.Delivery_List_RMB__c;
      invoiceInsert1.Consumable_order__c = invoiceId;
      invoiceInsert1.Invoicedet1_OD_link__c = detaliFromList[i]
        .Consumable_order__c;
            invoiceInsert1.Invoicedet1_OD_link__c = detaliFromList[i].Consumable_order__c;
      invoiceorderList1.add(invoiceInsert1);
    }
    System.debug('invoiceorderList1 +++++' + invoiceorderList1.size());
@@ -1396,22 +1208,12 @@
    // }
  }
  public static void deleteOutboundorder(
    Map<String, String> deleteMap,
    String value
  ) {
    public static void deleteOutboundorder(Map<String, String> deleteMap, String value) {
    //删除发票明细1
    List<Consumable_Orderdetails__c> detInvoicedet1List = [
      SELECT
        Id,
        Consumable_Shipment_order__c,
        Consumable_Sale_order__c,
        Consumable_product__c,
        Asset_Model_No__c
            SELECT Id, Consumable_Shipment_order__c, Consumable_Sale_order__c, Consumable_product__c, Asset_Model_No__c
      FROM Consumable_Orderdetails__c
      WHERE
        Consumable_order__c = :value
        AND Invoicedet1_OD_link__c = :deleteMap.keySet()
            WHERE Consumable_order__c = :value AND Invoicedet1_OD_link__c = :deleteMap.keySet()
    ];
    System.debug('detInvoicedet1List = ' + detInvoicedet1List);
    delete detInvoicedet1List;
@@ -1478,11 +1280,7 @@
  //上传ContentVersion附件
  @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;
@@ -1497,19 +1295,13 @@
  // 保存附件
  @AuraEnabled
  public static ResponseBodyLWC saveAttachment(
    String attachmentRecoedsLwc,
    String invoiceId
  ) {
    public static ResponseBodyLWC saveAttachment(String attachmentRecoedsLwc, String invoiceId) {
    System.debug('进入 saveAttachment');
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
    res.entity = data;
    invoiceId = invoiceId;
    attachmentRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(
      attachmentRecoedsLwc,
      List<InvoiceOrderInfo>.class
    );
        attachmentRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(attachmentRecoedsLwc, List<InvoiceOrderInfo>.class);
    System.debug('attachmentRecoeds = ' + attachmentRecoeds);
    try {
      Consumable_accessories_invoice__c attachmentdetails = new Consumable_accessories_invoice__c();
@@ -1525,12 +1317,7 @@
        }
      }
    } catch (Exception e) {
      return new ResponseBodyLWC(
        'Error',
        500,
        e.getMessage() + e.getLineNumber(),
        ''
      );
            return new ResponseBodyLWC('Error', 500, e.getMessage() + e.getLineNumber(), '');
    }
    res.status = 'Success';
    res.code = 200;
@@ -1559,10 +1346,7 @@
    HospitalInfo = HospitalInfoLwc;
    SecondDealer = SecondDealerLwc;
    errorMsg = '';
    invoiceOrderRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(
      invoiceOrderRecoedsLwc,
      List<InvoiceOrderInfo>.class
    );
        invoiceOrderRecoeds = (List<InvoiceOrderInfo>) JSON.deserialize(invoiceOrderRecoedsLwc, List<InvoiceOrderInfo>.class);
    invoiceId = invoiceIdLwc;
    accountid = accountidLwc;
    agencyProType = agencyProTypeLwc;
@@ -1617,10 +1401,7 @@
      soql += ' AND Order_ForDealer__c = \'' + SecondDealer + '\'';
    }
    if (coc.Order_ForDealerText__c != null) {
      soql +=
        ' AND ShipmentAccount__c = \'' +
        coc.Order_ForDealerText__c +
        '\'';
            soql += ' AND ShipmentAccount__c = \'' + coc.Order_ForDealerText__c + '\'';
    }
    soql += ' AND InvoiceNotPro_total_amount__c > 0';
    soql += ' AND Onchange_order__c = false limit 1000';
@@ -1643,10 +1424,7 @@
      soql += ' AND Order_ForDealer__c = \'' + SecondDealer + '\'';
    }
    if (coc.Order_ForDealerText__c != null) {
      soql +=
        ' AND ShipmentAccount__c = \'' +
        coc.Order_ForDealerText__c +
        '\'';
            soql += ' AND ShipmentAccount__c = \'' + coc.Order_ForDealerText__c + '\'';
    }
    soql += ' AND InvoiceNotPro_total_amount__c > 0';
    soql += ' AND Onchange_order__c = false limit 1000';
@@ -1655,10 +1433,7 @@
  // 删除按钮
  @AuraEnabled
  public static ResponseBodyLWC deleteButton(
    String invoiceIdLwc,
    Consumable_order__c cocLwc
  ) {
    public static ResponseBodyLWC deleteButton(String invoiceIdLwc, Consumable_order__c cocLwc) {
    System.debug('进入 deleteButton');
    ResponseBodyLWC res = new ResponseBodyLWC();
    Map<String, object> data = new Map<String, object>();
@@ -1685,12 +1460,7 @@
    } catch (Exception e) {
      // ApexPages.addMessages(e);
      // return null;
      return new ResponseBodyLWC(
        'Error',
        500,
        e.getMessage() + ' ' + e.getLineNumber(),
        ''
      );
            return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
    }
  }
@@ -1740,99 +1510,61 @@
      WHERE Consumable_order__c IN :outOrderStringList
    ];
    for (Integer i = 0; i < outOrderdet1List.size(); i++) {
      if (
        outordercountMap.containsKey(
          outOrderdet1List[i].Consumable_order__c +
          outOrderdet1List[i].Asset_Model_No__c
        )
      ) {
            if (outordercountMap.containsKey(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c)) {
        Consumable_Orderdetails__c invoiceUpdte1 = new Consumable_Orderdetails__c();
        invoiceUpdte1.Id = outOrderdet1List[i].Id;
        invoiceUpdte1.Invoice_Unit__c = outordercountMap.get(
            outOrderdet1List[i].Consumable_order__c +
            outOrderdet1List[i].Asset_Model_No__c
                        outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c
          )
          .Invoice_Unit__c;
        if (
          outordercountMap.get(
              outOrderdet1List[i].Consumable_order__c +
              outOrderdet1List[i].Asset_Model_No__c
            )
            .Box_Piece__c == '盒' &&
          outordercountMap.get(
              outOrderdet1List[i].Consumable_order__c +
              outOrderdet1List[i].Asset_Model_No__c
            )
            .Invoice_Unit__c == '个'
                    outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c).Box_Piece__c ==
                    '盒' &&
                    outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c).Invoice_Unit__c ==
                    '个'
        ) {
          Decimal OldinvoicedProcount = 0;
          OldinvoicedProcount = (outordercountMap.get(
                outOrderdet1List[i].Consumable_order__c +
                outOrderdet1List[i].Asset_Model_No__c
                                outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c
              )
              .Invoiced_Count__c /
            outordercountMap.get(
                outOrderdet1List[i].Consumable_order__c +
                outOrderdet1List[i].Asset_Model_No__c
              )
                        outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c)
              .ProductPacking_list_manual__c)
            .setScale(2);
          invoiceUpdte1.Invoiced_Procount__c =
            outOrderdet1List[i].Invoiced_Procount__c + OldinvoicedProcount;
                    invoiceUpdte1.Invoiced_Procount__c = outOrderdet1List[i].Invoiced_Procount__c + OldinvoicedProcount;
        } else {
          invoiceUpdte1.Invoiced_Procount__c =
            outOrderdet1List[i].Invoiced_Procount__c +
            outordercountMap.get(
                outOrderdet1List[i].Consumable_order__c +
                outOrderdet1List[i].Asset_Model_No__c
              )
                        outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c)
              .Invoiced_Count__c;
        }
        invoiceUpdte1.Invoice_Unitprice__c = outordercountMap.get(
            outOrderdet1List[i].Consumable_order__c +
            outOrderdet1List[i].Asset_Model_No__c
                        outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c
          )
          .Invoice_Unitprice__c;
        System.debug('====>procount' + invoiceUpdte1.Invoiced_Procount__c);
        System.debug('===>RMB' + outOrderdet1List[i].Delivery_List_RMB__c);
        invoiceUpdte1.InvoicedProCost_RMB__c =
          invoiceUpdte1.Invoiced_Procount__c *
          outOrderdet1List[i].Delivery_List_RMB__c;
                invoiceUpdte1.InvoicedProCost_RMB__c = invoiceUpdte1.Invoiced_Procount__c * outOrderdet1List[i].Delivery_List_RMB__c;
        Decimal invoicedProcount = 0;
        if (
          outordercountMap.get(
              outOrderdet1List[i].Consumable_order__c +
              outOrderdet1List[i].Asset_Model_No__c
            )
            .Box_Piece__c == '盒' &&
          outordercountMap.get(
              outOrderdet1List[i].Consumable_order__c +
              outOrderdet1List[i].Asset_Model_No__c
            )
            .Invoice_Unit__c == '个'
                    outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c).Box_Piece__c ==
                    '盒' &&
                    outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c).Invoice_Unit__c ==
                    '个'
        ) {
          invoicedProcount = (outordercountMap.get(
                outOrderdet1List[i].Consumable_order__c +
                outOrderdet1List[i].Asset_Model_No__c
                                outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c
              )
              .Invoiced_Count__c /
            outordercountMap.get(
                outOrderdet1List[i].Consumable_order__c +
                outOrderdet1List[i].Asset_Model_No__c
              )
                        outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c)
              .ProductPacking_list_manual__c)
            .setScale(2);
        } else {
          invoicedProcount = outordercountMap.get(
              outOrderdet1List[i].Consumable_order__c +
              outOrderdet1List[i].Asset_Model_No__c
            )
                    invoicedProcount = outordercountMap.get(outOrderdet1List[i].Consumable_order__c + outOrderdet1List[i].Asset_Model_No__c)
            .Invoiced_Count__c;
        }
        System.debug(
          '发票数量===>' + outOrderdet1List[i].InvoiceProNot_count__c
        );
                System.debug('发票数量===>' + outOrderdet1List[i].InvoiceProNot_count__c);
        System.debug('还没发票数量===>' + invoicedProcount);
        if (outOrderdet1List[i].InvoiceProNot_count__c < invoicedProcount) {
@@ -1870,13 +1602,7 @@
      }
      //发票状态更新
      cocinfo = [
        SELECT
          Id,
          Name,
          Invoice_status__c,
          Dealer_Info__c,
          Order_ForHospital__c,
          SummonsForDirction__c
                SELECT Id, Name, Invoice_status__c, Dealer_Info__c, Order_ForHospital__c, SummonsForDirction__c
        FROM Consumable_order__c
        WHERE Id = :invoiceId
      ];
@@ -1891,12 +1617,7 @@
      Database.rollback(sp);
      // ApexPages.addMessages(ex);
      // return null;
      return new ResponseBodyLWC(
        'Error',
        500,
        ex.getMessage() + ' ' + ex.getLineNumber(),
        ''
      );
            return new ResponseBodyLWC('Error', 500, ex.getMessage() + ' ' + ex.getLineNumber(), '');
    }
    res.status = 'Success';
    res.code = 200;