Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.rms.domain.investor;

import com.rms.domain.common.JPAEntity;
import com.rms.domain.core.Product;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "Profit_Details")
public class ProfitDetails extends JPAEntity {
@Column(name = "Bill_Price")
private double billPrice;

@Column(name = "Product_Price")
private double productPrice;

@Column(name = "count")
private int count;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id")
private Product product;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.rms.repository;

import com.rms.domain.investor.ProfitDetails;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ProfitDetailsRepository extends JpaRepository<ProfitDetails, Integer> {

@Query("select p from ProfitDetails p where p.product.id = :productId")
Optional<ProfitDetails> findProfitDetailsByProductId(@Param("productId") Integer productId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.rms.rest.controller;

import com.rms.rest.dto.ProfitDetailsDto;
import com.rms.rest.handler.ProfitDetailsHandler;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/profitDetails")
@AllArgsConstructor
@Tag(name = "ProfitDetails", description = "Rest Api For ProfitDetails")
public class ProfitDetailsController {
private ProfitDetailsHandler profitDetailsHandler;

@GetMapping
@Operation(summary = "Get All", description = "this api for get all profit Details")
public ResponseEntity<?> getAll(@RequestParam(value = "page", defaultValue = "0") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size) {
return profitDetailsHandler.getAll(page, size);
}

@GetMapping("/{id}")
@Operation(summary = "Get By Id", description = "this api for get profit Details by id")
public ResponseEntity<?> getById(@PathVariable("id") Integer id) {
return profitDetailsHandler.getById(id);
}


@PutMapping("/{id}")
@Operation(summary = "Update", description = "this api for update profit Details")
public ResponseEntity<?> updateProfit(@RequestBody ProfitDetailsDto profitDetailsdto, @PathVariable Integer id) {
return profitDetailsHandler.update(profitDetailsdto, id);
}

@DeleteMapping("/{id}")
@Operation(summary = "delete profit By Id")
public ResponseEntity<?> delete(@PathVariable Integer id) {
return profitDetailsHandler.delete(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rms.rest.dto;

import com.rms.rest.dto.common.GenericDto;
import lombok.Data;


@Data
public class ProfitDetailsDto extends GenericDto {
private double billPrice;
private double productPrice;
private int count;
private ProductDto product;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.rms.rest.handler;

import com.rms.domain.core.Product;
import com.rms.domain.purchase.Bill;
import com.rms.domain.purchase.BillDetails;
Expand All @@ -18,6 +19,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
Expand All @@ -29,6 +31,8 @@ public class BillDetailsHandler {
private BillDetailsMapper billDetailsMapper;
private PaginationMapper paginationMapper;

private ProfitDetailsHandler profitDetailsHandler;

public ResponseEntity<?> getAll(Integer page, Integer size) {
Page<BillDetails> billDetaills = billDetailsService.getAll(page, size);
List<BillDetailsDto> dtos = billDetailsMapper.toDto(billDetaills.getContent());
Expand All @@ -38,19 +42,19 @@ public ResponseEntity<?> getAll(Integer page, Integer size) {
return ResponseEntity.ok(paginatedResultDto);
}


public ResponseEntity <?>save(int billId,List<BillDetailsDto> billDetailsDtoList)
{
for (BillDetailsDto billDetailsDto :billDetailsDtoList ){

public ResponseEntity<?> save(int billId, List<BillDetailsDto> billDetailsDtoList) {
for (BillDetailsDto billDetailsDto : billDetailsDtoList) {
Product product = productService.getById(billDetailsDto.getProduct().getId())
.orElseThrow(() -> new ResourceNotFoundException(Product.class.getSimpleName(),billDetailsDto.getProduct().getId()));
product.setQuantity(billDetailsDto.getQuantity()+product.getQuantity());
.orElseThrow(() -> new ResourceNotFoundException(Product.class.getSimpleName(), billDetailsDto.getProduct().getId()));
product.setQuantity(billDetailsDto.getQuantity() + product.getQuantity());
}
Bill bill = billService.getById(billId)
.orElseThrow(()->new ResourceNotFoundException(Bill.class.getSimpleName(),billId));
List<BillDetails> billDetails=billDetailsMapper.toEntity(billDetailsDtoList);
billDetailsService.save(bill,billDetails);
List<BillDetailsDto> dtos =billDetailsMapper.toDto(billDetails);
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), billId));
List<BillDetails> billDetails = billDetailsMapper.toEntity(billDetailsDtoList);
billDetailsService.save(bill, billDetails);
profitDetailsHandler.save(billDetails);
List<BillDetailsDto> dtos = billDetailsMapper.toDto(billDetails);
return ResponseEntity.ok(dtos);
}

Expand All @@ -75,29 +79,27 @@ public ResponseEntity<?> update(BillDetailsDto billDetailsDto, Integer id) {
billDetails.setProduct(product);
}


billDetailsMapper.updateEntityFromDto(billDetailsDto, billDetails);
billDetailsService.update(billDetails);
BillDetailsDto dto = billDetailsMapper.toDto(billDetails);
return ResponseEntity.ok(dto);




}



public ResponseEntity<?> findAllBillDetailsByBillId(Integer id) {
billService.getById(id).orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), id));
List<BillDetails> billDetails = billDetailsService.getAllBillDetailsByBillId(id);
List<BillDetailsDto> dtos = billDetailsMapper.toDto(billDetails);
return ResponseEntity.ok(dtos);
}


public ResponseEntity<?> delete(Integer id) {
BillDetails billDetails = billDetailsService.getById(id).orElseThrow(() -> new ResourceNotFoundException(BillDetails.class.getSimpleName(), id));

try {
billDetailsService.delete(billDetails);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.rms.rest.handler;

import com.rms.domain.purchase.Bill;
import com.rms.domain.purchase.BillDetails;
import com.rms.domain.purchase.Supplier;
Expand All @@ -16,6 +17,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,46 +35,42 @@ public class BillHandler {

private BillDetailsService billDetailsService;

public ResponseEntity<?>getById(Integer id)
{
Bill bill = billService.getById(id)
.orElseThrow(()-> new ResourceNotFoundException(Bill.class.getSimpleName(),id));
BillDto billDto=billMapper.toDto(bill);
public ResponseEntity<?> getById(Integer id) {
Bill bill = billService.getById(id)
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), id));
BillDto billDto = billMapper.toDto(bill);
return ResponseEntity.ok(billDto);
}
public ResponseEntity<?>getAll(Integer page , Integer size)
{
Page<Bill> bills =billService.getAll(page,size);
List<BillDto>billDtos = billMapper.toDto(bills.getContent());

public ResponseEntity<?> getAll(Integer page, Integer size) {
Page<Bill> bills = billService.getAll(page, size);
List<BillDto> billDtos = billMapper.toDto(bills.getContent());
PaginatedResultDto<BillDto> paginatedResultDto = new PaginatedResultDto<>();
paginatedResultDto.setData(billDtos);
paginatedResultDto.setPagination(paginationMapper.toDto(bills));
return ResponseEntity.ok(paginatedResultDto);
}
public ResponseEntity<?>save(BillDto billDto)
{
Supplier supplier =supplierService.getById(billDto.getSupplierDto().getId())
.orElseThrow(() -> new ResourceNotFoundException(Supplier.class.getSimpleName(),billDto.getId()));
if(billDto.getBillDetailsDtoList()==null || billDto.getBillDetailsDtoList().size()==0)
{
throw new BusinessValidationException(Bill.class.getName()," requested id",billDto.getId().toString(),ErrorCodes.BUSINESS_VALIDATION.getCode());

public ResponseEntity<?> save(BillDto billDto) {
Supplier supplier = supplierService.getById(billDto.getSupplierDto().getId())
.orElseThrow(() -> new ResourceNotFoundException(Supplier.class.getSimpleName(), billDto.getId()));
if (billDto.getBillDetailsDtoList() == null || billDto.getBillDetailsDtoList().size() == 0) {
throw new BusinessValidationException(Bill.class.getName(), " requested id", billDto.getId().toString(), ErrorCodes.BUSINESS_VALIDATION.getCode());
}
Bill bill = billMapper.toEntity(billDto);
bill.setSupplier(supplier);
bill.setDate(LocalDate.now());
if(billService.findBillNumber(bill.getBillNo()).isPresent())
{
throw new ResourceAlreadyExistsException(Bill.class.getSimpleName(),"bill Number",bill.getBillNo(),ErrorCodes.RELATED_RESOURCE.getCode());
if (billService.findBillNumber(bill.getBillNo()).isPresent()) {
throw new ResourceAlreadyExistsException(Bill.class.getSimpleName(), "bill Number", bill.getBillNo(), ErrorCodes.RELATED_RESOURCE.getCode());

}

billService.save(bill);
BillDto dto = billMapper.toDto(bill);
if(billDto.getBillDetailsDtoList()!=null)
{
billDetailsHandler.save(bill.getId(),billDto.getBillDetailsDtoList());
}
return ResponseEntity.ok(dto);
billService.save(bill);
BillDto dto = billMapper.toDto(bill);
if (billDto.getBillDetailsDtoList() != null) {
billDetailsHandler.save(bill.getId(), billDto.getBillDetailsDtoList());
}
return ResponseEntity.ok(dto);

}

Expand All @@ -81,16 +79,15 @@ public ResponseEntity<?> update(BillDto billDto, Integer id) {

Bill bill = billService.getById(id)
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), id));
if(billDto.getSupplierDto()!=null) {
if (billDto.getSupplierDto() != null) {
Supplier supplier = supplierService.getById(billDto.getSupplierDto().getId())
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), billDto.getSupplierDto().getId()));
bill.setSupplier(supplier);
}

Optional<Bill>billNumExist=billService.findBillNumber(billDto.getBillNo());
if(billNumExist.isPresent() && !billNumExist.get().getId().equals(id))
{
throw new ResourceAlreadyExistsException(Bill.class.getSimpleName(),"bill Number",bill.getBillNo(),ErrorCodes.DUPLICATE_RESOURCE.getCode());
Optional<Bill> billNumExist = billService.findBillNumber(billDto.getBillNo());
if (billNumExist.isPresent() && !billNumExist.get().getId().equals(id)) {
throw new ResourceAlreadyExistsException(Bill.class.getSimpleName(), "bill Number", bill.getBillNo(), ErrorCodes.DUPLICATE_RESOURCE.getCode());

}

Expand All @@ -102,10 +99,10 @@ public ResponseEntity<?> update(BillDto billDto, Integer id) {
BillDto dto = billMapper.toDto(bill);
return ResponseEntity.ok(dto);
}

public ResponseEntity<?> delete(Integer id) {
Bill bill= billService.getById(id)
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(),id));
Bill bill = billService.getById(id)
.orElseThrow(() -> new ResourceNotFoundException(Bill.class.getSimpleName(), id));
try {
billService.delete(bill);
} catch (Exception exception) {
Expand All @@ -115,7 +112,4 @@ public ResponseEntity<?> delete(Integer id) {
}





}
Loading