Skip to content

Commit

Permalink
Use structured addresses in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Jun 1, 2024
1 parent 293f2f4 commit 0f1ebce
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 75 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ To generate a QR bill, you first fill in the `Bill` data structure and then call
// Set creditor
Address creditor = new Address();
creditor.setName("Robert Schneider AG");
creditor.setAddressLine1("Rue du Lac 1268/2/22");
creditor.setAddressLine2("2501 Biel");
creditor.setStreet("Rue du Lac");
creditor.setHouseNo("1268/2/22");
creditor.setPostalCode("2501");
creditor.setTown("Biel");
creditor.setCountryCode("CH");
bill.setCreditor(creditor);

Expand All @@ -89,16 +91,19 @@ To generate a QR bill, you first fill in the `Bill` data structure and then call
// Set debtor
Address debtor = new Address();
debtor.setName("Pia-Maria Rutschmann-Schnyder");
debtor.setAddressLine1("Grosse Marktgasse 28");
debtor.setAddressLine2("9400 Rorschach");
debtor.setStreet("Grosse Marktgasse");
debtor.setHouseNo("28");
debtor.setPostalCode("9400");
debtor.setTown("Rorschach");
debtor.setCountryCode("CH");
bill.setDebtor(debtor);

// Set output format
BillFormat format = bill.getFormat();
BillFormat format = new BillFormat();
format.setGraphicsFormat(GraphicsFormat.SVG);
format.setOutputSize(OutputSize.QR_BILL_ONLY);
format.setLanguage(Language.DE);
bill.setFormat(format);

