//设置列的标题
Label labelColumn0 = new Label(0, 2, "客户", formatColumnHeader);
Label labelColumn1 = new Label(1, 2, "开单日期", formatColumnHeader);
Label labelColumn2 = new Label(2, 2, "送货地址", formatColumnHeader);
Label labelColumn3 = new Label(3, 2, "订单编号", formatColumnHeader);
Label labelColumn4 = new Label(4, 2, "存货名称", formatColumnHeader);
Label labelColumn5 = new Label(5, 2, "主要单位", formatColumnHeader);
Label labelColumn6 = new Label(6, 2, "订货数量", formatColumnHeader);
Label labelColumn7 = new Label(7, 2, "审核数量", formatColumnHeader);
Label labelColumn8 = new Label(8, 2, "欠货数量", formatColumnHeader);
Label labelColumn9 = new Label(9, 2, "单价", formatColumnHeader);
Label labelColumn10 = new Label(10, 2, "金额", formatColumnHeader);
Label labelColumn11 = new Label(11, 2, "本次出货量", formatColumnHeader);
Label labelColumn12 = new Label(12, 2, "累计出货量", formatColumnHeader);
sheet.addCell(labelColumn0);
sheet.addCell(labelColumn1);
sheet.addCell(labelColumn2);
sheet.addCell(labelColumn3);
sheet.addCell(labelColumn4);
sheet.addCell(labelColumn5);
sheet.addCell(labelColumn6);
sheet.addCell(labelColumn7);
sheet.addCell(labelColumn8);
sheet.addCell(labelColumn9);
sheet.addCell(labelColumn10);
sheet.addCell(labelColumn11);
sheet.addCell(labelColumn12);
// 内容格式设置
WritableFont fontContentHeader = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD);
WritableCellFormat formatContentHeader = new WritableCellFormat();
formatContentHeader.setFont(fontContentHeader);
formatContentHeader.setAlignment(jxl.format.Alignment.CENTRE);
formatContentHeader.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 遍历输出list
int totalAboveRow = 3;// 上部高度
float totalsum = 0;
List<Object[]> list = (List<Object[]>) this.findAllRBpdf(obj);
Label itemName = new Label(0, totalAboveRow, obj.getRequestBranchName(), formatContentHeader);//客户信息
sheet.addCell(itemName);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Label date = new Label(1, totalAboveRow, sdf.format(obj.getSalesDate()), formatContentHeader);//开单时间
sheet.addCell(date);
Label address = new Label(2, totalAboveRow, "", formatContentHeader);// 送货地址
sheet.addCell(address);
Label bomLable9 = null;
Label bomLable11 = null;
BdSecondaryUnit secoUnit =null;
for (int i = 0; i < list.size(); i++) {
Double price =0.0;
String priceStr ="";
String orderNumber ="";
String auditNumber ="";
String oweNumber ="";
String saleNumber ="";
//累计出货
String totalGoOutStr ="";
if(list.get(i)[9]!=null){
secoUnit = (BdSecondaryUnit) this.getQcyOweOrderDAO().getObject("from BdSecondaryUnit where product.id=" +list.get(i)[9]);
}
if (null != list.get(i)[4] && null != list.get(i)[10]&& null != list.get(i)[6]) {
price = Double.parseDouble(list.get(i)[4].toString())/Double.parseDouble(list.get(i)[10].toString())*Double.parseDouble( list.get(i)[6].toString()) ;
priceStr = Tool.keep4DecimalRounding1ToString(price);
}
totalsum += price;
//订货量
if (null != list.get(i)[3]&&null != list.get(i)[10]&& Double.parseDouble(list.get(i)[3].toString())>=Double.parseDouble(list.get(i)[10].toString())) {
orderNumber= (int) (Double.parseDouble(list.get(i)[3].toString())/Double.parseDouble( list.get(i)[10].toString()))+ list.get(i)[2].toString();
}
if (null != list.get(i)[3]&&null != list.get(i)[10]&& null != secoUnit&&secoUnit.getSecondary2Basic()!=null &&
Double.parseDouble(list.get(i)[3].toString()) % Double.parseDouble(list.get(i)[10].toString()) != 0) {
orderNumber=(orderNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[3].toString()) - (int) (Double.parseDouble(list.get(i)[3].toString())/ Double.parseDouble(list.get(i)[10].toString()))
* Double.parseDouble(list.get(i)[10].toString()))
/ secoUnit.getSecondary2Basic()) + secoUnit.getUnit().getName());
}else {
if (null != list.get(i)[3]&& null != list.get(i)[10]&& Double.parseDouble(list.get(i)[3].toString()) %Double.parseDouble(list.get(i)[10].toString())> 0&&null!= list.get(i)[11])
orderNumber=(orderNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[3].toString()) - (int) (Double.parseDouble(list.get(i)[3].toString()) / Double.parseDouble(list.get(i)[10].toString())) * Double.parseDouble(list.get(i)[10].toString())))
+ list.get(i)[11].toString());
}
//本次出货量
if (null != list.get(i)[4]&&null != list.get(i)[10]&& Double.parseDouble(list.get(i)[4].toString())>=Double.parseDouble(list.get(i)[10].toString())) {
saleNumber= (int) (Double.parseDouble(list.get(i)[4].toString())/Double.parseDouble( list.get(i)[10].toString()))+ list.get(i)[2].toString();
}
if (null != list.get(i)[4]&&null != list.get(i)[10]&& null != secoUnit&&secoUnit.getSecondary2Basic()!=null &&
Double.parseDouble(list.get(i)[4].toString()) % Double.parseDouble(list.get(i)[10].toString()) != 0) {
saleNumber=(saleNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[4].toString()) - (int) (Double.parseDouble(list.get(i)[4].toString())/ Double.parseDouble(list.get(i)[10].toString()))
* Double.parseDouble(list.get(i)[10].toString()))
/ secoUnit.getSecondary2Basic()) + secoUnit.getUnit().getName());
}else {
if (null != list.get(i)[4]&& null != list.get(i)[10]&& Double.parseDouble(list.get(i)[4].toString()) %Double.parseDouble(list.get(i)[10].toString())> 0&&null!= list.get(i)[11])
saleNumber=(saleNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[4].toString()) - (int) (Double.parseDouble(list.get(i)[4].toString()) / Double.parseDouble(list.get(i)[10].toString())) * Double.parseDouble(list.get(i)[10].toString())))
+ list.get(i)[11].toString());
}
//审核量
if (null != list.get(i)[8]&&null != list.get(i)[10]&& Double.parseDouble(list.get(i)[8].toString())>=Double.parseDouble(list.get(i)[10].toString())) {
auditNumber= (int) (Double.parseDouble(list.get(i)[8].toString())/Double.parseDouble( list.get(i)[10].toString()))+ list.get(i)[2].toString();
}
if (null != list.get(i)[8]&&null != list.get(i)[10]&& null != secoUnit&&secoUnit.getSecondary2Basic()!=null &&
Double.parseDouble(list.get(i)[8].toString()) % Double.parseDouble(list.get(i)[10].toString()) != 0) {
auditNumber=(auditNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[8].toString()) - (int) (Double.parseDouble(list.get(i)[8].toString())/ Double.parseDouble(list.get(i)[10].toString()))
* Double.parseDouble(list.get(i)[10].toString()))
/ secoUnit.getSecondary2Basic()) + secoUnit.getUnit().getName());
}else {
if (null != list.get(i)[8]&& null != list.get(i)[10]&& Double.parseDouble(list.get(i)[8].toString()) %Double.parseDouble(list.get(i)[10].toString())> 0&&null!= list.get(i)[11])
auditNumber=(auditNumber +Tool.keep2DecimalRounding( (Double.parseDouble(list.get(i)[8].toString()) - (int) (Double.parseDouble(list.get(i)[8].toString()) / Double.parseDouble(list.get(i)[10].toString())) * Double.parseDouble(list.get(i)[10].toString())))
+ list.get(i)[11].toString());
}
//欠货量
if (null != list.get(i)[5]&&null != list.get(i)[10]&& Double.parseDouble(list.get(i)[5].toString())>=Double.parseDouble(list.get(i)[10].toString())) {
oweNumber= (int) (Double.parseDouble(list.get(i)[5].toString())/Double.parseDouble( list.get(i)[10].toString()))+ list.get(i)[2].toString();
}
if (null != list.get(i)[5]&&null != list.get(i)[10]&& null != secoUnit&&secoUnit.getSecondary2Basic()!=null &&
Double.parseDouble(list.get(i)[5].toString()) % Double.parseDouble(list.get(i)[10].toString()) != 0) {
oweNumber=(oweNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[5].toString()) - (int) (Double.parseDouble(list.get(i)[5].toString())/ Double.parseDouble(list.get(i)[10].toString()))
* Double.parseDouble(list.get(i)[10].toString()))
/ secoUnit.getSecondary2Basic()) + secoUnit.getUnit().getName());
}else {
if (null != list.get(i)[5]&& null != list.get(i)[10]&& Double.parseDouble(list.get(i)[5].toString()) %Double.parseDouble(list.get(i)[10].toString())> 0&&null!= list.get(i)[11])
oweNumber=(oweNumber + Tool.keep2DecimalRounding((Double.parseDouble(list.get(i)[5].toString()) - (int) (Double.parseDouble(list.get(i)[5].toString()) / Double.parseDouble(list.get(i)[10].toString())) * Double.parseDouble(list.get(i)[10].toString())))
+ list.get(i)[11].toString());
}
Double totalGoOut = 0.0d;
if(null != list.get(i)[4] && null != list.get(i)[5] && null != list.get(i)[8]){
totalGoOut =Double.parseDouble(list.get(i)[8].toString()) - Double.parseDouble(list.get(i)[5].toString())+Double.parseDouble(list.get(i)[4].toString());
//累计出货量
if (null != list.get(i)[10]&& totalGoOut>=Double.parseDouble(list.get(i)[10].toString())) {
totalGoOutStr= (int) (totalGoOut/Double.parseDouble( list.get(i)[10].toString()))+ list.get(i)[2].toString();
}
if (null != list.get(i)[10]&& null != secoUnit&&secoUnit.getSecondary2Basic()!=null && totalGoOut% Double.parseDouble(list.get(i)[10].toString()) != 0) {
totalGoOutStr=(totalGoOutStr + Tool.keep2DecimalRounding((totalGoOut- (int) (Double.parseDouble(list.get(i)[5].toString())/ Double.parseDouble(list.get(i)[10].toString()))
* Double.parseDouble(list.get(i)[10].toString()))
/ secoUnit.getSecondary2Basic()) + secoUnit.getUnit().getName());
}else {
if (null != list.get(i)[10]&&totalGoOut%Double.parseDouble(list.get(i)[10].toString())> 0&&null!= list.get(i)[11])
totalGoOutStr=(totalGoOutStr + Tool.keep2DecimalRounding((totalGoOut - (int) (totalGoOut/ Double.parseDouble(list.get(i)[10].toString())) * Double.parseDouble(list.get(i)[10].toString())))
+ list.get(i)[11].toString());
}
}
Label bomLable0 = new Label(3, totalAboveRow + i, "" + isNull(list.get(i)[0]), formatContentHeader);
Label bomLable1 = new Label(4, totalAboveRow + i, "" + isNull(list.get(i)[1]), formatContentHeader);
Label bomLable2 = new Label(5, totalAboveRow + i, "" + isNull(list.get(i)[2]), formatContentHeader);
Label bomLable3 = new Label(6, totalAboveRow + i, "" + isNull(orderNumber), formatContentHeader);//订货量
Label bomLable4 = new Label(7, totalAboveRow + i, "" + isNull(auditNumber), formatContentHeader);//审核量
Label bomLable5 = new Label(8, totalAboveRow + i, "" + isNull(oweNumber), formatContentHeader);//欠货量
Label bomLable6 = new Label(9, totalAboveRow + i, "" + isNull(list.get(i)[6]), formatContentHeader);
Label bomLable100 = new Label(10, totalAboveRow + i, "" + isNull(priceStr), formatContentHeader);
Label bomLable111 = new Label(11, totalAboveRow + i, "" + isNull(saleNumber), formatContentHeader);
Label bomLable120 = new Label(12, totalAboveRow + i, "" + isNull(totalGoOutStr), formatContentHeader);
bomLable9 = new Label(0, totalAboveRow + 1 + i, "合 计", formatColumnHeader);
bomLable11 = new Label(10, totalAboveRow + 1 + i, "" +Tool.keep4DecimalRounding1ToString( totalsum), formatColumnHeader);