1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
package com.mavlushechka.notaryautomation;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.*;
public class App {
private static final Scanner SCANNER = new Scanner(System.in);
public static void main(String[] args) throws Exception {
Person deadPerson;
LocalDate dateOfDeath;
String roleOfDeadPerson;
ArrayList<Person> heirs = new ArrayList<>();
Person finalHeir;
String roleOfFinalHeir;
System.out.println("Погибший человек:\n");
deadPerson = createPerson();
System.out.print("Дата смерти (1990-12-31): ");
dateOfDeath = LocalDate.parse(SCANNER.next());
System.out.print("Роль в семье (Мать, Отец и т.д.): ");
roleOfDeadPerson = SCANNER.next().toLowerCase();
boolean isThereAnotherHeir;
System.out.println("\nНаследникики:");
do {
System.out.println();
heirs.add(createPerson());
System.out.print("\nЕсть ещё наследники? (Да/Нет) ");
isThereAnotherHeir = "Да".equalsIgnoreCase(SCANNER.next());
} while (isThereAnotherHeir);
System.out.println("\nВсе наследники:");
for (int i = 0; i < heirs.size(); i++) {
System.out.println(i+1 + ". " + heirs.get(i).firstName() + " " + heirs.get(i).secondName() + " " + heirs.get(i).middleName());
}
System.out.print("Окончательный наследник (введите число): ");
finalHeir = heirs.get(SCANNER.nextInt() - 1);
System.out.print("Роль в семье (Сын, Дочь и т.д.): ");
roleOfFinalHeir = SCANNER.next().toLowerCase();
updateApplicationOfTheHeirToRenounceTheInheritanceShareDocument(deadPerson, dateOfDeath, roleOfDeadPerson, heirs, finalHeir, roleOfFinalHeir);
}
private static Person createPerson() {
System.out.print("Введите имя: ");
String firstName = SCANNER.next().toUpperCase();
System.out.print("Введите фамилию: ");
String secondName = SCANNER.next().toUpperCase();
System.out.print("Введите отчество: ");
SCANNER.nextLine();
String middleName = SCANNER.nextLine().toUpperCase();
System.out.print("Введите серию паспорта (AA): ");
String serial = SCANNER.next().toUpperCase();
if (" ".equals(serial)) {
serial = "AA";
}
System.out.print("Введите номер паспорта (1234567): ");
int number = SCANNER.nextInt();
System.out.print("Введите гражданство человека (Uzbekistan): ");
String citizenship = SCANNER.next();
if (" ".equals(citizenship)) {
citizenship = "Uzbekistan";
}
System.out.print("Введите место выдачи паспорта (XORAZM VILOYATI URGANCH TUMANI IIB): ");
SCANNER.nextLine();
String placeOfIssue = SCANNER.nextLine().toUpperCase();
if (" ".equals(placeOfIssue)) {
placeOfIssue = "XORAZM VILOYATI URGANCH TUMANI IIB";
}
System.out.print("Введите дату выдачи паспорта (1990-12-31): ");
LocalDate dateOfIssue = LocalDate.parse(SCANNER.next());
System.out.print("Введите ЖШШИР (12345678901234): ");
String personalIdentificationNumberOfThePhysicalPerson = SCANNER.next();
System.out.print("Введите место проживания: ");
SCANNER.nextLine();
String placeOfResidence = SCANNER.nextLine();
return new Person(firstName, secondName, middleName, new Passport(serial, number, citizenship, placeOfIssue, dateOfIssue, personalIdentificationNumberOfThePhysicalPerson, placeOfResidence));
}
private static void updateApplicationOfTheHeirToRenounceTheInheritanceShareDocument(Person deadPerson, LocalDate dateOfDeath, String roleOfDeadPerson, ArrayList<Person> heirs, Person finalHeir, String roleOfFinalHeir) throws Exception {
FileInputStream fileInputStream = new FileInputStream("Application of the heir to renounce the inheritance share.docx");
try (XWPFDocument xwpfDocument = new XWPFDocument(OPCPackage.open(fileInputStream))) {
List<XWPFParagraph> xwpfParagraphList = xwpfDocument.getParagraphs();
for (XWPFParagraph xwpfParagraph : xwpfParagraphList) {
for (XWPFRun xwpfRun : xwpfParagraph.getRuns()) {
String oldText = xwpfRun.getText(0);
if (oldText == null) continue;
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
String text = oldText
.replace("${dateOfDeath}", dateOfDeath.format(dateTimeFormatter))
.replace("${currentDate}", LocalDate.now().format(dateTimeFormatter)
.replace("${relationship1}", roleOfDeadPerson)
.replace("${relationship2}", roleOfFinalHeir)
.replace("${deadPerson.firstName}", deadPerson.firstName())
.replace("${deadPerson.secondName}", deadPerson.secondName())
.replace("${finalHeir.firstName}", finalHeir.firstName())
.replace("${finalHeir.secondName}", finalHeir.secondName())
.replace("${numberOfArticle}", "Отец".equalsIgnoreCase(roleOfDeadPerson) && "Мать".equalsIgnoreCase(roleOfFinalHeir) ? "1135" : "?"));
for (int i = 1; i < heirs.size(); i++) {
String personsFullInfo = "${personsFullInfo" + i + "}";
String personsLine = "${personsLine" + (i + 1) + "}";
Person person = heirs.get(i - 1);
text = text
.replace(personsFullInfo,person.passport().placeOfResidence() + "да\n"
+ "рўйхатда турувчи " + person.firstName() + " " + person.secondName() + " " + person.middleName() + "\n"
+ "(" + person.passport().citizenship() + " фуқаросининг биометрик паспорти " + person.passport().serial() + " " + person.passport().number() + ",\n"
+ person.passport().placeOfIssue() + " томонидан\n"
+ person.passport().dateOfIssue().format(dateTimeFormatter) + " йилда берилган, ЖШШИР " + person.passport().personalIdentificationNumberOfThePhysicalPerson() + ")\n"
+ (heirs.size() > i + 1 ? "${personsFullInfo" + (i + 1) + "}" : ""))
.replace(personsLine,(i + 1) + "._______________________________________________________________________\n"
+ (heirs.size() > i + 1 ? "${personsLine" + (i + 2) + "}" : ""));
}
xwpfRun.setText(text, 0);
}
}
try (FileOutputStream out = new FileOutputStream(finalHeir.firstName() + " " + finalHeir.secondName() + " " + finalHeir.middleName() + ", Меросхўрнинг мерос улушидан воз кечиш ҳақидаги аризаси.docx")) {
xwpfDocument.write(out);
}
}
}
}
|