public without sharing class PrintConsumblePDFController { /*****************検索用******************/ public Consumable_order__c coc { get; set; } public String gestName{get;set;} //供货商名称 public String addressName {get;set;} /** 1ページに表示する明細の数です。 */ private Integer rowSize = 32; /** 最終ページに表示する明細の数です。 */ private Integer lastRowSize = 24; /** 製品名を開業する文字数です。 */ private Integer nameMax = 23; /** 印刷するページ数です。 */ public Integer maxPageNumber { get; set; } /** 印刷対象の見積の配下にある見積品目データです。 */ public List printRecords {get; private set;} public String baseUrl {get;private set;} // 产品 ID private String ESetId = ''; private String userName = ''; //经销商管理编码 -- 电子签收ID号 public String idName{get;set;} public PrintConsumblePDFController(){ //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8'); baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); ESetId = ApexPages.currentPage().getParameters().get('esetId'); } public void init(){ userName = UserInfo.getUserId(); List Useracc = New List(); Useracc = [select name,accountid from user where id =:userName]; String accountid = Useracc[0].accountid; //update by rentx 2020-11-11 start CHAN-BV2677 // List accountInfo = [SELECT name FROM account WHERE id =:accountid]; List accountInfo = [SELECT name,Management_FormulaCode__c FROM account WHERE id =:accountid]; gestName = accountInfo[0].name; idName = accountInfo[0].Management_FormulaCode__c; //update by rentx 2020-11-11 end CHAN-BV2677 coc = new Consumable_order__c(); List ConsumableorderdetailsRecords = new List(); List CountSet = new List(); if(ESetId== NULL || ESetId==''){ }else{ List qs = New List(); qs = [select Id,Name,Order_status__c,Dealer_Info__c, Order_ForHospital__c,Deliver_date__c,Order_Reason__c, Order_date__c,Total_amount__c,Order_ProType__c, Offers_Price__c,Order_effective_contact__r.Business_Assistant__r.Province_Text__c ,Order_effective_contact__r.OSH_Dealer__c //20230323 lt DB202303088261 两票制 add From Consumable_order__c Where Id =:ESetId]; if (qs.size()>0){ coc = qs[0]; } this.rowSize = 42; this.lastRowSize = 42; this.nameMax = 18; // 選択済みの明细を取得 bindQuoteLineData(); this.getShipmentaddress(); } } /** * 見積品目データを取得して、インスタンス変数にセットします。 */ private void bindQuoteLineData(){ System.debug('ESetId +++++' + ESetId); this.maxPageNumber = 0; String nowId = coc.Id; Integer repeatCount = null; String nowName = null, nowRightAsstModelNo = null; //String nowCompany = null; boolean hasEnglish = false; Consumable_Orderdetails__c work = null; List nameStringArray = null; Consumable_Orderdetails__c[] itemsOrg = [select Id, Name, Consumable_order__c, Consumable_Product__c, Consumable_Product__r.Name, Consumable_Product__r.Name__c, CFDA_Status__c, Consumable_Count__c, Consumable_Product__r.Intra_Trade_List_RMB__c, Consumable_Product__r.Asset_Model_No__c, Consumable_Product__r.Product2__r.SalesPackagingUnit_Chinese__c, Consumable_Product__r.Product2__r.ProduceCompany_F__c, Consumable_Product__r.Product2__r.ProduceCompany__c, Sum_of_money__c, Dealer_Custom_Price__c, Lose_reason__c, ProduceCompany__c, ProductPacking_list_manual__c, CFDA_No__c, Intra_Trade_List_RMB__c, Qty_Unit__c, Asset_Model_No__c from Consumable_Orderdetails__c where Consumable_order__c = :ESetId order by Name]; System.debug('itemsOrg+++++' + itemsOrg.size()); Consumable_Orderdetails__c[] items = new List(); for (Integer i = 0; i < itemsOrg.size(); i++) { nowName = itemsOrg[i].Consumable_Product__r.Name__c == null ? '' : itemsOrg[i].Consumable_Product__r.Name__c; //CHAN-B368WS 当产品编号为:N/A时,打印报价单/合同配置单/系统合同配置单时,打印的产品型号处空白(现在显示产品CODE) if(itemsOrg[i].Asset_Model_No__c == '' || itemsOrg[i].Asset_Model_No__c == 'N/A'){ nowRightAsstModelNo = ''; }else if( nowName.indexOf( ':') >= 0) { nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( ':')); nowName = nowName.subString( nowName.indexOf( ':')+1); } else if( nowName.indexOf( ':') >= 0) { nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( ':')); nowName = nowName.subString( nowName.indexOf( ':')+1); } else { nowRightAsstModelNo = ''; } nameStringArray = new List(); // 20220824 ljh SWAG-CHKAMM update start // repeatCount = (nowName.length() / nameMax) + ( Math.mod( nowName.length(), nameMax) > 0 ? 1 : 0); if(String.isBlank(nowName)){ repeatCount = 1; }else{ repeatCount = (nowName.length() / nameMax) + ( Math.mod( nowName.length(), nameMax) > 0 ? 1 : 0); } // 20220824 ljh SWAG-CHKAMM update end //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, 'repeatCount!' + repeatCount)); // 生产企业 注释原代码 // nowCompany = itemsOrg[i].Consumable_Product__r.Product2__r.ProduceCompany_F__c; String nowCompany = null; if(itemsOrg[i].Consumable_Product__r.Product2__r.ProduceCompany__c !=null){ nowCompany = getProduceCompanyName(itemsOrg[i].Consumable_Product__r.Product2__r.ProduceCompany__c); } if (nowCompany == null) nowCompany = ''; //hasEnglish = Pattern.matches('.*[a-zA-Z]+.*', nowCompany); //Integer companyMax = hasEnglish ? 16 : 12; //Integer repeatCount2 = (nowCompany.length() / companyMax) + ( Math.mod( nowCompany.length(), companyMax) > 0 ? 1 : 0); //String descri = itemsOrg[i].Description == null ? '' : itemsOrg[i].Description; //Integer repeetCount3 = (descri.length() / 12) + (Math.mod(descri.length(), 12) > 0 ? 1 : 0); for ( Integer j = 0; j < repeatCount; j++) { if (( j + 1) == repeatCount) { nameStringArray.add( nowName.substring( j * nameMax)); } else { nameStringArray.add( nowName.substring( j * nameMax, (j+1) * nameMax)); } } //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, 'nameStringArray!' + nameStringArray)); for ( Integer k = 0; k < repeatCount; k++) { if ( k == 0) { work = itemsOrg[i]; work.Remarks__c = ':'; work.Product_code__c = nowRightAsstModelNo; work.AgencyName_text1__c = nowCompany.trim(); work.Shipment_Count__c = i + 1; } else { work = new Consumable_Orderdetails__c(); work.Remarks__c = ''; work.Product_code__c = ''; } work.Lose_reason__c = nameStringArray[k]; items.add(work); } } printRecords = new List(); ConsumableorderdetailsInfo[] pageItems = new ConsumableorderdetailsInfo[]{}; Integer counter = 0; for (Integer i = 0; i < items.size(); i++) { if ( counter <= rowSize) { pageItems.add(new ConsumableorderdetailsInfo(items[i])); counter++; } if ( counter == rowSize) { counter = 0; printRecords.add( pageItems); pageItems = new ConsumableorderdetailsInfo[]{}; this.maxPageNumber += 1; } } if ( !pageItems.isEmpty()) { printRecords.add( pageItems); this.maxPageNumber += 1; } if ( printRecords.size() > 0) { List lastList = printRecords[printRecords.size()-1]; if ( lastList.size() > lastRowSize) { printRecords.add( new List()); this.maxPageNumber += 1; } } System.debug('printRecords +++++' + printRecords); } public class ConsumableorderdetailsInfo { public Consumable_Orderdetails__c esd { get; set; } public Product2__c Prod { get; set; } public Integer lineNo { get; set; } public String unit { get; set; } // 订单明细用 public ConsumableorderdetailsInfo(Consumable_Orderdetails__c e) { esd = e; Prod = e.Consumable_Product__r; lineNo = Integer.valueOf(e.Shipment_Count__c); if(Prod != null){ unit = Prod.Product2__r.SalesPackagingUnit_Chinese__c; if(String.isBlank(unit)){ unit = '件'; } } //unit = Prod.Product2__r.SalesPackagingUnit_Chinese__c; //if(String.isBlank(unit)){ // unit = '件'; //} } } private static Map addressNameApiMap = new Map { '湖南省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '四川省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '广东省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '贵州省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '云南省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '广西自治区' => '奥林巴斯(北京)销售服务有限公司广州分公司', '深圳市' => '奥林巴斯(北京)销售服务有限公司广州分公司', '湖北省' => '奥林巴斯(北京)销售服务有限公司广州分公司', '重庆市' => '奥林巴斯(北京)销售服务有限公司广州分公司', '北京市' => '奥林巴斯(北京)销售服务有限公司', '吉林省' => '奥林巴斯(北京)销售服务有限公司', '大连市' => '奥林巴斯(北京)销售服务有限公司', '黑龙江省' => '奥林巴斯(北京)销售服务有限公司', '内蒙古' => '奥林巴斯(北京)销售服务有限公司', '山东省' => '奥林巴斯(北京)销售服务有限公司', '甘肃省' => '奥林巴斯(北京)销售服务有限公司', '青岛市' => '奥林巴斯(北京)销售服务有限公司', '辽宁省' => '奥林巴斯(北京)销售服务有限公司', '河北省' => '奥林巴斯(北京)销售服务有限公司', '山西省' => '奥林巴斯(北京)销售服务有限公司', '天津市' => '奥林巴斯(北京)销售服务有限公司', '新疆自治区' => '奥林巴斯(北京)销售服务有限公司', '陕西省' => '奥林巴斯(北京)销售服务有限公司', '青海省' => '奥林巴斯(北京)销售服务有限公司', '宁夏自治区' => '奥林巴斯(北京)销售服务有限公司', '河南省' => '奥林巴斯(北京)销售服务有限公司', '浙江省' => '奥林巴斯(北京)销售服务有限公司上海分公司', '安徽省' => '奥林巴斯(北京)销售服务有限公司上海分公司', 'OSH-安徽省' => '奥林巴斯贸易(上海)有限公司', //20230323 lt DB202303088261 两票制 add '江西省' => '奥林巴斯(北京)销售服务有限公司上海分公司', '福建省' => '奥林巴斯(北京)销售服务有限公司上海分公司', '江苏省' => '奥林巴斯(北京)销售服务有限公司上海分公司', '上海市' => '奥林巴斯(北京)销售服务有限公司上海分公司' }; //获取办事处地址 private void getShipmentaddress(){ //CHAN-B42D6F 安徽ET特约经销商来的询价 SAP上传省 紧急对应为北京 以后会修改 TODO //CHAN-BTF64C 安徽ENG经销商的询价默认SAP上传省修改 update by rentongxiao 2020-09-14 start // String province = coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c == '安徽省' ? '北京市' : coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c; //20230323 lt DB202303088261 两票制 start String province = ''; if(coc.Order_effective_contact__r.OSH_Dealer__c == TRUE){ province = 'OSH-安徽省'; }else if(coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c == '安徽省' && coc.Order_ProType__c == 'ET'){ province = '北京市'; }else{ province = coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c; } // String province = coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c == '安徽省' && coc.Order_ProType__c == 'ET' ? '北京市' : coc.Order_effective_contact__r.Business_Assistant__r.Province_Text__c; //20230323 lt DB202303088261 两票制 end //CHAN-BTF64C 安徽ENG经销商的询价默认SAP上传省修改 update by rentongxiao 2020-09-14 end if(addressNameApiMap.get(province) != null){ this.addressName = addressNameApiMap.get(province); }else{ this.addressName = ' '; } } //产品主数据生产企业 获取企业名称 private String getProduceCompanyName(String produceCompany){ //获取企业名称 (生产企业,注册证状态) //getProduceCompanyName(String produceCompany,String sfdaApprobatedStatus) //取前一部分 eg: 生产企业名称 : //String firstHalf = ''; //①统一中英文符号 找不到就返回原数据 String tempProduceCompany = produceCompany.replace(';', ';'); tempProduceCompany = tempProduceCompany.replace(':', ':'); //②先截取第一个分号前的数据 if(tempProduceCompany.indexOf(';')>0){ tempProduceCompany = tempProduceCompany.substring(0, tempProduceCompany.indexOf(';')); } //③截取第一个分号前 冒号后 分号前的数据 if(tempProduceCompany.indexOf(':') > 0){ //如果需要传入注册证状态的话 再拼接前一部分 //firstHalf = tempProduceCompany.substring(0, tempProduceCompany.indexOf(':')+1); tempProduceCompany = tempProduceCompany.substring(tempProduceCompany.indexOf(':')+1, tempProduceCompany.length()); } //④正则 只取出中文 不包括 全角符号 # % 不包括英文名 //[\u4E00-\u9FA5\\s]+ 多个汉字,包括空格 //[\u4E00-\u9FA5]+ 多个汉字,不包括空格 //[\u4E00-\u9FA5] 一个汉字 ///u0800-/u4e00 日文 //输出中日文 Pattern p = Pattern.compile('([\u0800-\u9fa5()()]+)'); Matcher pm = p.matcher(tempProduceCompany); if( pm.find() ){ system.debug('123'); tempProduceCompany = pm.group(0); } //如果注册证等于不要 拼接前一部分 // if(sfdaApprobatedStatus == '不要'){ // //如果前半部分不为空 则拼接上前半部分 // if(firstHalf!= ''){ // tempProduceCompany = firstHalf +tempProduceCompany; // } // } return tempProduceCompany; } }