// Generate QR bill
byte[] svg = QRBill.generate(bill);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) throws URISyntaxException, IOException {
// Setup bill format
Bill bill = new Bill();
bill.getFormat().setLanguage(Language.DE);
bill.getFormat().setOutputSize(OutputSize.QR_CODE_ONLY);
bill.getFormat().setOutputSize(OutputSize.QR_BILL_ONLY);

// Set account and amount
bill.setAccount("CH48 0900 0000 8575 7337 2");
Expand All @@ -43,8 +43,10 @@ public static void main(String[] args) throws URISyntaxException, IOException {
// Set creditor
Address creditor = new Address();
creditor.setName("Omnia Trading AG");
creditor.setAddressLine1("Allmendweg 30");
creditor.setAddressLine2("4528 Zuchwil");
creditor.setStreet("Allmendweg");
creditor.setHouseNo("30");
creditor.setPostalCode("4528");
creditor.setTown("Zuchwil");
creditor.setCountryCode("CH");
bill.setCreditor(creditor);

Expand All @@ -55,8 +57,10 @@ public static void main(String[] args) throws URISyntaxException, IOException {
// Set debtor
Address debtor = new Address();
debtor.setName("Machina Futura AG");
debtor.setAddressLine1("Alte Fabrik 3A");
debtor.setAddressLine2("8400 Winterthur");
debtor.setStreet("Alte Fabrik");
debtor.setHouseNo("3A");
debtor.setPostalCode("8400");
debtor.setTown("Winterthur");
debtor.setCountryCode("CH");
bill.setDebtor(debtor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public static void main(String[] args) {
// Set creditor
Address creditor = new Address();
creditor.setName("Robert Schneider AG");
creditor.setAddressLine1("Rue du Lac 1268/2/22");
creditor.setAddressLine2("2501 Biel");
creditor.setStreet("Rue du Lac");
creditor.setHouseNo("1268/2/22");
creditor.setPostalCode("2501");
creditor.setTown("Biel");
creditor.setCountryCode("CH");
bill.setCreditor(creditor);

Expand All @@ -45,8 +47,10 @@ public static void main(String[] args) {
// Set debtor
Address debtor = new Address();
debtor.setName("Pia-Maria Rutschmann-Schnyder");
debtor.setAddressLine1("Grosse Marktgasse 28");
debtor.setAddressLine2("9400 Rorschach");
debtor.setStreet("Grosse Marktgasse");
debtor.setHouseNo("28");
debtor.setPostalCode("9400");
debtor.setTown("Rorschach");
debtor.setCountryCode("CH");
bill.setDebtor(debtor);

Expand Down
2 changes: 1 addition & 1 deletion examples/jasper_reports_rendering/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>net.codecrete.qrbill</groupId>
<artifactId>qrbill-generator</artifactId>
<version>[3.0.0,3.999999]</version>
<version>[3.3.0,3.999999]</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
* </p>
* <ul>
* <li>CreditorName</li>
* <li>CreditorAddressLine1</li>
* <li>CreditorAddressLine2</li>
* <li>CreditorStreet – optional</li>
* <li>CreditorHouseNo – optional</li>
* <li>CreditorPostalCode – optional</li>
* <li>CreditorTown – optional</li>
* <li>CreditorCountryCode</li>
* <li>Account</li>
* <li>DebtorName – optional</li>
* <li>DebtorAddressLine1 – optional</li>
* <li>DebtorAddressLine2 – optional</li>
* <li>CreditorAddressLine1 – optional</li>
* <li>CreditorAddressLine2 – optional</li>
* <li>DebtorStreet – optional</li>
* <li>DebtorHouseNo – optional</li>
* <li>DebtorPostalCode – optional</li>
* <li>DebtorTown – optional</li>
* <li>DebtorCountryCode – optional</li>
* <li>Reference – optional</li>
* <li>UnstructuredMessage – optional</li>
Expand All @@ -54,13 +56,17 @@ public class QrBillImageDataSource implements JRDataSource {
public static final String FIELD_QR_BILL_IMAGE = "QrBillImage";

public static final String INPUT_FIELD_CREDITOR_NAME = "CreditorName";
public static final String INPUT_FIELD_CREDITOR_ADDRESS_LINE_1 = "CreditorAddressLine1";
public static final String INPUT_FIELD_CREDITOR_ADDRESS_LINE_2 = "CreditorAddressLine2";
public static final String INPUT_FIELD_CREDITOR_STREET = "CreditorStreet";
public static final String INPUT_FIELD_CREDITOR_HOUSE_NO = "CreditorHouseNo";
public static final String INPUT_FIELD_CREDITOR_POSTAL_CODE = "CreditorPostalCode";
public static final String INPUT_FIELD_CREDITOR_TOWN = "CreditorTown";
public static final String INPUT_FIELD_CREDITOR_COUNTRY_CODE = "CreditorCountryCode";
public static final String INPUT_FIELD_ACCOUNT = "Account";
public static final String INPUT_FIELD_DEBTOR_NAME = "DebtorName";
public static final String INPUT_FIELD_DEBTOR_ADDRESS_LINE_1 = "DebtorAddressLine1";
public static final String INPUT_FIELD_DEBTOR_ADDRESS_LINE_2 = "DebtorAddressLine2";
public static final String INPUT_FIELD_DEBTOR_STREET = "DebtorStreet";
public static final String INPUT_FIELD_DEBTOR_HOUSE_NO = "DebtorHouseNo";
public static final String INPUT_FIELD_DEBTOR_POSTAL_CODE = "DebtorPostalCode";
public static final String INPUT_FIELD_DEBTOR_TOWN = "DebtorTown";
public static final String INPUT_FIELD_DEBTOR_COUNTRY_CODE = "DebtorCountryCode";
public static final String INPUT_FIELD_REFERENCE = "Reference";
public static final String INPUT_FIELD_UNSTRUCTURED_MESSAGE = "UnstructuredMessage";
Expand All @@ -76,13 +82,17 @@ public class QrBillImageDataSource implements JRDataSource {

private void initFieldNameMap() {
addFieldNameMapping(INPUT_FIELD_CREDITOR_NAME);
addFieldNameMapping(INPUT_FIELD_CREDITOR_ADDRESS_LINE_1);
addFieldNameMapping(INPUT_FIELD_CREDITOR_ADDRESS_LINE_2);
addFieldNameMapping(INPUT_FIELD_CREDITOR_STREET);
addFieldNameMapping(INPUT_FIELD_CREDITOR_HOUSE_NO);
addFieldNameMapping(INPUT_FIELD_CREDITOR_POSTAL_CODE);
addFieldNameMapping(INPUT_FIELD_CREDITOR_TOWN);
addFieldNameMapping(INPUT_FIELD_CREDITOR_COUNTRY_CODE);
addFieldNameMapping(INPUT_FIELD_ACCOUNT);
addFieldNameMapping(INPUT_FIELD_DEBTOR_NAME);
addFieldNameMapping(INPUT_FIELD_DEBTOR_ADDRESS_LINE_1);
addFieldNameMapping(INPUT_FIELD_DEBTOR_ADDRESS_LINE_2);
addFieldNameMapping(INPUT_FIELD_DEBTOR_STREET);
addFieldNameMapping(INPUT_FIELD_DEBTOR_HOUSE_NO);
addFieldNameMapping(INPUT_FIELD_DEBTOR_POSTAL_CODE);
addFieldNameMapping(INPUT_FIELD_DEBTOR_TOWN);
addFieldNameMapping(INPUT_FIELD_DEBTOR_COUNTRY_CODE);
addFieldNameMapping(INPUT_FIELD_REFERENCE);
addFieldNameMapping(INPUT_FIELD_UNSTRUCTURED_MESSAGE);
Expand Down Expand Up @@ -177,16 +187,20 @@ protected void createBill() throws JRException {

var creditor = new Address();
creditor.setName(getStringValue(INPUT_FIELD_CREDITOR_NAME));
creditor.setAddressLine1(getStringValue(INPUT_FIELD_CREDITOR_ADDRESS_LINE_1));
creditor.setAddressLine2(getStringValue(INPUT_FIELD_CREDITOR_ADDRESS_LINE_2));
creditor.setStreet(getStringValue(INPUT_FIELD_CREDITOR_STREET));
creditor.setHouseNo(getStringValue(INPUT_FIELD_CREDITOR_HOUSE_NO));
creditor.setPostalCode(getStringValue(INPUT_FIELD_CREDITOR_POSTAL_CODE));
creditor.setTown(getStringValue(INPUT_FIELD_CREDITOR_TOWN));
creditor.setCountryCode(getStringValue(INPUT_FIELD_CREDITOR_COUNTRY_CODE));
bill.setCreditor(creditor);
bill.setAccount(getStringValue(INPUT_FIELD_ACCOUNT));

var debtor = new Address();
debtor.setName(getStringValue(INPUT_FIELD_DEBTOR_NAME));
debtor.setAddressLine1(getStringValue(INPUT_FIELD_DEBTOR_ADDRESS_LINE_1));
debtor.setAddressLine2(getStringValue(INPUT_FIELD_DEBTOR_ADDRESS_LINE_2));
debtor.setStreet(getStringValue(INPUT_FIELD_DEBTOR_STREET));
debtor.setHouseNo(getStringValue(INPUT_FIELD_DEBTOR_HOUSE_NO));
debtor.setPostalCode(getStringValue(INPUT_FIELD_DEBTOR_POSTAL_CODE));
debtor.setTown(getStringValue(INPUT_FIELD_DEBTOR_TOWN));
debtor.setCountryCode(getStringValue(INPUT_FIELD_DEBTOR_COUNTRY_CODE));
bill.setDebtor(debtor);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
InvoiceNumber,CreditorName,CreditorAddressLine1,CreditorAddressLine2,CreditorCountryCode,Account,Reference,UnstructuredMessage,BillInformation,DebtorName,DebtorAddressLine1,DebtorAddressLine2,DebtorCountryCode,Currency,Amount,Language
1,Mordasini Architekten,Ackerstrasse 28,4057 Basel,CH,CH93666701BCX8EPX5F02,RF1910037484,Ref 10037484,,Alexandra Fankhauser,Hulmenweg 25,8352 Frauenfeld,CH,CHF,40.50,IT
2,Frey Camponovo SA,Aeneas Silvius-Strasse 28,9500 St. Gallen,CH,CH0828791JBHR7DKK50N9,,Bestellungsreferenz 3829203,,Jorim Peter,Camoletti 28,4051 Locarno,CH,CHF,300.00,DE
3,Chiesa Pellegrini SA,Naphtastrasse 15,8005 Richterswil,CH,CH3337859H8W8Z84402FI,RF4923409BCYZ230,,//S1/10/802277/11/2007012107/20/55878/30/109532551/32/7.7/40/0:30,Alexander Leuthold,Chemin Wiliam-Barbey 7,1292 Genève,CH,CHF,2832.25,DE
4,Swisstech AG,Rue Jean-Jaquet 10,1202 Versoix,CH,CH39 3016 2R48 39C9 8000 1,8 76300 65822 54397,,,Eduard Thomann,Industriestrasse 12,8604 Uster,CH,CHF,928.20,FR
5,Markt Monitoring AG,Rue du Lac 16,1207 Meyrin,CH,CH04 3005 8823 7392 0BC0 1,9 00027 23849 31830,,,Sanna Thönen,Spitzwiesenstrasse 3,8957 Baden,CH,CHF,770.45,DE
6,Klink Klingenstein,Sonnenhofweg 16,3006 Uznach,CH,CH38445968XH2M35XYKH6,,,//S1/10/10201409/11/190512/20/1400.000-53/30/106017086/31/180508/32/7.7/40/2:10;0:30,Frida Gassmann,Chemin des Vallières 17,1295 Nyon,CH,CHF,2012.50,DE
7,Carrosserie Meyer AG,Technikumstrasse 30,8400 Zürich,CH,CH8233989K7S515W72SGU,,,,Leonie Zürcher,Weinbergstrasse 31,5502 Hunzenschwil,CH,EUR,2348.10,DE
8,Schreinerei Habegger & Söhne,Uetlibergstrasse 138,8045 Zürich,CH,CH45 0023 0230 9999 9999 A,RF19 2320 QF02 T323 4UI2 34,Rechnungsnr. 10978 / Auftragsrnr. 3987,,Simon Glarner,Bächliwis 55,8184 Bachenbülach,CH,CHF,287.30,DE
9,Gromion SA,Avenue Fornachon 34,2034 Peseux,CH,CH95 0020 6206 1057 2901 J,RF23 T208 3QFT 2800 291F,,,Céline Pythoud,Chemin du Grand Record 42,1040 Échallens,CH,CHF,371.20,FR
10,Robert Schneider AG,Rue du Lac 1268/2/22,2501 Biel,CH,CH44 3199 9123 0008 8901 2,21 00000 00003 13947 14300 09017,Instruction of 15.09.2019,//S1/01/20170309/11/10201409/20/14000000/22/36958/30/CH106017086/40/1020/41/3010,Pia-Maria Rutschmann-Schnyder,Grosse Marktgasse 28,9400 Rorschach,CH,CHF,123949.75,DE
InvoiceNumber,CreditorName,CreditorStreet,CreditorHouseNo,CreditorPostalCode,CreditorTown,CreditorCountryCode,Account,Reference,UnstructuredMessage,BillInformation,DebtorName,DebtorStreet,DebtorHouseNo,DebtorPostalCode,DebtorTown,DebtorCountryCode,Currency,Amount,Language
1,Mordasini Architekten,Ackerstrasse,28,4057,Basel,CH,CH93666701BCX8EPX5F02,RF1910037484,Ref 10037484,,Alexandra Fankhauser,Hulmenweg,25,8352,Frauenfeld,CH,CHF,40.50,IT
2,Frey Camponovo SA,Aeneas Silvius-Strasse,28,9500,St. Gallen,CH,CH0828791JBHR7DKK50N9,,Bestellungsreferenz 3829203,,Jorim Peter,Camoletti,28,4051,Locarno,CH,CHF,300.00,DE
3,Chiesa Pellegrini SA,Naphtastrasse,15,8005,Richterswil,CH,CH3337859H8W8Z84402FI,RF4923409BCYZ230,,//S1/10/802277/11/2007012107/20/55878/30/109532551/32/7.7/40/0:30,Alexander Leuthold,Chemin Wiliam-Barbey,7,1292,Genève,CH,CHF,2832.25,DE
4,Swisstech AG,Rue Jean-Jaquet,10,1202,Versoix,CH,CH39 3016 2R48 39C9 8000 1,8 76300 65822 54397,,,Eduard Thomann,Industriestrasse,12,8604,Uster,CH,CHF,928.20,FR
5,Markt Monitoring AG,Rue du Lac,16,1207,Meyrin,CH,CH04 3005 8823 7392 0BC0 1,9 00027 23849 31830,,,Sanna Thönen,Spitzwiesenstrasse,3,8957,Baden,CH,CHF,770.45,DE
6,Klink Klingenstein,Sonnenhofweg,16,3006,Uznach,CH,CH38445968XH2M35XYKH6,,,//S1/10/10201409/11/190512/20/1400.000-53/30/106017086/31/180508/32/7.7/40/2:10;0:30,Frida Gassmann,Chemin des Vallières,17,1295,Nyon,CH,CHF,2012.50,DE
7,Carrosserie Meyer AG,Technikumstrasse,30,8400,Zürich,CH,CH8233989K7S515W72SGU,,,,Leonie Zürcher,Weinbergstrasse,31,5502,Hunzenschwil,CH,EUR,2348.10,DE
8,Schreinerei Habegger & Söhne,Uetlibergstrasse,138,8045,Zürich,CH,CH45 0023 0230 9999 9999 A,RF19 2320 QF02 T323 4UI2 34,Rechnungsnr. 10978 / Auftragsrnr. 3987,,Simon Glarner,Bächliwis,55,8184,Bachenbülach,CH,CHF,287.30,DE
9,Gromion SA,Avenue Fornachon,34,2034,Peseux,CH,CH95 0020 6206 1057 2901 J,RF23 T208 3QFT 2800 291F,,,Céline Pythoud,Chemin du Grand Record,42,1040,Échallens,CH,CHF,371.20,FR
10,Robert Schneider AG,Rue du Lac,1268/2/22,2501,Biel,CH,CH44 3199 9123 0008 8901 2,21 00000 00003 13947 14300 09017,Instruction of 15.09.2019,//S1/01/20170309/11/10201409/20/14000000/22/36958/30/CH106017086/40/1020/41/3010,Pia-Maria Rutschmann-Schnyder,Grosse Marktgasse,28,9400,Rorschach,CH,CHF,123949.75,DE
59 changes: 32 additions & 27 deletions examples/kotlin_example/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,42 @@ import java.nio.file.Paths
fun main() {

// Setup bill
val bill = Bill()
bill.account = "CH4431999123000889012"
bill.setAmountFromDouble(199.95)
bill.currency = "CHF"
val bill = Bill().apply {
account = "CH4431999123000889012"
setAmountFromDouble(199.95)
currency = "CHF"

// Set creditor
val creditor = Address()
creditor.name = "Robert Schneider AG"
creditor.addressLine1 = "Rue du Lac 1268/2/22"
creditor.addressLine2 = "2501 Biel"
creditor.countryCode = "CH"
bill.creditor = creditor
// creditor
creditor = Address().apply {
name = "Robert Schneider AG"
street = "Rue du Lac"
houseNo = "1268/2/22"
postalCode = "2501"
town = "Biel"
countryCode = "CH"
}

// more bill data
bill.reference = "210000000003139471430009017"
bill.unstructuredMessage = "Abonnement für 2020"
// more bill data
reference = "210000000003139471430009017"
unstructuredMessage = "Abonnement für 2020"

// Set debtor
val debtor = Address()
debtor.name = "Pia-Maria Rutschmann-Schnyder"
debtor.addressLine1 = "Grosse Marktgasse 28"
debtor.addressLine2 = "9400 Rorschach"
debtor.countryCode = "CH"
bill.debtor = debtor
// debtor
debtor = Address().apply {
name = "Pia-Maria Rutschmann-Schnyder"
street = "Grosse Marktgasse"
houseNo = "28"
postalCode = "9400"
town = "Rorschach"
countryCode = "CH"
}

// Set output format
val format = BillFormat()
format.graphicsFormat = GraphicsFormat.SVG
format.outputSize = OutputSize.QR_BILL_ONLY
format.language = Language.DE
bill.format = format
// output format
format = BillFormat().apply {
graphicsFormat = GraphicsFormat.SVG
outputSize = OutputSize.QR_BILL_ONLY
language = Language.DE
}
}

// Generate QR bill
val svg = QRBill.generate(bill)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public static void main(String[] args) {
// Set creditor
Address creditor = new Address();
creditor.setName("Robert Schneider AG");
creditor.setAddressLine1("Rue du Lac 1268/2/22");
creditor.setAddressLine2("2501 Biel");
creditor.setStreet("Rue du Lac");
creditor.setHouseNo("1268/2/22");
creditor.setPostalCode("2501");
creditor.setTown("Biel");
creditor.setCountryCode("CH");
bill.setCreditor(creditor);

Expand All @@ -45,8 +47,10 @@ public static void main(String[] args) {
// Set debtor
Address debtor = new Address();
debtor.setName("Pia-Maria Rutschmann-Schnyder");
debtor.setAddressLine1("Grosse Marktgasse 28");
debtor.setAddressLine2("9400 Rorschach");
debtor.setStreet("Grosse Marktgasse");
debtor.setHouseNo("28");
debtor.setPostalCode("9400");
debtor.setTown("Rorschach");
debtor.setCountryCode("CH");
bill.setDebtor(debtor);

Expand Down

0 comments on commit 0f1ebce

Please sign in to comment.