@Override public Truck findOperationallCostTruck(String operationalCostId) { List<Truck> truckList = ImmutableList.copyOf(truckRepository.findAll()); for (Truck truck : truckList) { if (getTruckOperationalCost(truck.getOperatingCosts(), operationalCostId)) { return truck; } } return null; }
public AssignedDriversTable(MshenguMain main) { this.main = main; setSizeFull(); addContainerProperty("Vehicle Number", String.class, null); addContainerProperty("Brand", String.class, null); addContainerProperty("Model", String.class, null); addContainerProperty("Number Plate", String.class, null); addContainerProperty("Expire Date", String.class, null); addContainerProperty("Driver", String.class, null); addContainerProperty("In Service?", Boolean.class, null); // addContainerProperty("Contact Number", String.class, null); // Add Data Columns List<Truck> truckList = TruckFacade.getTruckService().findAll(); for (Truck truck : truckList) { addItem( new Object[] { truck.getVehicleNumber(), truck.getBrand(), truck.getModel(), truck.getNumberPlate(), formatHelper.getYearMonthDay(truck.getDateOfExpire()), truck.getDriverName(), truck.isIsActive(), }, truck.getId()); } // Allow selecting items from the table. setNullSelectionAllowed(false); setSelectable(true); // Send changes in selection immediately to server. setImmediate(true); }
private List<MaintenanceSpendBySupplier> getTruckMaintenanceSpend( Truck truck, Date from, Date to) { Query truckMaintenanceSpendListQuery = new Query(); truckMaintenanceSpendListQuery.addCriteria( Criteria.where("truckId") .is(truck.getId()) .andOperator( Criteria.where("transactionDate").gte(from), Criteria.where("transactionDate").lte(to))); /* * List<MaintenanceSpendBySupplier> maintenanceSpendList = mongoOperation.find(truckMaintenanceSpendListQuery, MaintenanceSpendBySupplier.class); System.out.println(" MaintenanceSpendBySupplierRepository - TRUCK QUERY - Start= " + to + " | To= " + to + " FOR truckId: " + truck.getId()); if (maintenanceSpendList.isEmpty()) { System.out.println("MaintenanceSpendBySupplierRepository - TRUCK QUERY - NO MATCHING RECORDS FOUND"); } for (MaintenanceSpendBySupplier maintenanceSpend : maintenanceSpendList) { System.out.println(" MaintenanceSpendBySupplierRepository - TRUCK QUERY - Date= " + maintenanceSpend.getTransactionDate() + " | Cost= " + maintenanceSpend.getMaintenanceCost() + " | Truck= " + maintenanceSpend.getTruckId() + " | Supplier" + maintenanceSpend.getSupplierId()); } System.out.println("--==--"); */ return mongoOperation.find(truckMaintenanceSpendListQuery, MaintenanceSpendBySupplier.class); }
@Test public void testSheet() { try { truckService = ctx.getBean(TruckService.class); annualDataService = ctx.getBean(AnnualDataFleetFuelService.class); personService = ctx.getBean(PersonService.class); StringTokenizer stringTokenizer; SimpleDateFormat simpleFormat = (SimpleDateFormat) DateFormat.getDateInstance(); simpleFormat.applyPattern("dd-MMM-yyyy"); // Open the Excel File URL url = this.getClass().getResource("/setupfleet/Fleet_Data_Annual.xls"); FileInputStream fileInputStream = new FileInputStream(url.getFile()); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); // Open Spreadsheet Work book // Process each Sheet at a time. API FAILS to move to next sheets for (int j = 16; j <= 16; j++) { Date datee = null; String truckId = null; String driverPersonId = null; BigDecimal amount; Integer closingMileage; // Get the first Sheet(0) HSSFSheet worksheet = workbook.getSheetAt(j); // First Sheet is 0 , second is 1 and so on vehicleNumber = worksheet.getRow(4).getCell(0).toString().trim(); employeeNumber = worksheet.getRow(4).getCell(4).toString().trim(); System.out.println( "\n\n" + "Begin processing Sheet: " + j + " i.e. " + vehicleNumber + ", Driver: " + employeeNumber); // Get the Truck based of the VEHICLEnUMBER truck = truckService.findByVehicleNumber(vehicleNumber); // Set this as Start Milleage for Truck if (truck != null) { truckId = truck.getId(); } // Get personId driver = personService.findDriverWithEmployeeNumber(employeeNumber); if (driver != null) { driverPersonId = driver.getId(); } if (truck != null && driver != null) { // iterated through all the rows for (int i = 4; i <= worksheet.getPhysicalNumberOfRows(); i++) { // if Row 6, index is (5) try { datee = simpleFormat.parse( worksheet.getRow(i).getCell(1).toString().trim()); // String to Date } catch (ParseException ex) { Logger.getLogger(Setup_DailyInputSheetOne.class.getName()) .log(Level.SEVERE, null, ex); List<AnnualDataFleetFuel> annualDataFleetFuelList = annualDataService.findAll(); for (AnnualDataFleetFuel annualDataFuel : annualDataFleetFuelList) { System.out.println( "READING DATABASE - TruckId: " + annualDataFuel.getTruckId() + ". Date: " + annualDataFuel.getTransactionDate() + ". Amount: " + annualDataFuel.getMonthlyFuelCost() + ". Closing Mileage: " + annualDataFuel.getClosingMileage() + ". Driver Person ID: " + annualDataFuel.getDriverPersonId()); } } // amount = new BigDecimal(worksheet.getRow(i).getCell(2).toString().trim()); if (amount.compareTo(new BigDecimal("0.0")) == 0) { amount = new BigDecimal("0.00"); } // String mileageToken = worksheet.getRow(i).getCell(3).toString().trim(); stringTokenizer = new StringTokenizer(mileageToken, "."); closingMileage = Integer.parseInt(stringTokenizer.nextElement().toString()); // System.out.println( "TruckId: " + truckId + ". Date: " + datee + ". Amount: " + amount.setScale(2, BigDecimal.ROUND_HALF_UP) + ". Closing Mileage: " + closingMileage + ". Driver Person ID: " + driverPersonId); // Build and Persist the AnnualDataFleetFuel Object AnnualDataFleetFuel annualData = createAnnualDataEntity( datee, amount.setScale(2, BigDecimal.ROUND_HALF_UP), closingMileage, truckId, driverPersonId); annualDataService.persist(annualData); // // Build and Update the Truck Object // addTruckAnnualData(annualData); } } else { if (truck != null) { System.out.println("Truck NOT FOUND"); } if (driver != null) { System.out.println("DRIVER NOT FOUND"); } } } fileInputStream.close(); } catch (FileNotFoundException e) { System.out.println("\n\n" + "File Not Found in function setupDailyInputs()"); System.out.println("" + e); } catch (IOException e) { System.out.println("\n\n" + "Problem Reading File: /setupfleet/Fleet_Data_Annual.xls"); System.out.println("" + e); } }