コード例 #1
0
  @RequestMapping(
      value = "/{invoiceId}/control-letters/{id}/rows/create",
      method = RequestMethod.GET)
  public String showControlLetterRowCreateForm(
      @PathVariable("invoiceId") int invoiceId, @PathVariable("id") int id, Model model) {
    ControlLetterRow controlLetterRow = new ControlLetterRow();
    // TODO: Validate id that coming from form
    controlLetterRow.setControlLetterId(id);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
    List<Route> routes = routeService.findAll();

    model.addAttribute("controlLetterRow", controlLetterRow);
    model.addAttribute("routes", routes);
    model.addAttribute("employees", employees);
    model.addAttribute("invoiceId", invoiceId);

    return "controlLetterRow/edit";
  }
コード例 #2
0
  @RequestMapping(value = "/{invoiceId}/control-letters/{controlLetterId}/rows/{id}")
  public String showControlLetterRow(
      @PathVariable("invoiceId") int invoiceId,
      @PathVariable("controlLetterId") int controlLetterId,
      @PathVariable("id") int id,
      Model model) {

    ControlLetterRow controlLetterRow = controlLetterRowService.find(id);
    if (controlLetterRow == null) throw new ResourceNotFoundException();
    controlLetterRow.setControlLetterId(controlLetterId);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
    List<Route> routes = routeService.findAll();

    model.addAttribute("routes", routes);
    model.addAttribute("employees", employees);
    model.addAttribute("controlLetterRow", controlLetterRow);
    model.addAttribute("invoiceId", invoiceId);

    return "controlLetterRow/edit";
  }
コード例 #3
0
  @RequestMapping(value = "/{invoiceId}/control-letters/{id}/rows", method = RequestMethod.POST)
  public String createOrUpdateControlLetterRow(
      @PathVariable("id") int controlLetterid,
      @PathVariable("invoiceId") int invoiceId,
      @ModelAttribute("controlLetterRow") @Validated ControlLetterRow controlLetterRow,
      BindingResult bindingResult,
      Model model,
      RedirectAttributes redirectAttributes) {

    if (!bindingResult.hasErrors())
      controlLetterRowValidator.validate(controlLetterRow, bindingResult);

    if (bindingResult.hasErrors()) {
      List<Employee> employees =
          employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
      List<Route> routes = routeService.findAll();
      model.addAttribute("routes", routes);
      model.addAttribute("employees", employees);
      model.addAttribute("invoiceId", invoiceId);
      model.addAttribute("employees", employees);

      return "controlLetterRow/edit";
    }

    // TODO: Trigger
    // Якщо рядок новий, то кондуктор ще не повертав квитки, отже вважаємо, що він повернув все, що
    // отримав
    if (controlLetterRow.isNew())
      controlLetterRow.setTicketsReturned(controlLetterRow.getTicketsGiven());

    return handleSaving(
        controlLetterRow,
        controlLetterRowService,
        redirectAttributes,
        "tickets-invoices/" + invoiceId + "/control-letters/" + controlLetterid + "/rows");
  }