Changeset 16f38d4


Ignore:
Timestamp:
01/08/23 17:17:48 (2 years ago)
Author:
DarkoSasanski <darko.sasanski@…>
Branches:
main
Children:
0afa35a
Parents:
7e10599
Message:

Implemented processing of delivered articles by workers

Location:
FullyStocked/src/main
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • FullyStocked/src/main/java/com/bazi/fullystocked/Models/SqlViews/OrderedArticlesReport.java

    r7e10599 r16f38d4  
    2727    private ArticleStatus articlestatus;
    2828    private int orderid;
     29    private int storedquantity;
    2930}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/OrdersReportRepository.java

    r7e10599 r16f38d4  
    11package com.bazi.fullystocked.Repositories;
    22
     3import com.bazi.fullystocked.Models.Enumerations.OrderStatus;
    34import com.bazi.fullystocked.Models.SqlViews.OrdersReport;
     5import org.hibernate.criterion.Order;
    46import org.springframework.data.jpa.repository.JpaRepository;
    57import java.util.*;
     
    810    List<OrdersReport> findAllBySupplieruserid(Integer id);
    911    List<OrdersReport> findAllByManageruserid(Integer id);
     12    List<OrdersReport> findAllByStatus(OrderStatus status);
    1013}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/OrdersServiceImpl.java

    r7e10599 r16f38d4  
    192192    }
    193193
     194    @Override
     195    public List<OrdersReport> findByStatus(OrderStatus status) {
     196        return ordersReportRepository.findAllByStatus(status);
     197    }
     198
    194199}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/OrdersService.java

    r7e10599 r16f38d4  
    2323    Optional<OrdersReport> findByIdReport(Integer orderId);
    2424    Optional<Orders> updateStatus(Integer orderId, OrderStatus status);
     25    List<OrdersReport> findByStatus(OrderStatus status);
    2526
    2627}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/OrderController.java

    r7e10599 r16f38d4  
    291291        return "redirect:/orders/manager/details/"+orderId;
    292292    }
     293    @GetMapping("/worker/list")
     294    public String listOrdersWorker(Model model)
     295    {
     296        model.addAttribute("orders", ordersService.findByStatus(OrderStatus.IN_PROGRESS));
     297        return "workerOrders";
     298    }
    293299    @PostMapping("/worker/accept")
    294300    public String acceptOrder(@RequestParam Integer orderId)
    295301    {
    296         ordersService.updateStatus(orderId, OrderStatus.DELIVERED);
    297         return "redirect:/worker";
     302        try {
     303            ordersService.updateStatus(orderId, OrderStatus.DELIVERED);
     304        }
     305        catch (Exception e)
     306        {
     307            return "redirect:/orders/worker/list"+e.getMessage();
     308        }
     309        return "redirect:/orders/worker/list";
    298310    }
    299311}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/WorkerController.java

    r7e10599 r16f38d4  
    11package com.bazi.fullystocked.Web.Controller;
    22
     3import com.bazi.fullystocked.Models.Enumerations.ArticleStatus;
    34import com.bazi.fullystocked.Models.SqlViews.ArticlesReport;
    45import com.bazi.fullystocked.Models.Workers;
    56import com.bazi.fullystocked.Services.ArticlesService;
     7import com.bazi.fullystocked.Services.OrderedArticlesService;
    68import com.bazi.fullystocked.Services.StoredArticlesService;
    79import org.springframework.stereotype.Controller;
    810import org.springframework.ui.Model;
    9 import org.springframework.web.bind.annotation.GetMapping;
    10 import org.springframework.web.bind.annotation.PathVariable;
    11 import org.springframework.web.bind.annotation.RequestMapping;
     11import org.springframework.web.bind.annotation.*;
    1212
    1313import javax.servlet.http.HttpServletRequest;
     
    1919   private final StoredArticlesService storedArticlesService;
    2020   private final ArticlesService articlesService;
     21   private final OrderedArticlesService orderedArticlesService;
    2122
    22     public WorkerController(StoredArticlesService storedArticlesService, ArticlesService articlesService) {
     23    public WorkerController(StoredArticlesService storedArticlesService, ArticlesService articlesService, OrderedArticlesService orderedArticlesService) {
    2324        this.storedArticlesService = storedArticlesService;
    2425        this.articlesService = articlesService;
     26        this.orderedArticlesService = orderedArticlesService;
    2527    }
    2628
     
    5153        return "redirect:/worker/articles?error=ArticleNotFound";
    5254    }
     55    @GetMapping("/deliveredArticles")
     56    public String listDeliveredArticles(Model model, HttpServletRequest request)
     57    {
     58        Workers u= (Workers) request.getSession().getAttribute("user");
     59        model.addAttribute("articles", orderedArticlesService.findByStatusAtLocation(ArticleStatus.DELIVERED, u.getLocation().getLocationid()));
     60        return "deliveredArticles";
     61    }
     62
     63    @PostMapping("/deliveredArticles/process")
     64    public String processOrderedArticle(@RequestParam Integer articleId, HttpServletRequest request)
     65    {
     66        try
     67        {
     68            Workers u= (Workers) request.getSession().getAttribute("user");
     69            if(storedArticlesService.findById(articleId).isEmpty())
     70            {
     71                return "redirect:/worker/deliveredArticles";
     72            }
     73            if(!storedArticlesService.findById(articleId).get().getLocationid().equals(u.getLocation().getLocationid()))
     74            {
     75                return "redirect:/login";
     76            }
     77            storedArticlesService.updateFromOrder(articleId);
     78            return "redirect:/worker/deliveredArticles";
     79        }
     80        catch (Exception e)
     81        {
     82            return "redirect:/worker/deliveredArticles?error="+e.getMessage();
     83        }
     84    }
     85
    5386}
  • FullyStocked/src/main/resources/templates/supplierOrders.html

    r7e10599 r16f38d4  
    4949        </th>
    5050        <th>
    51             Добавувач
     51            Забелешка на менаџер
     52        </th>
     53        <th>
     54            Забелешка на добавувач
    5255        </th>
    5356        <th>
     
    5659        <th>
    5760            Приоритет
    58         </th>
    59         <th>
    60             Забелешка
    6161        </th>
    6262        <th>
Note: See TracChangeset for help on using the changeset viewer.