Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name="transactions")
- public class Transactions implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "transactions_id")
- private Integer transactionsid;
- @Column(name = "date_de_MAJ")
- @DateTimeFormat(pattern = "yyyy-MM-dd")
- private Date datemaj;
- @Column(name = "item")
- private String item;
- @Column(name = "transaction")
- private Integer transaction;
- @Column(name = "q_actuelle")
- private Integer qactuelle;
- @Column(name = "q_old")
- private Integer qold;
- @Column(name = "type")
- private String type;
- @Column(name = "motif")
- private String motif;
- @Column(name = "personnel")
- private String personne;
- // by defaults methods
- }
- public interface TransactionsRepository extends JpaRepository<Transactions, Integer> {
- /*@Query("select t from Transactions t order by t.datemaj ASC")
- List<Transactions> findByIdOrderedByDate(Integer Id, Date date);*/
- @Query("SELECT DISTINCT t.type FROM Transactions t")
- public List<Transactions> findDistinctType();
- }
- @Controller
- public class TransactionsController {
- @Autowired
- private TransactionsRepository transRepo;
- @GetMapping("/")
- public String showPageTransaction(Model model) {
- model.addAttribute("data", transRepo.findAll(new Sort(Sort.Direction.DESC, "datemaj", "type")));
- //model.addAttribute("data", transactionsRepo.findByIdOrderedByDate(Id, date));
- model.addAttribute("typelist", transRepo.findDistinctType());
- return "index";
- }
- @PostMapping("/save")
- public String saveTransaction(Transactions t, BindingResult bindingResult) {
- if(bindingResult.hasErrors()){
- System.out.println("les erreurs"+ bindingResult.toString());
- return "redirect:/errors";
- }
- System.out.println("-------------------------------- transaction t Start ------------------------------");
- System.out.println(t.toString());
- System.out.println("-------------------------------- transaction t End ------------------------------");
- transRepo.save(t);
- return "redirect:/";
- }
- @GetMapping("/findOne")
- @ResponseBody
- public Optional<Transactions> findOneTransaction(Integer id) {
- return transRepo.findById(id);
- }
- }
- <table>
- <thead>
- <tr>
- <th>Id</th>
- <th>Type</th>
- <th>Item</th>
- <th>Transaction</th>
- <th>Quantité ancienne</th>
- <th>Quantité actuelle</th>
- <th>motif</th>
- <th>Date de MAJ</th>
- <th>Par</th>
- </tr>
- </thead>
- <tbody>
- <tr class="rClick" th:each="transaction :${data}">
- <td><a th:href="@{findOne(id=${transaction.transactionsid})}"
- th:text="${transaction.transactionsid}"
- class="btn btn-primary eBtn"></a></td>
- <td th:text="${transaction.type}"></td>
- <td th:text="${transaction.item}"></td>
- <td th:text="${transaction.transaction}"></td>
- <td th:text="${transaction.qold}"></td>
- <td th:text="${transaction.qactuelle}"></td>
- <td th:text="${transaction.motif}"></td>
- <td th:text="${transaction.datemaj}"></td>
- <td th:text="${transaction.personne}"></td>
- </tbody>
- </table>
- <div class="myForm">
- <form th:action="@{/save}" method="post">
- <div class="modal fade bd-example-modal-lg" id="exampleModal"
- tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-lg" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLabel">Changer or
- Créer</h5>
- <button type="button" class="close" data-dismiss="modal"
- aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <!-- ************************ -->
- <div class="modal-body">
- <div class="form-group idHide">
- <label for="idtrans" class="col-form-label">ID :</label> <input
- type="number" class="form-control" id="idtrans" name="idtrans"
- value="" readonly />
- </div>
- <div class="form-group">
- <label for="type" class="col-form-label">Type :</label>
- <div id="type"
- th:if="${typelist != null and not #lists.isEmpty(typelist)}">
- <select id="type" name="type">
- <option th:each="dropDownItem : ${typelist}"
- th:value="${dropDownItem}" th:text="${dropDownItem}" />
- </select>
- </div>
- <div th:if="${typelist == null or #lists.isEmpty(typelist)}">
- <div>"list non crée ou vide"</div>
- </div>
- </div>
- <div class="form-group">
- <label for="item" class="col-form-label">Item :</label> <input
- type="text" class="form-control" id="item" name="item" value="" />
- </div>
- <div>
- <label for="trans" class="col-form-label">Transaction :</label>
- <input
- type="number" class="form-control" id="trans" name="trans"
- value="" />
- <label for="qold" class="col-form-label">Ancienne
- quantité :</label>
- <input type="number" class="form-control" id="qold"
- name="qold" value="" />
- <label for="qactu"
- class="col-form-label">Nouvelle quantité (ancienne - transaction) :</label>
- <input
- type="number" class="form-control" id="qactu" name="qactu"
- value="" readonly />
- </div>
- <div class="form-group">
- <label for="motif" class="col-form-label">Motif de la transaction:</label> <input
- type="text" class="form-control" id="motif" name="motif"
- value="" />
- </div>
- <div class="form-group">
- <label for="datemaj" class="col-form-label">Date de
- mis-à-jour :</label> <input type="date" class="form-control"
- id="datemaj" name="datemaj" value="" />
- </div>
- <div class="form-group">
- <label for="personne" class="col-form-label">Par :</label> <input type="text" class="form-control"
- id="personne" name="personne" value="" />
- </div>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary"
- data-dismiss="modal">Close</button>
- <input type="submit" class="btn btn-primary" value="Sauvegarder" />
- </div>
- </div>
- </div>
- </div>
- </form>
- </div>
- $(document).ready(function() {
- $('*[data-href]').on("click", function() {
- window.location = $(this).data('href');
- return false;
- });
- $("td > a").on("click", function(e) {
- e.stopPropagation();
- e.preventDefault();
- var href = $(this).attr('href');
- $.get(href, function(transaction, status) {
- $('.myForm #idtrans').val(transaction.transactionsid);
- $('.myForm #type').val(transaction.type);
- $('.myForm #item').val(transaction.item);
- $('.myForm #trans').val(transaction.transaction);
- $('.myForm #qold').val(transaction.qold);
- $('.myForm #qactu').val(transaction.qactuelle);
- $('.myForm #datemaj').val(transaction.datemaj);
- $('.myForm #motif').val(transaction.motif);
- $('.myForm #personne').val(transaction.personne);
- });
- $('.myForm #exampleModal').modal();
- });
- });
- # Database
- spring.datasource.url = jdbc:mysql://localhost:3306/store?autoReconnect=true&useSSL=false
- spring.datasource.username = ******
- spring.datasource.password = ******
- spring.datasource.driver = com.mysql.jdbc.Driver
- # Hibernate
- spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
- spring.jpa.show_sql = true
- #spring.jpa.hibernate.hbm2ddl.auto= create
- spring.jpa.hibernate.ddl-auto = none
- #entitymanager.packagesToScan= com.watcom.first.entity
- Transactions [
- transactions_id=null,
- dateMAJ=null,
- item=scotch fil,
- transaction=null,
- q_actuelle=null,
- q_old=27,
- type=Accessoire,
- motif=Mohamed V,
- personne=Mark Dun
- ]
Add Comment
Please, Sign In to add comment