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; package com.jFxKasse.application;
import java.util.ArrayList;
import com.jFxKasse.controller.DBController; import com.jFxKasse.controller.DBController;
import com.jFxKasse.controller.PrinterController; import com.jFxKasse.controller.PrinterController;
import com.jFxKasse.controller.XMLController; import com.jFxKasse.controller.XMLController;
import com.jFxKasse.datatypes.PrintDataSimple; import com.jFxKasse.datatypes.PrintDataSimple;
import com.jFxKasse.datatypes.PrintDataSplitted;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
@ -53,9 +56,26 @@ public class PrintJob
pc.selectPrinter(xmlc.getPrintername()); pc.selectPrinter(xmlc.getPrintername());
if (xmlc.getCategorySplitted()) { if (xmlc.getCategorySplitted()) {
// split the bills // 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 { } else {
// one single bills // one single bills
PrintDataSimple pds = new PrintDataSimple(xmlc.getLinebreak(), PrintDataSimple pds = new PrintDataSimple(xmlc.getLinebreak(),

View File

@ -83,13 +83,13 @@ public class PrinterController implements Printable
} }
} }
/** /**
* *
* @param input data as String * @param input data as String
*/ */
public void printString(String text) public void printString(String text)
{ {
PrintService service = selectedPrinter; PrintService service = selectedPrinter;
DocPrintJob job = service.createPrintJob(); 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 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; protected String jobID;
@ -60,17 +60,16 @@ public abstract class PrintData
* @param jobValue * @param jobValue
*/ */
public void setData(String jobID, String timeAndDateOrder, public void setData(String jobID, String timeAndDateOrder,
String positionenQuantity, String positionenName, String positionsQuantity, String positionsName,
String positionenValue, String positionenCategory, String jobValue) String positionsValue, String positionsCategory, String jobValue)
{ {
this.jobID = jobID; this.jobID = jobID;
this.timeAndDateOrder = timeAndDateOrder; this.timeAndDateOrder = timeAndDateOrder;
this.positionenQuantity = positionenQuantity; this.positionsQuantity = positionsQuantity;
this.positionenName = positionenName; this.positionsName = positionsName;
this.positionenValue = positionenValue; this.positionsValue = positionsValue;
this.positionenCategory = positionenCategory; this.positionsCategory = positionsCategory;
this.jobValue = jobValue; this.jobValue = jobValue;
} }
/** /**

View File

@ -53,14 +53,14 @@ public class PrintDataSimple extends PrintData
String positionen = "\n"; String positionen = "\n";
int posCount = positionenQuantity.length() int posCount = positionsQuantity.length()
- positionenQuantity.replace(";", "").length() + 1; - 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 for (int i = 0; i < posCount; i++) { //All different posNames
int quantity = Integer.parseInt(positionQuantity[i]); int quantity = Integer.parseInt(positionQuantity[i]);

View File

@ -1,12 +1,17 @@
package com.jFxKasse.datatypes; package com.jFxKasse.datatypes;
import java.util.ArrayList;
public class PrintDataSplitted extends PrintData 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 lineBreak
* @param headerSpace * @param headerSpace
* @param footerSpace * @param footerSpace
@ -23,17 +28,20 @@ public class PrintDataSplitted extends PrintData
/** /**
* Generates the String * Generates the String
* @return the final Print String * @return the final Array with the Print Strings
*/ */
public String getPrintString() public ArrayList<String> getPrintStrings()
{ {
generatePrintString(); generatePrintString();
return this.printString; return printString;
} }
@Override @Override
protected void generatePrintString() protected void generatePrintString()
{ {
String firstBill;
/* Header */ /* Header */
String header = "\n"; String header = "\n";
for (int i = 1; i < headerSpace; i++) { for (int i = 1; i < headerSpace; i++) {
@ -49,26 +57,7 @@ public class PrintDataSplitted extends PrintData
+ setRight("Druck: ", timeAndDatePrint) + "\n" + setRight("Druck: ", timeAndDatePrint) + "\n"
+ setRight("Bestellnummer: ", jobID); + setRight("Bestellnummer: ", jobID);
/* Positionen */ /* Splitted Bills */
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";
}
}
/* Price */ /* Price */
@ -83,11 +72,98 @@ public class PrintDataSplitted extends PrintData
} }
footer = footer + "_"; 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;
} }
} }