Skip to content

Commit

Permalink
WORK ON DOCUMENT CONTROLLER
Browse files Browse the repository at this point in the history
CREATE NOMENCLATURE CONTROLLER
TODO:
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTEOLLED TASK FOR USER
SHOW USERS TASK
STOREHAUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
REGISTER BED PRODUCT
  • Loading branch information
FairWindCo committed Oct 27, 2015
1 parent be7cc3e commit 2ee6a17
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.Utils;
import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.MOVEMENT_TYPES;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Movement;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.MovementElements;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Storehouse;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.*;
import ua.pp.fairwind.favorid.internalDB.repository.*;
import ua.pp.fairwind.favorid.internalDB.security.UserDetailsAdapter;

Expand Down Expand Up @@ -52,6 +50,37 @@ public String list(Model model) {
return "storehouse_operation_list";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_special", method = RequestMethod.GET)
public String list_special(Model model) {
return "storehouse_operation_list_special";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_arrival", method = RequestMethod.GET)
public String list_arrival(Model model) {
return "storehouse_operation_list_arrival";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_shipment", method = RequestMethod.GET)
public String list_shipment(Model model) {
return "storehouse_operation_list_shipment";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_move", method = RequestMethod.GET)
public String list_move(Model model) {
return "storehouse_operation_list_move";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_utilization", method = RequestMethod.GET)
public String list_utilization(Model model) {
return "storehouse_operation_list_utilization";
}


@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
Expand Down Expand Up @@ -82,6 +111,61 @@ public JGridRowsResponse<Movement> getTable(HttpServletRequest request){
}
}

private JGridRowsResponse<Movement> getOperations(HttpServletRequest request,MOVEMENT_TYPES type){
PageRequest pageRequest=null;
if(request.getParameter("page")!=null){
int rows=10;
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
rows = request.getParameter("rows") == null ? 10 : Integer.parseInt(request.getParameter("rows"));
if(request.getParameter("sidx")!=null && !request.getParameter("sidx").isEmpty()){
String direction=request.getParameter("sord");
pageRequest=new PageRequest(page,rows,"asc".equals(direction)? Sort.Direction.ASC: Sort.Direction.DESC,request.getParameter("sidx"));
} else {
pageRequest=new PageRequest(page,rows);
}
}catch (NumberFormatException ex){
//do nothing
}

}/**/
if(pageRequest!=null){
return new JGridRowsResponse<>(movementRepository.findByTypeMovement(type, pageRequest));
} else {
return new JGridRowsResponse<>(movementRepository.findByTypeMovement(type));
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/arrivallisting", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Movement> getArrivalTable(HttpServletRequest request){
return getOperations(request,MOVEMENT_TYPES.ARRIVAL);
}

@Transactional(readOnly = true)
@RequestMapping(value = "/shipmentlisting", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Movement> getShipmentTable(HttpServletRequest request){
return getOperations(request,MOVEMENT_TYPES.SHIPMENT);
}

@Transactional(readOnly = true)
@RequestMapping(value = "/movelisting", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Movement> getMoveTable(HttpServletRequest request){
return getOperations(request,MOVEMENT_TYPES.MOVE);
}

@Transactional(readOnly = true)
@RequestMapping(value = "/utilizzationlisting", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Movement> getUtilizTable(HttpServletRequest request){
return getOperations(request,MOVEMENT_TYPES.UTILIZATION);
}

@Transactional(readOnly = true)
@RequestMapping(value = "/elements", method = RequestMethod.POST)
@ResponseBody
Expand Down Expand Up @@ -328,4 +412,116 @@ public void editor(@RequestParam String oper,HttpServletRequest request,HttpServ
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/documents", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Document> getDocumentsTable(HttpServletRequest request,@RequestParam long id){
PageRequest pageRequest=null;
if(request.getParameter("page")!=null){
int rows=10;
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
rows = request.getParameter("rows") == null ? 10 : Integer.parseInt(request.getParameter("rows"));
if(request.getParameter("sidx")!=null && !request.getParameter("sidx").isEmpty()){
String direction=request.getParameter("sord");
pageRequest=new PageRequest(page,rows,"asc".equals(direction)? Sort.Direction.ASC: Sort.Direction.DESC,request.getParameter("sidx"));
} else {
pageRequest=new PageRequest(page,rows);
}
}catch (NumberFormatException ex){
//do nothing
}

}/**/
if(pageRequest!=null){
return new JGridRowsResponse<>(movementRepository.documents(id, pageRequest));
} else {
return new JGridRowsResponse<>(movementRepository.documents(id));
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void nomenclatureeditor(@RequestParam String oper,@RequestParam long moveid,HttpServletRequest request,HttpServletResponse response)throws IOException {
Movement movement=movementRepository.findOne(moveid);
if(movement==null){
response.sendError(404,"Movement not found!");
return;
}
switch (oper){
case "add": {
MovementElements element=new MovementElements();
Long nomenclid=Utils.getLongParameter("nomenclature_id",request);
if(nomenclid==null) {
response.sendError(404,"Nomenclature not found!");
return;
}
Nomenclature nom=nomenclatureRepository.findOne(nomenclid);
if(nom==null) {
response.sendError(404,"Nomenclature not found!");
return;
}
Long cnt=Utils.getLongParameter("count",request);
if(cnt==null){
response.sendError(400,"NO COUNT!");
return;
}
element.setNomenclature(nom);
element.setComments(request.getParameter("comments"));
element.setCount(cnt);
element.setMovement(movement);
//TO-DO: need units
//element.setUnits();
movementElementRepository.save(element);
movementRepository.save(movement);
}
break;
case "edit": {
Long id= Utils.getLongParameter("id",request);
MOVEMENT_TYPES types = getMovementType(request);
if (types == null || id==null) {
response.sendError(406, "UNKNOWN OPERATION");
return;
}
Movement fromDB = movementRepository.getOne(id);
if(fromDB!=null) {
if (!fromDB.isApproved()) {
if(updateMovement(fromDB,request,types,response)) {
movementRepository.save(fromDB);
response.setStatus(200);
}
} else {
response.sendError(403, "FORBIDDEN!");
}
} else {
response.sendError(404, "MOVEMENT WIDTH ID="+id+" mot found!");
}
}
break;
case "del":
Long id= Utils.getLongParameter("id", request);
if(id==null){
response.sendError(406,"UNKNOWN OPERATION");
return;
}
Movement fromDB = movementRepository.getOne(id);
if(fromDB!=null) {
if (!fromDB.isApproved()) {
movementRepository.delete(id);
response.setStatus(200);
} else {
response.sendError(403, "FORBIDDEN!");
}
} else {
response.sendError(404, "MOVEMENT WIDTH ID="+id+" mot found!");
}

break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,49 @@ public enum Units {
LITRES,
MILLILITRES,
METERS,
MILLIMETERS
MILLIMETERS;

public static Units fromInteger(int x) {
switch(x) {
case 0:
return KILOGRAMS;
case 1:
return GRAMS;
case 2:
return TONS;
case 3:
return COUNT;
case 4:
return LITRES;
case 5:
return MILLILITRES;
case 6:
return METERS;
case 7:
return MILLIMETERS;
}
return null;
}

public static Integer toInteger(Units x) {
switch(x) {
case KILOGRAMS:
return 0;
case GRAMS:
return 1;
case TONS:
return 2;
case COUNT:
return 3;
case LITRES:
return 4;
case MILLILITRES:
return 5;
case METERS:
return 6;
case MILLIMETERS:
return 7;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package ua.pp.fairwind.favorid.internalDB.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.MOVEMENT_TYPES;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Movement;

import java.util.List;


/**
* Created by Ñåðãåé on 07.10.2015.
*/

public interface MovementRepository extends JpaRepository<Movement,Long>{
Page<Movement> findByTypeMovement(MOVEMENT_TYPES typeMovement,Pageable pager);
List<Movement> findByTypeMovement(MOVEMENT_TYPES typeMovement);

@Query("select m.documents from Movement m where m.id=:movement")
Page<Document> documents(@Param(value = "movement")long id,Pageable pager);
@Query("select m.documents from Movement m where m.id=:movement")
List<Document> documents(@Param(value = "movement")long id);
}
14 changes: 13 additions & 1 deletion src/main/resources/label_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,16 @@ label.storehouseoperation.source=From Storehouse
label.storehouseoperation.destanation=TO Storehouse
label.storehouseoperation.counterparty=Counterparty
label.storehouseoperation.comments=Comments
label.storehouseoperation.type=Operation Type
label.storehouseoperation.type=Operation Type
label.storehouse_operation.nomenclature_list=List of nomenclature
label.nomenclature.template.code=Code
label.nomenclature.template.manufactured=Manufacturer
label.nomenclature=Nomenclature
label.nomenclature.manufactured=Manufacturer
label.ARRIVAL=ARRIVAL
label.SHIPMENT=SHIPMENT
label.MOVE=MOVE
label.COMBINED=COMBINED
label.UTILIZATION=UTILIZATION
label.DEFECTIVE=DEFECTIVE
label.storehouse.nomenclature_list=List of nomenclature in storehouse
14 changes: 13 additions & 1 deletion src/main/resources/label_ru_RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,16 @@ label.storehouseoperation.source=From Storehouse
label.storehouseoperation.destanation=TO Storehouse
label.storehouseoperation.counterparty=Counterparty
label.storehouseoperation.comments=Comments
label.storehouseoperation.type=Operation Type
label.storehouseoperation.type=Operation Type
label.storehouse_operation.nomenclature_list=List of nomenclature
label.nomenclature.template.code=Code
label.nomenclature.template.manufactured=Manufacturer
label.nomenclature=Nomenclature
label.nomenclature.manufactured=Manufacturer
label.ARRIVAL=ARRIVAL
label.SHIPMENT=SHIPMENT
label.MOVE=MOVE
label.COMBINED=COMBINED
label.UTILIZATION=UTILIZATION
label.DEFECTIVE=DEFECTIVE
label.storehouse.nomenclature_list=List of nomenclature in storehouse
14 changes: 13 additions & 1 deletion src/main/resources/label_ua_UA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,16 @@ label.storehouseoperation.source=From Storehouse
label.storehouseoperation.destanation=TO Storehouse
label.storehouseoperation.counterparty=Counterparty
label.storehouseoperation.comments=Comments
label.storehouseoperation.type=Operation Type
label.storehouseoperation.type=Operation Type
label.storehouse_operation.nomenclature_list=List of nomenclature
label.nomenclature.template.code=Code
label.nomenclature.template.manufactured=Manufacturer
label.nomenclature=Nomenclature
label.nomenclature.manufactured=Manufacturer
label.ARRIVAL=ARRIVAL
label.SHIPMENT=SHIPMENT
label.MOVE=MOVE
label.COMBINED=COMBINED
label.UTILIZATION=UTILIZATION
label.DEFECTIVE=DEFECTIVE
label.storehouse.nomenclature_list=List of nomenclature in storehouse
Loading

0 comments on commit 2ee6a17

Please sign in to comment.