bill splitted

This commit is contained in:
Hendrik Schutter 2018-12-06 23:15:06 +01:00
parent 25bedae873
commit 88b39820ca
6 changed files with 181 additions and 48 deletions

View File

@ -1,10 +1,13 @@
package com.jFxKasse.application;
import java.util.ArrayList;
import com.jFxKasse.controller.DBController;
import com.jFxKasse.controller.PrinterController;
import com.jFxKasse.controller.XMLController;
import com.jFxKasse.datatypes.PrintDataSimple;
import com.jFxKasse.datatypes.PrintDataSplitted;
import javafx.geometry.Insets;
import javafx.scene.control.ButtonType;
@ -53,9 +56,26 @@ public class PrintJob
pc.selectPrinter(xmlc.getPrintername());
if (xmlc.getCategorySplitted()) {
// split the bills
PrintDataSplitted pdsplitted = new PrintDataSplitted(xmlc.getLinebreak(),
xmlc.getOffsetHeader(), xmlc.getOffsetFooter(),
timedate.getSystemTime() + " " + timedate.getSystemDate(),
xmlc.getHeader(), xmlc.getFooter());
// TODO
pdsplitted.setData(Integer.toString(jobID), dbc.getTime_Job(jobID),
dbc.getQuantity_Job(jobID), dbc.getName_Job(jobID),
dbc.getValue_Job(jobID), dbc.getCategory_Job(jobID),
dbc.getJobValue_Job(jobID));
System.out.println("Printing job ...");
ArrayList<String> printString = pdsplitted.getPrintStrings();
for(int i = 0; i < printString.size(); i++) {
pc.printString(printString.get(i));
}
} else {
// one single bills
PrintDataSimple pds = new PrintDataSimple(xmlc.getLinebreak(),

View File

@ -83,13 +83,13 @@ public class PrinterController implements Printable
}
}
/**
*
* @param input data as String
*/
public void printString(String text)
{
PrintService service = selectedPrinter;
DocPrintJob job = service.createPrintJob();

View File

@ -0,0 +1,38 @@
package com.jFxKasse.datatypes;
public class Category
{
private String categoryName;
private String positionsString = "\n";
public Category(String categoryName)
{
this.categoryName = categoryName;
}
// public void setCategoryName(String categoryName) {
// this.categoryName = categoryName;
// }
public String getCategoryName()
{
return categoryName;
}
public void addPosition(int quantity, String name, String value, PrintData pd)
{
//positionenString = pd.setRight(pd.breakLines(name), value + "") + "\n";
for (int i = 0; i < quantity; i++) {
positionsString = positionsString
+ pd.setRight(pd.breakLines(name), value + "") + "\n";
}
}
public String getPositionsString() {
return positionsString;
}
}

View File

@ -13,13 +13,13 @@ public abstract class PrintData
protected String footer;
protected String positionenQuantity;
protected String positionsQuantity;
protected String positionenName;
protected String positionsName;
protected String positionenValue;
protected String positionsValue;
protected String positionenCategory;
protected String positionsCategory;
protected String jobID;
@ -60,17 +60,16 @@ public abstract class PrintData
* @param jobValue
*/
public void setData(String jobID, String timeAndDateOrder,
String positionenQuantity, String positionenName,
String positionenValue, String positionenCategory, String jobValue)
String positionsQuantity, String positionsName,
String positionsValue, String positionsCategory, String jobValue)
{
this.jobID = jobID;
this.timeAndDateOrder = timeAndDateOrder;
this.positionenQuantity = positionenQuantity;
this.positionenName = positionenName;
this.positionenValue = positionenValue;
this.positionenCategory = positionenCategory;
this.positionsQuantity = positionsQuantity;
this.positionsName = positionsName;
this.positionsValue = positionsValue;
this.positionsCategory = positionsCategory;
this.jobValue = jobValue;
}
/**

View File

@ -53,14 +53,14 @@ public class PrintDataSimple extends PrintData
String positionen = "\n";
int posCount = positionenQuantity.length()
- positionenQuantity.replace(";", "").length() + 1;
int posCount = positionsQuantity.length()
- positionsQuantity.replace(";", "").length() + 1;
String[] positionQuantity = positionenQuantity.split(";");
String[] positionQuantity = positionsQuantity.split(";");
String[] positionName = positionenName.split(";");
String[] positionName = positionsName.split(";");
String[] positionValue = positionenValue.split(";");
String[] positionValue = positionsValue.split(";");
for (int i = 0; i < posCount; i++) { //All different posNames
int quantity = Integer.parseInt(positionQuantity[i]);

View File

@ -1,12 +1,17 @@
package com.jFxKasse.datatypes;
import java.util.ArrayList;
public class PrintDataSplitted extends PrintData
{
private ArrayList<String> printString = new ArrayList<String>();
private String printString;
private ArrayList<Category> categories = new ArrayList<Category>();
private int categoryCount = 0;
/**
* Constructor with all data that is not in the DB
* Constructor with all data that is not in the DB
* @param lineBreak
* @param headerSpace
* @param footerSpace
@ -23,17 +28,20 @@ public class PrintDataSplitted extends PrintData
/**
* Generates the String
* @return the final Print String
* @return the final Array with the Print Strings
*/
public String getPrintString()
public ArrayList<String> getPrintStrings()
{
generatePrintString();
return this.printString;
return printString;
}
@Override
protected void generatePrintString()
{
String firstBill;
/* Header */
String header = "\n";
for (int i = 1; i < headerSpace; i++) {
@ -49,26 +57,7 @@ public class PrintDataSplitted extends PrintData
+ setRight("Druck: ", timeAndDatePrint) + "\n"
+ setRight("Bestellnummer: ", jobID);
/* Positionen */
String positionen = "\n";
int posCount = positionenQuantity.length()
- positionenQuantity.replace(";", "").length() + 1;
String[] positionQuantity = positionenQuantity.split(";");
String[] positionName = positionenName.split(";");
String[] positionValue = positionenValue.split(";");
for (int i = 0; i < posCount; i++) { //All different posNames
int quantity = Integer.parseInt(positionQuantity[i]);
for (int j = 0; j < quantity; j++) { //quantities
positionen = positionen + setRight(breakLines(positionName[i]),
positionValue[i] + "") + "\n";
}
}
/* Splitted Bills */
/* Price */
@ -83,11 +72,98 @@ public class PrintDataSplitted extends PrintData
}
footer = footer + "_";
/* Build final Print String */
/* Build first Print String */
firstBill = header + "\n" + getSeparator() + "\n" + info + "\n"
+ getSeparator() + "\n" + setCenter("Bon wurde aufgeteilt") + "\n"
+ getSeparator() + "\n" + price + "\n" + getSeparator() + "\n"
+ footer;
printString.add(firstBill);
/* first bill ends here */
/* Categories in extra bills*/
String positions = null;
int posCount = positionsQuantity.length()
- positionsQuantity.replace(";", "").length() + 1;
String[] positionQuantity = positionsQuantity.split(";");
String[] positionName = positionsName.split(";");
String[] positionValue = positionsValue.split(";");
String[] positionCategory = positionsCategory.split(";");
for (int i = 0; i < posCount; i++) { // All different posNames
int quantity = Integer.parseInt(positionQuantity[i]);
insertToCategory(quantity, positionName[i], positionValue[i],
positionCategory[i]);
}
// loops through all categories
for (int i = 0; i < categories.size(); i++) {
String thisBill;
/* Header */
header = "\n";
for (int o = 1; o < headerSpace; o++) {
header = header + "\n";
}
// This is the final header
header = header + setCenter(this.header);
/* Info */
info = setRight("Bestellung: ", timeAndDateOrder) + "\n"
+ setRight("Druck: ", timeAndDatePrint) + "\n"
+ setRight("Bestellnummer: ", jobID);
/* Positions */
positions = categories.get(i).getPositionsString();
/* Footer */
footer = setCenter(this.footer);
for (int o = 1; o < footerSpace; o++) {
footer = footer + "\n";
}
footer = footer + "_";
thisBill = header + "\n" + getSeparator() + "\n" + info + "\n"
+ getSeparator() + "\n"
+ setCenter(categories.get(i).getCategoryName()) + "\n"
+ getSeparator() +
positions + "\n" + getSeparator();
printString.add(thisBill);
}
}
private void insertToCategory(int quantity, String name, String value,
String category)
{
boolean createNewCategorie = true;
for (int i = 0; i < categoryCount; i++) {
if (category.equals(categories.get(i).getCategoryName())) {
categories.get(i).addPosition(quantity, name, value, this);
createNewCategorie = false;
}
}
if (createNewCategorie) {
// position has a new category
categories.add(new Category(category));
categories.get(categoryCount).addPosition(quantity, name, value, this);
categoryCount++;
}
printString = header + "\n" + getSeparator() + "\n" + info + "\n"
+ getSeparator() + "\n" + positionen + "\n" + getSeparator() + "\n"
+ price + "\n" + getSeparator() + "\n" + footer;
}
}