final String[] args);
public void printProductionBalance(final ViewDefinitionState viewDefinitionState, final ComponentState state,
<<<<<<< HEAD
final String[] args) {
reportService.printGeneratedReport(viewDefinitionState, state, new String[] { args[0],
ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_BALANCE, args[1] });
}
private void fillReportValues(final Entity productionBalance) {
productionBalance.setField(GENERATED, true);
productionBalance.setField(DATE,
new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale()).format(new Date()));
productionBalance.setField(WORKER, securityService.getCurrentUserName());
}
private void fillFieldsAndGrids(final Entity productionBalance) {
Entity order = productionBalance.getBelongsToField(ORDER);
if ((order == null) || checkIfTypeOfProductionRecordingIsBasic(order)) {
return;
}
if (order.getBooleanField(PARAM_REGISTER_IN_PRODUCTS)) {
fillBalanceOperationProductInComponents(productionBalance, order);
}
if (order.getBooleanField(PARAM_REGISTER_OUT_PRODUCTS)) {
fillBalanceOperationProductOutComponents(productionBalance, order);
}
if (HOURLY.getStringValue().equals(productionBalance.getStringField(CALCULATE_OPERATION_COST_MODE))
&& order.getBooleanField(PARAM_REGISTER_PRODUCTION_TIME)) {
if (FOR_EACH.getStringValue().equals(order.getStringField(TYPE_OF_PRODUCTION_RECORDING))) {
fillTimeValues(productionBalance, order);
fillOperationTimeComponents(productionBalance, order);
} else if (CUMULATED.getStringValue().equals(order.getStringField(TYPE_OF_PRODUCTION_RECORDING))) {
fillTimeValues(productionBalance, order);
}
} else if (PIECEWORK.getStringValue().equals(productionBalance.getStringField(CALCULATE_OPERATION_COST_MODE))
&& order.getBooleanField(PARAM_REGISTER_PIECEWORK)) {
fillOperationPieceworkComponents(productionBalance, order);
}
}
private void fillBalanceOperationProductInComponents(final Entity productionBalance, final Entity order) {
if ((productionBalance == null) || (order == null)) {
return;
}
List balanceOperationProductInComponents = Lists.newArrayList();
List productionRecords = getProductionRecordsFromDB(order);
for (Entity productionRecord : productionRecords) {
List recordOperationProductInComponents = productionRecord
.getHasManyField(RECORD_OPERATION_PRODUCT_IN_COMPONENTS);
if (recordOperationProductInComponents != null) {
for (Entity recordOperationProductInComponent : recordOperationProductInComponents) {
Entity balanceOperationProductInComponent = dataDefinitionService.get(
ProductionCountingConstants.PLUGIN_IDENTIFIER, MODEL_BALANCE_OPERATION_PRODUCT_IN_COMPONENT).create();
balanceOperationProductInComponent.setField(MODEL_PRODUCTION_RECORD,
recordOperationProductInComponent.getField(MODEL_PRODUCTION_RECORD));
balanceOperationProductInComponent.setField(MODEL_PRODUCT,
recordOperationProductInComponent.getField(PRODUCT));
balanceOperationProductInComponent.setField(L_USED_QUANTITY,
recordOperationProductInComponent.getField(USED_QUANTITY));
balanceOperationProductInComponent.setField(L_PLANNED_QUANTITY,
recordOperationProductInComponent.getField(PLANNED_QUANTITY));
balanceOperationProductInComponent.setField(L_BALANCE, recordOperationProductInComponent.getField(BALANCE));
balanceOperationProductInComponents.add(balanceOperationProductInComponent);
}
}
}
if (!balanceOperationProductInComponents.isEmpty()) {
Collections.sort(balanceOperationProductInComponents, new EntityProductInOutComparator());
productionBalance.setField(BALANCE_OPERATION_PRODUCT_IN_COMPONENTS,
operationPieceworkComponent.setField("cycles", "");
productionBalanceReportDataService.groupProductInOutComponentsByProduct(balanceOperationProductInComponents));
productionBalance.getDataDefinition().save(productionBalance);
}
}
private void fillBalanceOperationProductOutComponents(final Entity productionBalance, final Entity order) {
if ((productionBalance == null) || (order == null)) {
return;
}
List balanceOperationProductOutComponents = Lists.newArrayList();
List productionRecordList = getProductionRecordsFromDB(order);
for (Entity productionRecord : productionRecordList) {
List recordOperationProductOutComponents = productionRecord
.getHasManyField(RECORD_OPERATION_PRODUCT_OUT_COMPONENTS);
if (recordOperationProductOutComponents != null) {
for (Entity recordOperationProductOutComponent : recordOperationProductOutComponents) {
Entity balanceOperationProductOutComponent = dataDefinitionService.get(
ProductionCountingConstants.PLUGIN_IDENTIFIER,
ProductionCountingConstants.MODEL_BALANCE_OPERATION_PRODUCT_OUT_COMPONENT).create();
balanceOperationProductOutComponent.setField(MODEL_PRODUCTION_RECORD,
recordOperationProductOutComponent.getField(MODEL_PRODUCTION_RECORD));
balanceOperationProductOutComponent.setField(MODEL_PRODUCT,
recordOperationProductOutComponent.getField(PRODUCT));
balanceOperationProductOutComponent.setField(L_USED_QUANTITY,
recordOperationProductOutComponent.getField(USED_QUANTITY));
balanceOperationProductOutComponent.setField(L_PLANNED_QUANTITY,
recordOperationProductOutComponent.getField(PLANNED_QUANTITY));
balanceOperationProductOutComponent.setField(L_BALANCE, recordOperationProductOutComponent.getField(BALANCE));
balanceOperationProductOutComponents.add(balanceOperationProductOutComponent);
}
}
}
if (!balanceOperationProductOutComponents.isEmpty()) {
Collections.sort(balanceOperationProductOutComponents, new EntityProductInOutComparator());
productionBalance
.setField(BALANCE_OPERATION_PRODUCT_OUT_COMPONENTS, productionBalanceReportDataService
.groupProductInOutComponentsByProduct(balanceOperationProductOutComponents));
productionBalance.getDataDefinition().save(productionBalance);
}
}
private void fillTimeValues(final Entity productionBalance, final Entity order) {
if ((productionBalance == null) || (order == null)) {
return;
}
BigDecimal plannedMachineTime = BigDecimal.ZERO;
BigDecimal machineTime = BigDecimal.ZERO;
BigDecimal laborTime = BigDecimal.ZERO;
BigDecimal plannedLaborTime = BigDecimal.ZERO;
List productionRecordsList = getProductionRecordsFromDB(order);
if (!productionRecordsList.isEmpty()) {
for (Entity productionRecord : productionRecordsList) {
plannedMachineTime = plannedMachineTime
.add(new BigDecimal((Integer) productionRecord.getField(PLANNED_MACHINE_TIME)),
numberService.getMathContext());
plannedLaborTime = plannedLaborTime.add(new BigDecimal((Integer) productionRecord.getField(PLANNED_LABOR_TIME)),
numberService.getMathContext());
machineTime = machineTime.add(new BigDecimal((Integer) productionRecord.getField(MACHINE_TIME)),
numberService.getMathContext());
laborTime = laborTime.add(new BigDecimal((Integer) productionRecord.getField(LABOR_TIME)),
numberService.getMathContext());
}
}
BigDecimal machineTimeBalance = machineTime.subtract(plannedMachineTime, numberService.getMathContext());
BigDecimal laborTimeBalance = laborTime.subtract(plannedLaborTime, numberService.getMathContext());
productionBalance.setField(PLANNED_MACHINE_TIME, plannedMachineTime);
productionBalance.setField(MACHINE_TIME, machineTime);
productionBalance.setField(MACHINE_TIME_BALANCE, machineTimeBalance);
productionBalance.setField(PLANNED_LABOR_TIME, plannedLaborTime);
productionBalance.setField(LABOR_TIME, laborTime);
productionBalance.setField(LABOR_TIME_BALANCE, laborTimeBalance);
productionBalance.getDataDefinition().save(productionBalance);
}
private void fillOperationTimeComponents(final Entity productionBalance, final Entity order) {
if ((productionBalance == null) || (order == null)) {
return;
}
List operationTimeComponents = Lists.newArrayList();
List productionRecordsList = getProductionRecordsFromDB(order);
if (!productionRecordsList.isEmpty()) {
Collections.sort(productionRecordsList, new EntityProductionRecordOperationComparator());
List groupedProductionRecords = productionBalanceReportDataService
.groupProductionRecordsByOperation(productionRecordsList);
if (!groupedProductionRecords.isEmpty()) {
for (Entity groupedProductionRecord : groupedProductionRecords) {
Entity operationTimeComponent = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER,
ProductionCountingConstants.MODEL_OPERATION_TIME_COMPONENT).create();
operationTimeComponent.setField(MODEL_ORDER_OPERATION_COMPONENT,
groupedProductionRecord.getBelongsToField(MODEL_ORDER_OPERATION_COMPONENT));
operationTimeComponent.setField(L_PLANNED_MACHINE_TIME,
groupedProductionRecord.getField(PLANNED_MACHINE_TIME));
operationTimeComponent.setField(L_MACHINE_TIME, groupedProductionRecord.getField(MACHINE_TIME));
operationTimeComponent.setField(L_MACHINE_TIME_BALANCE,
groupedProductionRecord.getField(MACHINE_TIME_BALANCE));
operationTimeComponent.setField(L_PLANNED_LABOR_TIME, groupedProductionRecord.getField(PLANNED_LABOR_TIME));
operationTimeComponent.setField(L_LABOR_TIME, groupedProductionRecord.getField(LABOR_TIME));
operationTimeComponent.setField(L_LABOR_TIME_BALANCE, groupedProductionRecord.getField(LABOR_TIME_BALANCE));
operationTimeComponents.add(operationTimeComponent);
}
}
}
productionBalance.setField(OPERATION_TIME_COMPONENTS, operationTimeComponents);
productionBalance.getDataDefinition().save(productionBalance);
}
private void fillOperationPieceworkComponents(final Entity productionBalance, final Entity order) {
if ((productionBalance == null) || (order == null)) {
return;
}
List operationPieceworkComponents = Lists.newArrayList();
List productionRecordsList = getProductionRecordsFromDB(order);
if (!productionRecordsList.isEmpty()) {
Collections.sort(productionRecordsList, new EntityProductionRecordOperationComparator());
List groupedProductionRecords = productionBalanceReportDataService
.groupProductionRecordsByOperation(productionRecordsList);
if (!groupedProductionRecords.isEmpty()) {
for (Entity groupedProductionRecord : groupedProductionRecords) {
Entity operationPieceworkComponent = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER,
ProductionCountingConstants.MODEL_OPERATION_PIECEWORK_COMPONENT).create();
operationPieceworkComponent.setField(MODEL_ORDER_OPERATION_COMPONENT,
groupedProductionRecord.getBelongsToField(MODEL_ORDER_OPERATION_COMPONENT));
operationPieceworkComponent.setField("plannedCycles", "");
operationPieceworkComponent.setField("cyclesBalance", "");
operationPieceworkComponents.add(operationPieceworkComponent);
}
}
}
productionBalance.setField(OPERATION_PIECEWORK_COMPONENTS, operationPieceworkComponents);
productionBalance.getDataDefinition().save(productionBalance);
}
private void generateProductionBalanceDocuments(final Entity productionBalance, final Locale locale) throws IOException,
DocumentException {
String localePrefix = "productionCounting.productionBalance.report.fileName";
Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, DATE, localePrefix);
Entity company = getCompanyFromDB();
try {
productionBalancePdfService.generateDocument(productionBalanceWithFileName, company, locale);
=======
final String[] args);
>>>>>>> ccce16045502c5141944b23be021c89126814d52
public boolean checkIfTypeOfProductionRecordingIsBasic(final Entity order);
|