String issueDateStr = GeneralImport.addField(csvElement,
"Issue Date", values, 4);
Date issueDate = new MonadDate(issueDateStr).getDate();
String startDateStr = GeneralImport.addField(csvElement,
"Start Date", values, 5);
HhStartDate startDate = new HhStartDate(startDateStr);
String finishDateStr = GeneralImport.addField(csvElement,
"Finish Date", values, 6);
HhStartDate finishDate = new HhStartDate(finishDateStr);
String netStr = GeneralImport
.addField(csvElement, "Net", values, 7);
BigDecimal net = new BigDecimal(netStr);
String vatStr = GeneralImport
.addField(csvElement, "Vat", values, 8);
BigDecimal vat = new BigDecimal(vatStr);
String grossStr = GeneralImport.addField(csvElement, "Gross",
values, 9);
BigDecimal gross = new BigDecimal(grossStr);
String account = GeneralImport.addField(csvElement,
"Account Reference", values, 10);
String reference = GeneralImport.addField(csvElement, "Reference",
values, 11);
String typeCode = GeneralImport.addField(csvElement, "Type",
values, 12);
BillType type = BillType.getBillType(typeCode);
String breakdown = GeneralImport.addField(csvElement, "Breakdown",
values, 13);
String kwhStr = GeneralImport.addField(csvElement, "kWh", values,
14);
BigDecimal kwh = new BigDecimal(kwhStr);
Bill bill = batch.insertBill(mpanCore.getSupply(), account,
reference, issueDate, startDate, finishDate, kwh, net, vat,
gross, type, breakdown);
for (int i = 15; i < values.length; i += 11) {
String meterSerialNumber = GeneralImport.addField(csvElement,
"Meter Serial Number", values, i);
String mpanStr = GeneralImport.addField(csvElement, "MPAN",
values, i + 1);
String coefficientStr = GeneralImport.addField(csvElement,
"Coefficient", values, i + 2);
BigDecimal coefficient = new BigDecimal(coefficientStr);
String unitsStr = GeneralImport.addField(csvElement, "Units",
values, i + 3);
Units units = Units.getUnits(unitsStr);
String tprStr = GeneralImport.addField(csvElement, "TPR",
values, i + 4);
Tpr tpr = null;
if (tprStr.length() > 0) {
tpr = Tpr.getTpr(tprStr);
}
String previousDateStr = GeneralImport.addField(csvElement,
"Previous Date", values, i + 5);
HhStartDate previousDate = new HhStartDate(previousDateStr);
String previousValueStr = GeneralImport.addField(csvElement,
"Previous Value", values, i + 6);
BigDecimal previousValue = new BigDecimal(previousValueStr);
String previousTypeStr = GeneralImport.addField(csvElement,
"Previous Type", values, i + 7);
ReadType previousType = ReadType.getReadType(previousTypeStr);
String presentDateStr = GeneralImport.addField(csvElement,
"Present Date", values, i + 8);
HhStartDate presentDate = new HhStartDate(presentDateStr);
String presentValueStr = GeneralImport.addField(csvElement,
"Present Value", values, i + 9);
BigDecimal presentValue = new BigDecimal(presentValueStr);
String presentTypeStr = GeneralImport.addField(csvElement,
"Present Type", values, i + 10);
ReadType presentType = ReadType.getReadType(presentTypeStr);
bill.insertRead(tpr, coefficient, units, meterSerialNumber,
mpanStr, previousDate, previousValue, previousType,
presentDate, presentValue, presentType);
}
} else if (action.equals("update")) {
String billIdStr = GeneralImport.addField(csvElement, "Bill Id",
values, 0);
Bill bill = Bill.getBill(Long.parseLong(billIdStr));
String account = GeneralImport.addField(csvElement,
"Account Reference", values, 1);
if (account.equals(GeneralImport.NO_CHANGE)) {
account = bill.getAccount();
}
String reference = GeneralImport.addField(csvElement, "Reference",
values, 2);
if (reference.equals(GeneralImport.NO_CHANGE)) {
reference = bill.getReference();
}
String issueDateStr = GeneralImport.addField(csvElement,
"Issue Date", values, 3);
Date issueDate = null;
if (issueDateStr.equals(GeneralImport.NO_CHANGE)) {
issueDate = bill.getIssueDate();
} else {
issueDate = new MonadDate(issueDateStr).getDate();
}
String startDateStr = GeneralImport.addField(csvElement,
"Start Date", values, 4);
HhStartDate startDate = null;
if (startDateStr.equals(GeneralImport.NO_CHANGE)) {
startDate = bill.getStartDate();
} else {
startDate = new HhStartDate(startDateStr);
}
String finishDateStr = GeneralImport.addField(csvElement,
"Finish Date", values, 5);
HhStartDate finishDate = null;
if (finishDateStr.equals(GeneralImport.NO_CHANGE)) {
finishDate = bill.getFinishDate();
} else {
finishDate = new HhStartDate(finishDateStr);
}
String kwhStr = GeneralImport
.addField(csvElement, "kWh", values, 6);
BigDecimal kwh = null;