public Bill getPendingBill() { // status of the bill could have been updated by some other process, so also checking if the // bill is pending if (this.pendingBill != null && this.pendingBill.getStatus().equals(BillStatusEnum.PENDING.getValue())) { return pendingBill; } Bill bill = null; Iterator itr = this.getBills().iterator(); while (itr.hasNext()) { Bill tempBill = (Bill) itr.next(); if (tempBill.getStatus().equals(BillStatusEnum.PENDING.getValue())) { if (bill != null) { throw new MultiplePendingBillsException( "User with userid, username : "******", " + this.getUsername() + "has multiple pending Bills"); } bill = tempBill; } } return bill; }
@RequestMapping(value = "/waiter/bills/{billId}", method = RequestMethod.GET) public String showBillInWaiter( @PathVariable("billId") String billId, Model uiModel, Locale locale) { // warmup stuff Bill bill = warmupRestaurant(billId, uiModel); Restaurant resto = bill.getDiningTable().getRestaurant(); List<Order> allPreparedOrders = orderService.findPreparedOrdersForRestaurant(resto); uiModel.addAttribute("allPreparedOrders", allPreparedOrders); List<Bill> allSubmittedBills = billService.findSubmittedBillsForRestaurant(resto); uiModel.addAttribute("allSubmittedBills", allSubmittedBills); uiModel.addAttribute( "message", new Message( "info", messageSource.getMessage("label_bill_amount", new Object[] {}, locale) + ": " + bill.getPriceAllOrders() + " " + messageSource.getMessage("label_currency", new Object[] {}, locale))); return "hartigehap/waiter"; }
private Bill warmupRestaurant(String billId, Model uiModel) { Bill bill = billService.findById(Long.valueOf(billId)); Collection<Restaurant> restaurants = restaurantService.findAll(); uiModel.addAttribute("restaurants", restaurants); Restaurant restaurant = restaurantService.fetchWarmedUp(bill.getDiningTable().getRestaurant().getId()); uiModel.addAttribute("restaurant", restaurant); return bill; }
private void printSummary() { int count = 0; int totalDebt = 0; for (Bill current = firstBill; current != null; current = current.getNextBill()) { count++; totalDebt += current.getAmount(); } System.out.println("You have " + count + " bills unpaid (total debt: " + totalDebt + ")"); }
private void returnChange(Check c) { int twentyDollar = 0; int tenDollar = 0; int fiveDollar = 0; int oneDollar = 0; int coins = 0; if (c.cash.totalAmount() >= c.price) { cashTotal += c.price; double change = c.cash.totalAmount() - c.price; Cash Change; twentyDollar = (int) change / 20; change -= 20 * twentyDollar; tenDollar = (int) change / 10; change -= 10 * tenDollar; fiveDollar = (int) change / 5; change -= 5 * fiveDollar; oneDollar = (int) change / 1; change -= 1 * oneDollar; coins = (int) (100 * ((double) (change) + 0.0001)); Change = new Cash(twentyDollar, tenDollar, fiveDollar, oneDollar, coins); Do("Change is " + dFormat.format(Change.totalAmount())); c.customer.msgChange(Change); } else { cashTotal += c.cash.totalAmount(); } checks.remove(c); // check bills if cashier earns money double sum = 0; for (Bill b : bills) { if (b.state == Bill.BillState.unPaid) { sum += (b.price * b.orderedSize); if (cashTotal >= sum) { log.add(new LoggedEvent("Now have enough money to pay")); Do("I can now pay to the " + b.market + " for the order " + b.food + " [extra creidt]"); b.state = Bill.BillState.nothing; } else { break; } } } }
public static void main(String[] args) { Bill bill1 = new Bill(System.out); MakeItem item1 = new MakeItem("Pizza", 7); MakeItem item2 = new MakeItem("Stenen", 20); MakeItem item3 = new MakeItem("15", 5.4); MakeItem item4 = new MakeItem("Mona", 24.13); bill1.newItem(item1); bill1.newItem(item2); bill1.newItem(item3); bill1.newItem(item4); bill1.close(); }
void save() { checkEditViewSet(); if (bill == null) bill = new Bill(); bill = editView.fillBill(bill); bill.setInitDate(initDate); bill.setEndDate(endDate); OperationResult result = repository.save(bill); if (result.isValid()) { editView.finishView(); } else { for (ValidationError validationError : result.getErrors()) editView.showError(validationError); } }
@Test public void testLaunch() throws IOException { int billCount = 2; this.addBillToList("Dentist", 61); this.addBillToList("MOT", 55); this.addBillToList("END", 0); int count = 0; for (Bill current = firstBill; current != null; current = current.getNextBill()) { count++; } assertEquals(count, billCount); }
/** * Fetches the last {@link Bill} that the user Paid. If User has not paid any bill, then returns * null * * @return * @since 1.0 */ public Bill getLastPaidBill() { Bill bill = null; int maxBillId = 0; Iterator itr = this.getBills().iterator(); while (itr.hasNext()) { Bill tempBill = (Bill) itr.next(); if (tempBill.getStatus().equals(BillStatusEnum.PAID.getValue())) { if (tempBill.getBillId() > maxBillId) maxBillId = tempBill.getBillId(); bill = tempBill; } } return bill; }
/** Scheduler. Determine what action is called for, and do it. */ public boolean pickAndExecuteAnAction() { synchronized (checks) { if (!checks.isEmpty()) { for (int i = 0; i < checks.size(); i++) { if (checks.get(i).state == Check.CheckState.nothing) { checks.get(i).state = Check.CheckState.computing; ComputeBill(checks.get(i)); return true; } else if (checks.get(i).state == Check.CheckState.doneComputing) { giveCheckToWaiter(checks.get(i)); return true; } else if (checks.get(i).state == Check.CheckState.receivedCash) { checks.get(i).state = Check.CheckState.paid; returnChange(checks.get(i)); // checks.remove(i); return true; } } } } synchronized (pendingChecks) { if (!pendingChecks.isEmpty()) { for (Check chk : pendingChecks) { checks.add(chk); } pendingChecks.clear(); return true; } } synchronized (bills) { if (!bills.isEmpty()) { for (Bill b : bills) { if (b.state == Bill.BillState.nothing) { b.state = Bill.BillState.inProcess; PayBill(b); return true; } else if (b.state == Bill.BillState.done) { bills.remove(b); return true; } } } } return false; }
private Response downloadMorePdf(List<Integer> billIdList) throws Exception { Response response = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); List<String> list = new ArrayList<String>(); for (int i = 0; i < billIdList.size(); i++) { Integer billId = billIdList.get(i); Map<String, Object> templateMap = getTemplateMap(billId); if (templateMap == null || templateMap.isEmpty()) { logger.info("账单数据不完整,无法下载账单"); continue; } StringBuffer fileNameStr = new StringBuffer(); Bill bill = billMapper.selectByPrimaryKey(billId); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); fileNameStr .append(bill.getAgencyNickName()) .append(sdf.format(bill.getBillStartTime())) .append("-") .append(sdf.format(bill.getBillEndTime())) .append(".") .append(".pdf"); // classpath 中模板路径,根据html模版来生成pdf String template = "pdfConfig/templates/test.html"; PdfDocumentGenerator pdfGenerator = new PdfDocumentGenerator(); // 生成pdf try { pdfGenerator.generate(template, getTemplateMap(billId), bos); } catch (DocumentGeneratingException e) { e.printStackTrace(); } list.add(fileNameStr.toString()); } zipFiles(list, bos); String zipFileName = date2String(new Date()) + ".zip"; response = Response.status(Status.OK) .header("Content-Type", "application/zip;charset=ISO8859-1") .header("Content-Disposition", "attachment; filename=\"" + zipFileName + "\"") .entity(bos.toByteArray()) .build(); return response; }
public static void show(Long id) { Bowl bowl = Bowl.findById(id); List<Participant> bowlParticipants = Participant.calculateShares(bowl); List<Bill> bills = Bill.generateByBowl(bowl); render(bowl, bowlParticipants, bills); }
@Test public void should_create_stalmentItems() throws Exception { final InstalmentServiceImpl instalmentService = new InstalmentServiceImpl(); Consumer consumer = TestHelper.consumer(1, "name"); Bill bill = TestHelper.bill(1, 900, new Timestamp(1447048827122L), consumer); InstalmentPolicy policy = new InstalmentPolicy(3, 1); final InstalmentRequest instalment = instalmentService.createInstalment(900, bill, policy); assertThat(instalment.getItems().size(), is(policy.getTerm())); final int amountPerTerm = bill.getAmount() / policy.getTerm(); final InstalmentItem item1 = instalment.getItems().get(0); final InstalmentItem item2 = instalment.getItems().get(1); final InstalmentItem item3 = instalment.getItems().get(2); assertThat(item1.getCommission(), is((int) (policy.getCommission() * 0.01 * amountPerTerm))); assertThat(item1.getRepaymentDay(), is(bill.getRepaymentDay())); assertThat(item2.getRepaymentDay().toString(), is(Date.valueOf("2016-01-03").toString())); assertThat(item3.getRepaymentDay().toString(), is(Date.valueOf("2016-02-03").toString())); }
private Response downloadOnePdf(final @QueryParam("billId") Integer billId) throws Exception { Response response = null; Map<String, Object> templateMap = getTemplateMap(billId); if (templateMap == null || templateMap.isEmpty()) { logger.info("账单数据不完整,无法下载账单"); return null; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); StringBuffer fileNameStr = new StringBuffer(); Bill bill = billMapper.selectByPrimaryKey(billId); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); fileNameStr .append(bill.getAgencyNickName()) .append(sdf.format(bill.getBillStartTime())) .append("-") .append(sdf.format(bill.getBillEndTime())) .append("."); fileNameStr.append(".pdf"); String fileName = new String(fileNameStr.toString().getBytes("GBK"), "ISO8859-1"); // classpath 中模板路径,根据html模版来生成pdf String template = "pdfConfig/templates/test.html"; PdfDocumentGenerator pdfGenerator = new PdfDocumentGenerator(); // 生成pdf try { pdfGenerator.generate(template, templateMap, bos); } catch (DocumentGeneratingException e) { e.printStackTrace(); } response = Response.status(Response.Status.OK) .header("Content-Type", "application/pdf;charset=ISO8859-1") .header("Content-Disposition", "attachment; filename=\"" + fileName + "\"") .entity(bos.toByteArray()) .build(); bos.close(); return response; }
void viewUpdated(boolean invalidateCache) { if (bill != null) { if (invalidateCache) bill = repository.find(bill.getUuid()); if (editView != null) { editView.setTitle(R.string.edit_bill_title); } else { String title = view.getContext().getString(R.string.bill); view.setTitle(title.concat(" ").concat(bill.getName())); } view.showBill(bill); initDate = bill.getInitDate(); if (editView != null) editView.onInitDateChanged(initDate); endDate = bill.getEndDate(); if (editView != null) editView.onEndDateChanged(endDate); } else { if (editView != null) editView.setTitle(R.string.new_bill_title); } }
@RequestMapping(value = "/waiter/bills/{billId}", method = RequestMethod.PUT) public String receiveBillEvent( @PathVariable("billId") String billId, @RequestParam String event, Model uiModel) { Bill bill = warmupRestaurant(billId, uiModel); switch (event) { case "billHasBeenPaid": billHasBeenPaid(bill); break; default: log.error("Internal error: event " + event + " not recognized"); break; } return "redirect:/restaurants/" + bill.getDiningTable().getRestaurant().getId() + "/waiter"; }
private void addBillToList(String concept, int amount) { if (concept == "END") return; Bill bill = new Bill(concept, amount); if (firstBill == null) { firstBill = bill; return; } Bill current = firstBill; while (current != null) { if (current.getNextBill() == null) { current.setNextBill(bill); return; } current = current.getNextBill(); } return; }
private void PayBill(Bill b) { // Bill b = bills.get(0); if (cashTotal >= (b.price * b.orderedSize)) { cashTotal -= b.price * b.orderedSize; b.market.msgPayment(b.price * b.orderedSize); b.state = Bill.BillState.done; } else { log.add(new LoggedEvent("Don't have enough money to pay")); Do( "I don't have enough money to pay to the " + b.market + " for the order " + b.food + " [extra creidt]"); b.state = Bill.BillState.unPaid; } }
/** * Checks if bill has been created for a User and returns true if a Paid or Pending bill exists. * If no {@link Bill} in {@link BillStatusEnum#PAID} or {@link BillStatusEnum#PENDING} status * exists, returns false. * * <p>Note: Cancelled Bill is not considered since it will never be paid by the user, so a * cancelled Bill is a non billed user. * * @return * @since 1.0 */ public boolean isUserBeenBilledOnce() { // status of the bill could have been updated by some other process, so also checking if the // bill is pending // if there is a pending bill, then this is not the first bill if (this.pendingBill != null && this.pendingBill.getStatus().equals(BillStatusEnum.PENDING.getValue())) { return true; } // if user has a paid bill, then this is not the first bill Iterator itr = this.getBills().iterator(); while (itr.hasNext()) { Bill tempBill = (Bill) itr.next(); if (tempBill.getStatus().equals(BillStatusEnum.PAID.getValue())) { return true; } } return false; }
private void billHasBeenPaid(Bill bill) { try { billService.billHasBeenPaid(bill); } catch (StateException e) { log.error( "Internal error has occurred! Order " + Long.valueOf(bill.getId()) + "has not been changed to served state!", e); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.office_item, null); } Bill item = items.get(position); if (item == null) { return null; } TextView num = (TextView) convertView.findViewById(R.id.number); TextView b = (TextView) convertView.findViewById(R.id.bill); TextView time = (TextView) convertView.findViewById(R.id.time); num.setText((position + 1) + ""); b.setText(item.getTitle()); if (type == 0) { time.setText(item.getTrun_time()); if (item.getCurrent_node_id().equals("7") || item.getCurrent_node_id().equals("9")) { b.setTextColor(activity.getResources().getColor(android.R.color.holo_red_dark)); } else { b.setTextColor(activity.getResources().getColor(android.R.color.black)); } } else { time.setText(item.getDone_time()); } return convertView; }
/** * Create an instance of {@link Bill } * * @param id * @param amount * @param period * @param rate * @param valuedate */ public Bill createBill(String id, String amount, String period, String rate, String valuedate) { Bill bill = new Bill(); bill.setId(id); bill.setAmount(amount); bill.setPeriod(period); bill.setRate(rate); bill.setValuedate(valuedate); return bill; }
void selectCustomer(ActionEvent evt) { try { nb.user.value.setText(((JButton) (evt.getSource())).getText()); nb.userId = (ServiceFacade.getInstance().getUserByUsername(((JButton) (evt.getSource())).getText())) .getUserId(); this.SelectPanel.setVisible(false); this.MenuPanel.setVisible(true); } catch (RemoteException ex) { Logger.getLogger(NewAccount.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(NewAccount.class.getName()).log(Level.SEVERE, null, ex); } catch (NotBoundException ex) { Logger.getLogger(NewAccount.class.getName()).log(Level.SEVERE, null, ex); } }
public static void main(String[] args) { Bill bill1 = new Bill(); Bill bill2 = new Bill(); Bill bill3 = new Bill(); NumberBinding total = Bindings.add( bill1.amountDueProperty().add(bill2.amountDueProperty()), bill3.amountDueProperty()); total.addListener( new InvalidationListener() { public void invalidated(Observable o) { System.out.println("The binding is now invalid."); } }); // First call makes the binding invalid bill1.setAmountDue(200.00); // The binding is now invalid bill2.setAmountDue(100.00); bill3.setAmountDue(75.00); // Make the binding valid... System.out.println(total.getValue()); // Make invalid... bill3.setAmountDue(150.00); // Make valid... System.out.println(total.getValue()); // Calling Money-API directly System.out.println(bill1.getNewAmountDue()); System.out.println(bill2.getNewAmountDue().add(bill1.getNewAmountDue())); // Some test to check out Temporal Temporal t = LocalDateTime.now(); System.out.println(t); }
public static void expense(Long id) { Expense expense = Expense.findById(id); List<Bill> bills = Bill.generateByExpense(expense); render(expense, bills); }
@Override public Bill createBill(Bill bill) { billMapper.createBill(bill); for (BillItem item : bill.getItems()) billItemMapper.createBillItem(item); return findBillById(bill.getId()); }
void selectTable(ActionEvent evt) { nb.table.value.setText(((JButton) (evt.getSource())).getText()); nb.tableId = Integer.parseInt(((JButton) (evt.getSource())).getText()); this.SelectPanel.setVisible(false); this.MenuPanel.setVisible(true); }
String getUuid() { return bill != null ? bill.getUuid() : null; }