コード例 #1
0
  @RequestMapping(value = "/create", method = RequestMethod.GET)
  public String showCreateForm(Model model) {
    TicketsInvoice ticketsInvoice = new TicketsInvoice();
    List<Employee> employees =
        employeeService.findAll(Employee.EmployeePosition.MAIN_CASIER.getId());

    model.addAttribute("ticketsInvoice", ticketsInvoice);
    model.addAttribute("employees", employees);

    return "ticketsInvoice/edit";
  }
コード例 #2
0
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public String findOne(@PathVariable("id") int id, Model model) {
    TicketsInvoice ticketsInvoice = ticketsInvoiceService.find(id);
    if (ticketsInvoice == null) throw new ResourceNotFoundException();

    List<Employee> employees =
        employeeService.findAll(Employee.EmployeePosition.MAIN_CASIER.getId());

    model.addAttribute("employees", employees);
    model.addAttribute("ticketsInvoice", ticketsInvoice);
    return "ticketsInvoice/edit";
  }
コード例 #3
0
  @RequestMapping(value = "/{id}/control-letters/create", method = RequestMethod.GET)
  public String showControlLetterCreateForm(@PathVariable("id") int id, Model model) {
    ControlLetter controlLetter = new ControlLetter();
    // TODO: Validate income id that coming from form
    controlLetter.setIncomeId(id);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());

    model.addAttribute("controlLetter", controlLetter);
    model.addAttribute("employees", employees);

    return "controlLetter/edit";
  }
コード例 #4
0
  @RequestMapping(value = "/{invoiceId}/control-letters/{id}")
  public String showControlLetter(
      @PathVariable("invoiceId") int invoiceId, @PathVariable("id") int id, Model model) {

    ControlLetter controlLetter = controlLetterService.find(id);
    if (controlLetter == null) throw new ResourceNotFoundException();
    controlLetter.setIncomeId(invoiceId);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());

    model.addAttribute("employees", employees);
    model.addAttribute("controlLetter", controlLetter);
    return "controlLetter/edit";
  }
コード例 #5
0
  @RequestMapping(value = "/", method = RequestMethod.POST)
  public String createOrUpdate(
      @ModelAttribute("ticketsInvoice") @Validated TicketsInvoice ticketsInvoice,
      BindingResult bindingResult,
      Model model,
      RedirectAttributes redirectAttributes) {
    ticketsInvoiceValidator.validate(ticketsInvoice, bindingResult);
    if (bindingResult.hasErrors()) {
      List<Employee> employees =
          employeeService.findAll(Employee.EmployeePosition.MAIN_CASIER.getId());
      model.addAttribute("employees", employees);

      return "ticketsInvoice/edit";
    }

    return handleSaving(ticketsInvoice, ticketsInvoiceService, redirectAttributes, null);
  }
コード例 #6
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";
  }
コード例 #7
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";
  }
コード例 #8
0
  @RequestMapping(value = "/{id}/control-letters", method = RequestMethod.POST)
  public String createOrUpdateControlLetter(
      @PathVariable("id") int invoiceId,
      @ModelAttribute("controlLetter") @Validated ControlLetter controlLetter,
      BindingResult bindingResult,
      Model model,
      RedirectAttributes redirectAttributes) {

    if (!bindingResult.hasErrors()) controlLetterValidator.validate(controlLetter, bindingResult);

    if (bindingResult.hasErrors()) {
      List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());
      model.addAttribute("employees", employees);

      return "controlLetter/edit";
    }

    return handleSaving(
        controlLetter,
        controlLetterService,
        redirectAttributes,
        "tickets-invoices/" + invoiceId + "/control-letters");
  }
コード例 #9
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");
  }