add store pop up window in po status pdf generating screen
parent
b255071c2e
commit
c80cca6811
|
@ -47,7 +47,10 @@ public class POStatusController {
|
|||
}
|
||||
|
||||
@GetMapping(value = "/generate-po-pdf", produces = MediaType.APPLICATION_PDF_VALUE)
|
||||
public ResponseEntity<InputStreamResource> sendPoAndReturnPdf(@ModelAttribute POsDetails pOsDetails, Model model) throws Exception{
|
||||
return purchaseOrderService.generatePOPdf(pOsDetails, model);
|
||||
public ResponseEntity<InputStreamResource> sendPoAndReturnPdf(@ModelAttribute POsDetails pOsDetails,
|
||||
@RequestParam(required = false, defaultValue = "true") boolean includeJobCard,
|
||||
@RequestParam(required = false, defaultValue = "true") boolean includeStoreDetails,
|
||||
Model model) throws Exception{
|
||||
return purchaseOrderService.generatePOPdf(pOsDetails, model, includeJobCard, includeStoreDetails);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.utopiaindustries.model.ctp.JobCard;
|
|||
import com.utopiaindustries.model.ctp.PurchaseOrderCTP;
|
||||
import com.utopiaindustries.service.PurchaseOrderCTPService;
|
||||
import com.utopiaindustries.util.StringUtils;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -85,6 +86,11 @@ public class PurchaseOrderCTPController {
|
|||
return "redirect:/purchase-order";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping( "/store-items/{id}" )
|
||||
public String getPOStoreItems( @PathVariable("id") long poId,
|
||||
Model model ){
|
||||
model.addAttribute("storeItems", purchaseOrderCTPService.getStoreItemsByPoId( poId ));
|
||||
return "/reporting/po-store-items-table";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.utopiaindustries.dao.ctp;
|
||||
|
||||
import com.utopiaindustries.model.ctp.PackagingItems;
|
||||
import com.utopiaindustries.model.ctp.StoreItem;
|
||||
import com.utopiaindustries.util.KeyHolderFunctions;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
@ -10,7 +9,9 @@ import org.springframework.jdbc.support.KeyHolder;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public class StoreItemDao {
|
||||
|
@ -38,6 +39,7 @@ public class StoreItemDao {
|
|||
"finish_item_id = VALUES(finish_item_id), account_id = VALUES(account_id), bundle_id = VALUES(bundle_id), reject_reason = VALUES(reject_reason)",
|
||||
TABLE_NAME
|
||||
);
|
||||
String SELECT_BY_JOB_CARD_GROUP_REJECT_REASON = String.format("SELECT reject_reason, COUNT(*) AS total FROM %s WHERE job_card_id IN (:job_card_id) GROUP BY reject_reason", TABLE_NAME);
|
||||
|
||||
private static final String SELECT_BY_DATE_AND_IDs = String.format("SELECT COUNT(*) FROM %s WHERE (:start_date IS NULL OR created_at >= :start_date) AND created_at <= :end_date AND id IN (:ids)", TABLE_NAME);
|
||||
|
||||
|
@ -110,4 +112,20 @@ public class StoreItemDao {
|
|||
Long count = namedParameterJdbcTemplate.queryForObject(SELECT_BY_DATE_AND_IDs, params, Long.class);
|
||||
return count != null ? count : 0;
|
||||
}
|
||||
|
||||
public Map<String, Integer> totalCountByJobCardIdsAndGroupByRejectReason(List<Long> jobCardIds) {
|
||||
MapSqlParameterSource params = new MapSqlParameterSource();
|
||||
params.addValue("job_card_id", jobCardIds);
|
||||
|
||||
List<Map<String, Object>> rows = namedParameterJdbcTemplate.queryForList(SELECT_BY_JOB_CARD_GROUP_REJECT_REASON, params);
|
||||
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String reason = (String) row.get("reject_reason");
|
||||
Integer total = ((Number) row.get("total")).intValue();
|
||||
result.put(reason, total);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.utopiaindustries.service;
|
||||
|
||||
import com.utopiaindustries.dao.ctp.JobCardDAO;
|
||||
import com.utopiaindustries.dao.ctp.PurchaseOrderCTPDao;
|
||||
import com.utopiaindustries.dao.ctp.StoreItemDao;
|
||||
import com.utopiaindustries.model.ctp.*;
|
||||
import com.utopiaindustries.model.uind.PurchaseOrder;
|
||||
import com.utopiaindustries.querybuilder.ctp.JobCardQueryBuilder;
|
||||
|
@ -14,15 +16,22 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class PurchaseOrderCTPService {
|
||||
|
||||
private final PurchaseOrderCTPDao purchaseOrderCTPDao;
|
||||
private final JobCardDAO jobCardDAO;
|
||||
private final StoreItemDao storeItemDao;
|
||||
|
||||
public PurchaseOrderCTPService(PurchaseOrderCTPDao purchaseOrderCTPDao) {
|
||||
public PurchaseOrderCTPService(PurchaseOrderCTPDao purchaseOrderCTPDao, JobCardDAO jobCardDAO, StoreItemDao storeItemDao) {
|
||||
this.purchaseOrderCTPDao = purchaseOrderCTPDao;
|
||||
this.jobCardDAO = jobCardDAO;
|
||||
this.storeItemDao = storeItemDao;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -77,4 +86,17 @@ public class PurchaseOrderCTPService {
|
|||
return purchaseOrderCTPDao.findByTerm( term );
|
||||
}
|
||||
|
||||
public Map<String,Integer> getStoreItemsByPoId(Long poId){
|
||||
Map<String,Integer> totalItems = new HashMap<>();
|
||||
List<JobCard> jobCards = jobCardDAO.findByPoId(poId);
|
||||
List<Long> jobCardIds = jobCards.stream()
|
||||
.map(JobCard::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!jobCardIds.isEmpty()){
|
||||
return storeItemDao.totalCountByJobCardIdsAndGroupByRejectReason(jobCardIds);
|
||||
}else {
|
||||
return totalItems;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.utopiaindustries.service;
|
||||
|
||||
import com.utopiaindustries.dao.ctp.StoreItemDao;
|
||||
import com.utopiaindustries.dao.uind.PurchaseOrderDAO;
|
||||
import com.utopiaindustries.model.ctp.JobCardItem;
|
||||
import com.utopiaindustries.model.ctp.POsDetails;
|
||||
|
@ -19,13 +20,13 @@ import java.util.stream.Collectors;
|
|||
public class PurchaseOrderService {
|
||||
|
||||
private final PurchaseOrderDAO purchaseOrderDAO;
|
||||
private final ReportingService reportingService;
|
||||
private final PurchaseOrderCTPService purchaseOrderCTPService;
|
||||
private final HTMLBuilder htmlBuilder;
|
||||
private PDFResponseEntityInputStreamResource pdfGenerator;
|
||||
|
||||
public PurchaseOrderService(PurchaseOrderDAO purchaseOrderDAO, ReportingService reportingService, HTMLBuilder htmlBuilder, PDFResponseEntityInputStreamResource pdfGenerator) {
|
||||
public PurchaseOrderService(PurchaseOrderDAO purchaseOrderDAO, PurchaseOrderCTPService purchaseOrderCTPService, HTMLBuilder htmlBuilder, PDFResponseEntityInputStreamResource pdfGenerator) {
|
||||
this.purchaseOrderDAO = purchaseOrderDAO;
|
||||
this.reportingService = reportingService;
|
||||
this.purchaseOrderCTPService = purchaseOrderCTPService;
|
||||
this.htmlBuilder = htmlBuilder;
|
||||
this.pdfGenerator = pdfGenerator;
|
||||
}
|
||||
|
@ -37,9 +38,15 @@ public class PurchaseOrderService {
|
|||
/**
|
||||
* Print Job card *
|
||||
* **/
|
||||
public ResponseEntity<InputStreamResource> generatePOPdf(POsDetails pOsDetails, Model model ) throws Exception {
|
||||
public ResponseEntity<InputStreamResource> generatePOPdf(POsDetails pOsDetails, Model model, boolean jobCardDetail, boolean storeDetail ) throws Exception {
|
||||
model.addAttribute("poDetail", pOsDetails);
|
||||
model.addAttribute( "baseUrl", URLUtils.getCurrentBaseUrl() );
|
||||
if (storeDetail){
|
||||
model.addAttribute("showStore", true);
|
||||
model.addAttribute("store", purchaseOrderCTPService.getStoreItemsByPoId(pOsDetails.getPoId()));
|
||||
}else {
|
||||
model.addAttribute("showStore", false);
|
||||
}
|
||||
String htmlStr = htmlBuilder.buildHTML( "po-status-pdf", model );
|
||||
// return pdf
|
||||
return pdfGenerator.generatePdf( htmlStr, "Po-status", "inline" );
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="bordered" style="width: 100%; margin-top: 20px; border-collapse: collapse; ">
|
||||
<h5 class="no-margin-top no-margin-bottom" style="margin-top: 20px;">PO Details</h5>
|
||||
<table class="bordered" style="width: 100%; margin-top: 10px; border-collapse: collapse; ">
|
||||
<h5 class="no-margin-top no-margin-bottom" style="margin-top: 10px;">PO Details</h5>
|
||||
<thead >
|
||||
<tr class="tr-header">
|
||||
<td>Cutting</td>
|
||||
|
@ -88,6 +88,21 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="bordered" style="width: 50%; margin-top: 20px;" th:if="${showStore}">
|
||||
<tr class="tr-header">
|
||||
<td colspan="2" th:text="'Store Items'"></td>
|
||||
</tr>
|
||||
<tbody>
|
||||
<tr th:each="heading : ${store.keySet()}"
|
||||
th:if="${store != null and not store.isEmpty()}">
|
||||
<td style="width: 40%; border: 1px solid black;"><i th:text="${heading}"></i></td>
|
||||
<td style="width: 60%; border: 1px solid black;">
|
||||
<a class="text-reset" target="_blank" th:text="${store.get(heading)}"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -27,6 +27,7 @@
|
|||
<th>Finishing Items Balance</th>
|
||||
<th>A Grade Items</th>
|
||||
<th>Reject Items In Store</th>
|
||||
<th></th>
|
||||
<th>PO Status</th>
|
||||
<th>Generate PDF</th>
|
||||
</tr>
|
||||
|
@ -49,6 +50,11 @@
|
|||
<td th:text="${poDetail.remainingFinishing}"></td>
|
||||
<td th:text="${poDetail.totalAGradeItem}"></td>
|
||||
<td th:text="${poDetail.totalBGradeItem}"></td>
|
||||
<td data-show-dropdown-transactions
|
||||
th:data-po-id="${poDetail.poId}"
|
||||
title="Store-Items">
|
||||
<span data-dropdown-icon-transactions class="bi bi-caret-right-fill"></span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge font-sm badge-danger" th:if="*{poDetail.poStatus}" th:text="'CLOSE'"></span>
|
||||
<span class="badge font-sm badge-ACTIVE" th:if="*{!poDetail.poStatus}" th:text="'OPEN'"></span>
|
||||
|
@ -74,12 +80,10 @@
|
|||
<input type="hidden" name="totalBGradeItem" th:value="${poDetail.totalBGradeItem}"/>
|
||||
<input type="hidden" name="poStatus" th:value="${poDetail.poStatus}"/>
|
||||
|
||||
<!-- Link styled as a button -->
|
||||
<a href="javascript:void(0);"
|
||||
th:onclick="'document.getElementById(\'form-' + ${poDetail.poId} + '\').submit()'"
|
||||
th:onclick="'showPdfOptions(' + ${poDetail.poId} + ')'"
|
||||
class="btn btn-sm btn-secondary"
|
||||
title="Generate PDF"
|
||||
target="_blank">
|
||||
title="Generate PDF">
|
||||
<i class="bi bi-filetype-pdf"></i>
|
||||
</a>
|
||||
</form>
|
||||
|
@ -89,8 +93,118 @@
|
|||
</table>
|
||||
<h4 th:if="${#lists.size(allPOs) == 0 }">No PO found.</h4>
|
||||
</div>
|
||||
<div class="modal fade" id="pdfOptionsModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Select PDF Options</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- <div class="form-check">-->
|
||||
<!-- <input class="form-check-input" type="checkbox" id="includeJobCard" name="includeJobCard" value="true" checked>-->
|
||||
<!-- <label class="form-check-label" for="includeJobCard">-->
|
||||
<!-- Include Job Card Details-->
|
||||
<!-- </label>-->
|
||||
<!-- </div>-->
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="includeStoreDetails" name="includeStoreDetails" value="true" checked>
|
||||
<label class="form-check-label" for="includeStoreDetails">
|
||||
Include Store Details
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onclick="submitPdfForm()">Generate PDF</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div th:replace="_fragments :: page-footer-scripts"></div>
|
||||
<script>
|
||||
// PDF Generation Functions
|
||||
let currentPoIdForPdf = null;
|
||||
|
||||
function showPdfOptions(poId) {
|
||||
currentPoIdForPdf = poId;
|
||||
$('#pdfOptionsModal').modal('show');
|
||||
}
|
||||
|
||||
function submitPdfForm() {
|
||||
if (!currentPoIdForPdf) return;
|
||||
|
||||
const form = document.getElementById('form-' + currentPoIdForPdf);
|
||||
|
||||
// Remove existing options if they exist
|
||||
const existingJobCard = form.querySelector('input[name="includeJobCard"]');
|
||||
const existingStoreDetails = form.querySelector('input[name="includeStoreDetails"]');
|
||||
|
||||
if (existingJobCard) form.removeChild(existingJobCard);
|
||||
if (existingStoreDetails) form.removeChild(existingStoreDetails);
|
||||
|
||||
// Add params to show store details in pdf
|
||||
const includeStoreDetails = document.createElement('input');
|
||||
includeStoreDetails.type = 'hidden';
|
||||
includeStoreDetails.name = 'includeStoreDetails';
|
||||
includeStoreDetails.value = document.getElementById('includeStoreDetails').checked;
|
||||
form.appendChild(includeStoreDetails);
|
||||
|
||||
form.submit();
|
||||
$('#pdfOptionsModal').modal('hide');
|
||||
}
|
||||
|
||||
// DataTable and Dropdown Initialization
|
||||
$(document).ready(function() {
|
||||
const $body = $('body');
|
||||
|
||||
// Initialize DataTables for each individual table
|
||||
$('table[data-account-table]').each(function () {
|
||||
$(this).DataTable({
|
||||
paging: false,
|
||||
pageLength: 100,
|
||||
searching: false,
|
||||
lengthChange: false,
|
||||
processing: false,
|
||||
dom: `
|
||||
<'row'<'col-sm-3'B><'col-sm-4'f>>
|
||||
<'row'<'col-sm-6't>>
|
||||
<'row'<'col-sm-3'i><'col-sm-4'p>>`,
|
||||
buttons: [{
|
||||
extend: 'excel',
|
||||
text: '',
|
||||
className: 'bi bi-file-earmark-spreadsheet btn-sm d-none'
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
// Dropdown transactions toggle
|
||||
$body.on('click', '[data-show-dropdown-transactions]', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const $this = $(this);
|
||||
const $tr = $this.closest('tr');
|
||||
const $table = $this.closest('table');
|
||||
const dataTable = $table.DataTable();
|
||||
const $row = dataTable.row($tr);
|
||||
const $spanDropdown = $this.find('[data-dropdown-icon-transactions]');
|
||||
const poId = $this.data('po-id');
|
||||
$spanDropdown.toggleClass('bi-caret-right-fill bi-caret-down-fill');
|
||||
|
||||
if ($row.child.isShown()) {
|
||||
$row.child.hide();
|
||||
} else {
|
||||
$row.child(`<span class="spinner-border text-center spinner-border-md" role="status"></span>`).show();
|
||||
$.ajax({
|
||||
url: `/ctp/purchase-order/store-items/${poId}`,
|
||||
success: function (data) {
|
||||
$row.child(data).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -3,43 +3,24 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<style>
|
||||
/* Custom CSS for full height and center alignment of span */
|
||||
.vertical-divider {
|
||||
display: flex;
|
||||
justify-content: center; /* Center horizontally */
|
||||
align-items: center; /* Center vertically */
|
||||
}
|
||||
|
||||
.vertical-divider span {
|
||||
display: inline-block;
|
||||
width: 1px;
|
||||
background-color: #dee2e6;
|
||||
height: 100%; /* Take full height of the parent div */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table th:if="${#lists.size(transactions) != 0 && #lists != null }" class="table table-bordered font-sm mb-4" data-account-tables>
|
||||
<div class="col-sm-8">
|
||||
<table th:if="${#lists != null && #lists.size(storeItems.keySet()) != 0 }" class="table table-bordered font-sm mb-4" data-account-tables>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Cut To Pack</th>
|
||||
<th>Knitting</th>
|
||||
<th>Dying</th>
|
||||
<th th:each="heading : ${storeItems.keySet()}" th:text="${heading}"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="transaction : ${transactions}" th:object="${transaction}">
|
||||
<td th:text="*{id}"></td>
|
||||
<td th:text="*{itemId}"></td>
|
||||
<td th:text="*{sku}"></td>
|
||||
<tr>
|
||||
<td th:each="heading : ${storeItems.keySet()}" th:text="${storeItems.get(heading)}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h5 th:if="${#lists.size(transactions) == 0}" class="mt-2">No Inventory Transactions found.</h5>
|
||||
<h5 th:if="${#lists.size(storeItems.keySet()) == 0}" class="mt-2">No Inventory Transactions found.</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -53,43 +34,21 @@
|
|||
// Prevent reinitializing if already done
|
||||
if (!$.fn.DataTable.isDataTable($table)) {
|
||||
$table.DataTable({
|
||||
pageLength: 5,
|
||||
searching: true,
|
||||
paging: false,
|
||||
searching: false,
|
||||
lengthChange: false,
|
||||
processing: false,
|
||||
dom: `
|
||||
<'row'<'col-sm-5'B><'col-sm-7'f>>
|
||||
<'row'<'col-sm-12't>>
|
||||
<'row'<'col-sm-5'i><'col-sm-7'p>>`,
|
||||
info: false,
|
||||
dom: 't',
|
||||
buttons: [{
|
||||
extend: 'excel',
|
||||
text: '',
|
||||
className: 'bi bi-file-earmark-spreadsheet btn-sm d-none' // Keep it hidden
|
||||
className: 'bi bi-file-earmark-spreadsheet btn-sm d-none'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
(async function () {
|
||||
const $selectAllCheckBox = $('[data-checkbox-all]');
|
||||
|
||||
$selectAllCheckBox.change(function () {
|
||||
if ($selectAllCheckBox.prop('checked')) {
|
||||
// When parent checkbox is checked, check all child checkboxes
|
||||
$('[name="parent-doc-type-ids"]').each(function () {
|
||||
let $this = $(this);
|
||||
$this.prop('checked', true);
|
||||
});
|
||||
} else {
|
||||
// When parent checkbox is unchecked, uncheck all child checkboxes
|
||||
$('[name="parent-doc-type-ids"]').each(function () {
|
||||
let $this = $(this);
|
||||
$this.prop('checked', false);
|
||||
});
|
||||
}
|
||||
});
|
||||
})(jQuery)
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue