SDF57 processing

This commit is contained in:
etreschenkov 2023-05-24 19:25:45 +03:00
parent 2d7bfae8a0
commit b5de68ae1e

View file

@ -121,22 +121,23 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
return Optional.of(statement);
};
//create by companyDeb
Company companyDeb = validator.getStored(ValidationStored.Sdf57CompanyDeb);
Company companyDeb = validator.getStored(ValidationStored.Sdf57CompanyDeb); //плательщик
Account accountDeb = validator.getStored(ValidationStored.Sdf57AccountDeb);
Company companyCred = validator.getStored(ValidationStored.Sdf57CompanyCred);
Company companyCred = validator.getStored(ValidationStored.Sdf57CompanyCred);//получатель
Account accountCred = validator.getStored(ValidationStored.Sdf57AccountCred);
//адресат CREDIT / владелец DEBIT
Optional<Statement> statementDeb = createStatementIfNeeded.apply(companyCred, accountDeb, InOutDirection.out);
Optional<Statement> statementDeb = createStatementIfNeeded.apply(companyCred, accountCred, InOutDirection.in);
//адресат DEBIT / владелец CREDIT
Optional<Statement> statementCred = createStatementIfNeeded.apply(companyDeb, accountCred, InOutDirection.in);
Optional<Statement> statementCred = createStatementIfNeeded.apply(companyDeb, accountDeb, InOutDirection.out);
Consumer<StmtCmpAcc> createRegistryIfNeeded = stmtCmpAcc -> {
Statement stmt = stmtCmpAcc.statement();
Statement counterStmt = stmtCmpAcc.counterStatement();
Company company = stmtCmpAcc.company();
Account account = stmtCmpAcc.account();
Optional<EnumMessage> err = validateActiveness(company, account, stmt);
if (account == null)
return;
Optional<EnumMessage> err = validateActiveness(company, account);
if (err.isEmpty()) {
Consumer<Registry> update = rgs -> {
updateReg(stmt, rgs);
@ -157,17 +158,16 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
statementImdg.update(stmt);
}
};
statementDeb.ifPresent(stmt -> createRegistryIfNeeded.accept(new StmtCmpAcc(stmt, statementCred.orElse(null), companyDeb, accountDeb)));
statementCred.ifPresent(stmt -> createRegistryIfNeeded.accept(new StmtCmpAcc(stmt, statementDeb.orElse(null), companyCred, accountCred)));
statementDeb.ifPresent(stmt -> createRegistryIfNeeded.accept(new StmtCmpAcc(stmt, companyDeb, accountDeb)));
statementCred.ifPresent(stmt -> createRegistryIfNeeded.accept(new StmtCmpAcc(stmt, companyCred, accountCred)));
}
return result;
}
private static record StmtCmpAcc(Statement statement, Statement counterStatement, Company company,
Account account) {
private record StmtCmpAcc(Statement statement, Company company, Account account) {
}
private Optional<EnumMessage> validateActiveness(Company company, Account account, Statement statement) {
private Optional<EnumMessage> validateActiveness(Company company, Account account) {
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
return Optional.of(new EnumMessage(ClearingError.CompanyNotActive, company.getId()));
}