@Transactional(readOnly = true)
 @RequestMapping(value = "/showListAgreements", method = RequestMethod.GET)
 @ResponseBody
 public Object simpleAgrimentsList(
     @RequestParam(required = false) Integer page_num,
     @RequestParam(required = false) Integer per_page,
     @RequestParam(value = "pkey_val[]", required = false) String pkey,
     @RequestParam(value = "q_word[]", required = false) String[] qword,
     HttpServletRequest request) {
   Long counterpart_id = Utils.getLongParameter("counterpart_id", request);
   // Sort sort= FormSort.formSortFromSortDescription(orderby);
   Sort sort = new Sort(Sort.Direction.ASC, "name");
   PageRequest pager = null;
   if (page_num != null && per_page != null) {
     page_num = page_num < 1 ? 1 : page_num;
     pager = new PageRequest(page_num - 1, per_page, sort);
   }
   if (pager != null) {
     Page<Agreement> page;
     if (qword != null && qword.length > 0) {
       if (counterpart_id != null) {
         page = agreementRepository.findAgreement(counterpart_id, qword[0], pager);
       } else {
         page = agreementRepository.findAgreement(qword[0], pager);
       }
     } else {
       if (counterpart_id != null) {
         page = agreementRepository.findAgreement(counterpart_id, pager);
       } else {
         page = agreementRepository.findAgreement(pager);
       }
     }
     return new JSComboExpenseResp<>(page);
   } else {
     if (pkey != null && !pkey.isEmpty()) {
       Long key = Long.valueOf(pkey);
       Agreement ft = null;
       if (key != null) {
         ft = agreementRepository.findOne(key);
       }
       return ft;
     } else {
       List<Agreement> page;
       if (qword != null && qword.length > 0) {
         if (counterpart_id != null) {
           page = agreementRepository.findAgreement(counterpart_id, qword[0], sort);
         } else {
           page = agreementRepository.findAgreement(qword[0], sort);
         }
       } else {
         if (counterpart_id != null) {
           page = agreementRepository.findAgreement(counterpart_id, sort);
         } else {
           page = agreementRepository.findAgreement(sort);
         }
       }
       return new JSComboExpenseResp<>(page);
     }
   }
 }
 @Transactional(readOnly = false)
 @RequestMapping(
     value = "/editagreements",
     method = {RequestMethod.POST, RequestMethod.GET})
 public void agrimentsEditor(
     @RequestParam String oper,
     @RequestParam long ID,
     Agreement agreement,
     BindingResult result,
     HttpServletResponse response)
     throws IOException {
   if (result.hasErrors()) {
     response.sendError(400, result.toString());
     return;
   }
   switch (oper) {
     case "add":
       {
         Counterparty counterparty = counterpartyRepository.findOne(ID);
         if (counterparty != null) {
           counterparty.addAgreement(agreement);
           agreementRepository.save(agreement);
           counterpartyRepository.save(counterparty);
           response.setStatus(200);
         } else {
           response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND");
         }
       }
       break;
     case "edit":
       {
         Agreement agr = agreementRepository.findOne(agreement.getId());
         if (agr != null && agr.getVersion() <= agreement.getVersion()) {
           agr.setNumber(agreement.getNumber());
           agr.setName(agreement.getName());
           agr.setStartDate(agreement.getStartDate());
           agr.setEndDate(agreement.getEndDate());
           agr.setPlanEndDate(agreement.getPlanEndDate());
           agreementRepository.save(agr);
           response.setStatus(200);
         } else {
           response.sendError(404, "NO Agreement WITH ID " + agreement.getId() + " FOUND");
         }
       }
       break;
     case "del":
       {
         Counterparty counterparty = counterpartyRepository.findOne(ID);
         if (counterparty != null) {
           Agreement agr = agreementRepository.findOne(agreement.getId());
           if (agr != null) {
             counterparty.removeAgreement(agr);
             agreementRepository.delete(agr);
             counterpartyRepository.save(counterparty);
             response.setStatus(200);
           } else {
             response.sendError(404, "NO Agreement WITH ID " + agreement.getId() + " FOUND");
           }
         } else {
           response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND");
         }
       }
       break;
     default:
       response.sendError(406, "UNKNOWN OPERATION");
   }
 }