Guest User

Untitled

a guest
Aug 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. @Entity
  2. @Table(name="transactions")
  3. public class Transactions implements Serializable {
  4. private static final long serialVersionUID = 1L;
  5. @Id
  6. @GeneratedValue(strategy = GenerationType.IDENTITY)
  7. @Column(name = "transactions_id")
  8. private Integer transactionsid;
  9.  
  10. @Column(name = "date_de_MAJ")
  11. @DateTimeFormat(pattern = "yyyy-MM-dd")
  12. private Date datemaj;
  13.  
  14. @Column(name = "item")
  15. private String item;
  16.  
  17. @Column(name = "transaction")
  18. private Integer transaction;
  19.  
  20. @Column(name = "q_actuelle")
  21. private Integer qactuelle;
  22.  
  23. @Column(name = "q_old")
  24. private Integer qold;
  25.  
  26. @Column(name = "type")
  27. private String type;
  28.  
  29. @Column(name = "motif")
  30. private String motif;
  31.  
  32. @Column(name = "personnel")
  33. private String personne;
  34. // by defaults methods
  35. }
  36.  
  37. public interface TransactionsRepository extends JpaRepository<Transactions, Integer> {
  38.  
  39. /*@Query("select t from Transactions t order by t.datemaj ASC")
  40. List<Transactions> findByIdOrderedByDate(Integer Id, Date date);*/
  41.  
  42. @Query("SELECT DISTINCT t.type FROM Transactions t")
  43. public List<Transactions> findDistinctType();
  44.  
  45. }
  46.  
  47. @Controller
  48. public class TransactionsController {
  49.  
  50. @Autowired
  51. private TransactionsRepository transRepo;
  52.  
  53. @GetMapping("/")
  54. public String showPageTransaction(Model model) {
  55. model.addAttribute("data", transRepo.findAll(new Sort(Sort.Direction.DESC, "datemaj", "type")));
  56. //model.addAttribute("data", transactionsRepo.findByIdOrderedByDate(Id, date));
  57. model.addAttribute("typelist", transRepo.findDistinctType());
  58. return "index";
  59. }
  60.  
  61. @PostMapping("/save")
  62. public String saveTransaction(Transactions t, BindingResult bindingResult) {
  63. if(bindingResult.hasErrors()){
  64. System.out.println("les erreurs"+ bindingResult.toString());
  65. return "redirect:/errors";
  66. }
  67. System.out.println("-------------------------------- transaction t Start ------------------------------");
  68. System.out.println(t.toString());
  69. System.out.println("-------------------------------- transaction t End ------------------------------");
  70. transRepo.save(t);
  71. return "redirect:/";
  72. }
  73.  
  74. @GetMapping("/findOne")
  75. @ResponseBody
  76. public Optional<Transactions> findOneTransaction(Integer id) {
  77. return transRepo.findById(id);
  78.  
  79. }
  80.  
  81. }
  82.  
  83. <table>
  84. <thead>
  85. <tr>
  86. <th>Id</th>
  87. <th>Type</th>
  88. <th>Item</th>
  89. <th>Transaction</th>
  90. <th>Quantité ancienne</th>
  91. <th>Quantité actuelle</th>
  92. <th>motif</th>
  93. <th>Date de MAJ</th>
  94. <th>Par</th>
  95. </tr>
  96. </thead>
  97. <tbody>
  98. <tr class="rClick" th:each="transaction :${data}">
  99. <td><a th:href="@{findOne(id=${transaction.transactionsid})}"
  100. th:text="${transaction.transactionsid}"
  101. class="btn btn-primary eBtn"></a></td>
  102. <td th:text="${transaction.type}"></td>
  103. <td th:text="${transaction.item}"></td>
  104. <td th:text="${transaction.transaction}"></td>
  105. <td th:text="${transaction.qold}"></td>
  106. <td th:text="${transaction.qactuelle}"></td>
  107. <td th:text="${transaction.motif}"></td>
  108. <td th:text="${transaction.datemaj}"></td>
  109. <td th:text="${transaction.personne}"></td>
  110. </tbody>
  111. </table>
  112.  
  113. <div class="myForm">
  114. <form th:action="@{/save}" method="post">
  115. <div class="modal fade bd-example-modal-lg" id="exampleModal"
  116. tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
  117. aria-hidden="true">
  118. <div class="modal-dialog modal-lg" role="document">
  119. <div class="modal-content">
  120. <div class="modal-header">
  121. <h5 class="modal-title" id="exampleModalLabel">Changer or
  122. Créer</h5>
  123. <button type="button" class="close" data-dismiss="modal"
  124. aria-label="Close">
  125. <span aria-hidden="true">&times;</span>
  126. </button>
  127. </div>
  128. <!-- ************************ -->
  129. <div class="modal-body">
  130. <div class="form-group idHide">
  131. <label for="idtrans" class="col-form-label">ID :</label> <input
  132. type="number" class="form-control" id="idtrans" name="idtrans"
  133. value="" readonly />
  134. </div>
  135. <div class="form-group">
  136. <label for="type" class="col-form-label">Type :</label>
  137. <div id="type"
  138. th:if="${typelist != null and not #lists.isEmpty(typelist)}">
  139. <select id="type" name="type">
  140. <option th:each="dropDownItem : ${typelist}"
  141. th:value="${dropDownItem}" th:text="${dropDownItem}" />
  142. </select>
  143. </div>
  144. <div th:if="${typelist == null or #lists.isEmpty(typelist)}">
  145. <div>"list non crée ou vide"</div>
  146. </div>
  147. </div>
  148. <div class="form-group">
  149. <label for="item" class="col-form-label">Item :</label> <input
  150. type="text" class="form-control" id="item" name="item" value="" />
  151. </div>
  152. <div>
  153. <label for="trans" class="col-form-label">Transaction :</label>
  154. <input
  155. type="number" class="form-control" id="trans" name="trans"
  156. value="" />
  157. <label for="qold" class="col-form-label">Ancienne
  158. quantité :</label>
  159. <input type="number" class="form-control" id="qold"
  160. name="qold" value="" />
  161. <label for="qactu"
  162. class="col-form-label">Nouvelle quantité (ancienne - transaction) :</label>
  163. <input
  164. type="number" class="form-control" id="qactu" name="qactu"
  165. value="" readonly />
  166. </div>
  167. <div class="form-group">
  168. <label for="motif" class="col-form-label">Motif de la transaction:</label> <input
  169. type="text" class="form-control" id="motif" name="motif"
  170. value="" />
  171. </div>
  172. <div class="form-group">
  173. <label for="datemaj" class="col-form-label">Date de
  174. mis-à-jour :</label> <input type="date" class="form-control"
  175. id="datemaj" name="datemaj" value="" />
  176. </div>
  177. <div class="form-group">
  178. <label for="personne" class="col-form-label">Par :</label> <input type="text" class="form-control"
  179. id="personne" name="personne" value="" />
  180. </div>
  181.  
  182. </div>
  183. <div class="modal-footer">
  184. <button type="button" class="btn btn-secondary"
  185. data-dismiss="modal">Close</button>
  186. <input type="submit" class="btn btn-primary" value="Sauvegarder" />
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. </form>
  192.  
  193. </div>
  194.  
  195. $(document).ready(function() {
  196. $('*[data-href]').on("click", function() {
  197. window.location = $(this).data('href');
  198. return false;
  199. });
  200. $("td > a").on("click", function(e) {
  201. e.stopPropagation();
  202. e.preventDefault();
  203. var href = $(this).attr('href');
  204.  
  205. $.get(href, function(transaction, status) {
  206. $('.myForm #idtrans').val(transaction.transactionsid);
  207. $('.myForm #type').val(transaction.type);
  208. $('.myForm #item').val(transaction.item);
  209. $('.myForm #trans').val(transaction.transaction);
  210. $('.myForm #qold').val(transaction.qold);
  211. $('.myForm #qactu').val(transaction.qactuelle);
  212. $('.myForm #datemaj').val(transaction.datemaj);
  213. $('.myForm #motif').val(transaction.motif);
  214. $('.myForm #personne').val(transaction.personne);
  215. });
  216.  
  217. $('.myForm #exampleModal').modal();
  218.  
  219. });
  220.  
  221. });
  222.  
  223. # Database
  224. spring.datasource.url = jdbc:mysql://localhost:3306/store?autoReconnect=true&useSSL=false
  225. spring.datasource.username = ******
  226. spring.datasource.password = ******
  227. spring.datasource.driver = com.mysql.jdbc.Driver
  228.  
  229. # Hibernate
  230. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  231. spring.jpa.show_sql = true
  232. #spring.jpa.hibernate.hbm2ddl.auto= create
  233. spring.jpa.hibernate.ddl-auto = none
  234. #entitymanager.packagesToScan= com.watcom.first.entity
  235.  
  236. Transactions [
  237. transactions_id=null,
  238. dateMAJ=null,
  239. item=scotch fil,
  240. transaction=null,
  241. q_actuelle=null,
  242. q_old=27,
  243. type=Accessoire,
  244. motif=Mohamed V,
  245. personne=Mark Dun
  246. ]
Add Comment
Please, Sign In to add comment