// Initialisierung
string cashbox = "KASSA 001";
DSFinVK.DSFinVKCom m_com = new DSFinVK.DSFinVKCom();
var error = m_com.InitializeLibrary(tbLicense.Text, "D:\\Database\\DSFinVK\\dsfinvkdb.db3", "Administrator", "test", cashbox);
if(error != DSFinVK.ErrorCode.OK)
{
MessageBox.Show(error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Nächste verfügbare BON_NR und BON_ID für diese Kasse holen
int BON_ID = 0;
error = m_com.GetNextBON_ID(cashbox, ref BON_ID);
if(error != DSFinVK.ErrorCode.OK)
{
MessageBox.Show(error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int BON_NR = 0;
error = m_com.GetNextBON_NR(cashbox, ref BON_NR);
if(error != DSFinVK.ErrorCode.OK)
{
MessageBox.Show(error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Rechnung beginnen
DSFinVK.BonKopfBegin bonkopfBegin = new DSFinVK.BonKopfBegin();
bonkopfBegin.Z_KASSE_ID = cashbox;
bonkopfBegin.BEDIENER_ID = tbBEDIENER_ID.Text;
bonkopfBegin.BEDIENER_NAME = tbBEDIENER_NAME.Text;
bonkopfBegin.BON_ID = BON_ID.ToString();
bonkopfBegin.BON_NAME = tbBON_NAME.Text;
bonkopfBegin.BON_NOTIZ = tbBON_NOTIZ.Text;
bonkopfBegin.BON_NR = BON_ID;
bonkopfBegin.BON_STORNO = cbBON_STORNO.Checked ? "1" : "0";
bonkopfBegin.BON_TYP = cmbBON_TYP.SelectedItem.ToString();
bonkopfBegin.KUNDE_ID = tbKUNDE_ID.Text;
bonkopfBegin.KUNDE_LAND = tbKUNDE_LAND.Text;
bonkopfBegin.KUNDE_NAME = tbKUNDE_NAME.Text;
bonkopfBegin.KUNDE_ORT = tbKUNDE_ORT.Text;
bonkopfBegin.KUNDE_PLZ = tbKUNDE_PLZ.Text;
bonkopfBegin.KUNDE_STRASSE = tbKUNDE_STRASSE.Text;
bonkopfBegin.KUNDE_TYP = tbKUNDE_TYP.Text;
bonkopfBegin.KUNDE_USTID = tbKUNDE_USTID.Text;
bonkopfBegin.TERMINAL_ID = tbTERMINAL_ID.Text;
int transactionNumber = 0;
error = m_com.BeginReceipt(cashbox, bonkopfBegin, ref transactionNumber);
// Bonposition hinzufügen
DSFinVK.BonPosition position = new DSFinVK.BonPosition();
position.AGENTUR_ID = Convert.ToInt32(dgvBonPos.Rows[m_dgvCurrentRow].Cells["AGENTUR_ID"].Value);
position.ARTIKELTEXT = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["ARTIKELTEXT"].Value);
position.ART_NR = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["ART_NR"].Value);
position.BON_ID = Convert.ToString(BON_ID);
position.EINHEIT = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["EINHEIT"].Value);
position.FAKTOR = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["FAKTOR"].Value);
position.GTIN = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["GTIN"].Value);
position.GUTSCHEIN_NR = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["GUTSCHEIN_NR"].Value);
position.GV_NAME = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["GV_NAME"].Value);
position.GV_TYP = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["GV_TYP"].Value);
position.INHAUS = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["INHAUS"].Value);
position.MENGE = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["MENGE"].Value);
position.POS_TERMINAL_ID = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["POS_TERMINAL_ID"].Value);
position.POS_ZEILE = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["POS_ZEILE"].Value);
position.P_STORNO = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["P_STORNO"].Value);
position.STK_BR = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["STK_BR"].Value);
position.WARENGR = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["WARENGR"].Value);
position.WARENGR_ID = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["WARENGR_ID"].Value);
position.Z_KASSE_ID = Convert.ToString(dgvBonPos.Rows[m_dgvCurrentRow].Cells["Z_KASSE_ID"].Value);
// Beträge der Position
DSFinVK.BonPosition_Ust position_vat = new DSFinVK.BonPosition_Ust();
position_vat.BON_ID = position.BON_ID;
position_vat.POS_ZEILE = position.POS_ZEILE;
position_vat.UST_SCHLUESSEL = Convert.ToInt32(dgvBonPos.Rows[m_dgvCurrentRow].Cells["UST_SCHLUESSEL"].Value);
position_vat.POS_BRUTTO = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["POS_BRUTTO"].Value);
position_vat.POS_NETTO = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["POS_NETTO"].Value);
position_vat.POS_UST = Convert.ToDecimal(dgvBonPos.Rows[m_dgvCurrentRow].Cells["POS_UST"].Value);
error = m_com.AddPositionToReceipt(cashbox, position, position_vat, transactionNumber);
// Rechnung abschließen
DSFinVK.BonKopfFinish bonkopfFinish = new DSFinVK.BonKopfFinish();
bonkopfFinish.Z_KASSE_ID = cashbox;
bonkopfFinish.BON_ID = tbBON_ID.Text;
if(!decimal.TryParse(tbUMS_BRUTTO.Text, out bonkopfFinish.UMS_BRUTTO))
{
bonkopfFinish.UMS_BRUTTO = 0.00M;
}
bonkopfFinish.PROCESS_TYPE = "Kassenbeleg-V1";
bonkopfFinish.payment_currencies = new string[1] {"EUR"}
bonkopfFinish.payment_types = new string[1] {"Bar"}
bonkopfFinish.payment_per_currency = new decimal[1] {119.00M}
error = m_com.FinishReceipt(cashbox, bonkopfFinish, transactionNumber);
// Kassenabschluss anlegen über alle noch nicht abgeschlossenen Rechnungen zu dieser Kasse
error = m_com.CreateCashpointClosing(cashbox);
// DSFinV-K-Export
int from = 0;
int to = 10;
var ret = m_com.ExportCSVFiles(from, to, tbSelectedFolder.Text, tbZipName.Text, true, true,
true, true, true, true, true, true,
true, true, true, true,
true, true, true, true, true,
true, true, true);
if (ret == ErrorCode.OK)
{
MessageBox.Show("Die CSV Dateien wurden im Ordner " + tbSelectedFolder.Text + " angelegt und in die Zip-Datei " + tbZipName.Text + " gepackt.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Beim exportieren der CSV-Dateien ging etwas schief:\r\n" + ret.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Public xCom As New DSFinVKCom.DSFinVKCom
Dim ret As Long
Public bonkopfBegin As New DSFinVKCom.bonkopfBegin
Public bonkopfFinish As New DSFinVKCom.BonKopfFinishVBA
Public bonpos As New DSFinVKCom.BonPositionVBA
Public bonpos_ust As New DSFinVKCom.BonPosition_UstVBA
Dim transactionNumber As Long
Dim bonId As Long
Dim bonNr As Long
Dim poszeile As Integer
Private Sub btnBeginReceipt_Click()
' zwingend erforderliche Felder:
bonkopfBegin.Z_KASSE_ID = tbCashbox
bonkopfBegin.BON_ID = bonId
bonkopfBegin.BON_NR = bonId
bonkopfBegin.BON_TYP = tbBonTyp
bonkopfBegin.BON_NAME = tbBonName
bonkopfBegin.BON_STORNO = "0"
bonkopfBegin.BEDIENER_ID = tbBedienerId
bonkopfBegin.BEDIENER_NAME = tbBedienerName
tbBonStart = Format(Now(), "yyyy-mm-ddThh:MM:ss")
poszeile = 1
bonkopfBegin.BON_START = tbBonStart
' optionale Felder:
' bonkopfBegin.KUNDE_NAME = tbKundeName
' bonkopfBegin.KUNDE_ID = tbKundeId
' bonkopfBegin.KUNDE_TYP = tbKundeTyp
' bonkopfBegin.KUNDE_USTID = tbKundeUstId
' bonkopfBegin.KUNDE_STRASSE = tbKundeStrasse
' bonkopfBegin.KUNDE_PLZ = tbKundePlz
' bonkopfBegin.KUNDE_ORT = tbKundeOrt
' bonkopfBegin.KUNDE_LAND = tbKundeLand
ret = xCom.BeginReceipt(tbCashbox, bonkopfBegin, transactionNumber)
If ret <> 0 Then
MsgBox ("Es ist ein Fehler aufgetreten! ErrorCode = " + Str$(ret))
Else
tbTransNr = transactionNumber
End If
End Sub
Private Sub btnCashpointClosing_Click()
ret = xCom.CreateCashpointClosing(tbCashbox)
If ret = 0 Then
MsgBox ("DSFinVK Kassenabschluss wurde durchgeführt!")
Else
MsgBox ("DSFinVK Kassenabschluss wurde NICHT durchgeführt!!! ErrorCode = " + Str$(ret))
End If
End Sub
Private Sub btnExport_Click()
ret = xCom.ExportCSVFiles(tbCashbox, 1, 1000, tbExportFolder, tbExportZipFile, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True)
If ret = 0 Then
MsgBox ("DSFinVK Export wurde durchgeführt!")
Else
MsgBox ("DSFinVK Export wurde NICHT durchgeführt!!! ErrorCode = " + Str$(ret))
End If
End Sub
Private Sub btnFinishReceipt_Click()
bonkopfFinish.Z_KASSE_ID = tbCashbox
bonkopfFinish.BON_ID = tbBonId
bonkopfFinish.PROCESS_TYPE = "Kassenbeleg-V1"
tbUmsBrutto = 100.45
tbBonEnde = Format(Now(), "yyyy-mm-ddThh:MM:ss")
bonkopfFinish.BON_ENDE = tbBonEnde
ret = bonkopfFinish.AddPayment("EUR", "Bar", tbUmsBrutto)
ret = xCom.FinishReceiptVBA(tbCashbox, bonkopfFinish, tbTransNr)
If ret <> 0 Then
MsgBox ("Es ist ein Fehler aufgetreten! ErrorCode = " + Str$(ret))
Else
MsgBox ("Die Rechnung wurde abgeschlossen.")
End If
Dim transactionNumber As String
Dim serialNumber As String
Dim signature As String
Dim transactionStart As Date
Dim transactionFinish As Date
Dim sigCounter As String
ret = xCom.GetLastReceiptValues(transactionNumber, serialNumber, signature, transactionStart, transactionFinish, sigCounter)
tbOutTransNr = transactionNumber
tbOutSerialNr = serialNumber
tbOutSignature = signature
tbOutStart = transactionStart
tbOutFinish = transactionFinish
tbOutSigCounter = sigCounter
Dim qrCodeContent As String
ret = xCom.GetLastReceiptQrCodeContent(qrCodeContent)
tbOutQrCodeContent = qrCodeContent
Dim qrCodeBase64 As String
ret = xCom.GetLastReceiptQrCode(qrCodeBase64, "image/bmp")
If ret <> 0 Then
MsgBox ("Es ist ein Fehler aufgetreten! ErrorCode = " + Str$(ret))
Else
tbQrCodeBase64 = qrCodeBase64
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim fileStream As TextStream
Set fileStream = fso.CreateTextFile("D:\IMAGE.bmp")
fileStream.Write (Base64Decode(qrCodeBase64))
Call fileStream.Close
pbQrCode.Picture = "D:\IMAGE.bmp"
End If
End Sub
Private Sub btnInit_Click()
ret = xCom.InitializeLibrary(tbDatabase, "Administrator", "test", tbCashbox)
If ret = 0 Then
MsgBox ("DSFinVK Bibliothek wurde initialisiert!")
Else
MsgBox ("DSFinVK Bibliothek wurde NICHT initialisiert. ErrorCode = " + Str$(ret))
End If
End Sub
Private Sub btnNewIDs_Click()
ret = xCom.GetNextBON_ID(tbCashbox, bonId)
If ret <> 0 Then
MsgBox ("DSFinVK Bibliothek wurde initialisiert! ErrorCode = " + Str$(ret))
Else
tbBonId = bonId
End If
ret = xCom.GetNextBON_NR(tbCashbox, bonNr)
If ret <> 0 Then
MsgBox ("DSFinVK Bibliothek wurde initialisiert! ErrorCode = " + Str$(ret))
Else
tbBonNr = bonNr
End If
End Sub
Private Sub btnNewPosition_Click()
bonpos.ART_NR = "ART 001"
bonpos.ARTIKELTEXT = "ARTIKEL 001"
bonpos.BON_ID = tbBonId
bonpos.EINHEIT = "STK"
bonpos.FAKTOR = "1"
bonpos.GTIN = ""
bonpos.GV_NAME = ""
bonpos.GV_TYP = "Umsatz"
bonpos.INHAUS = "1"
bonpos.MENGE = "1"
bonpos.P_STORNO = "0"
bonpos.POS_ZEILE = poszeile
bonpos.STK_BR = "100.45"
bonpos.Z_KASSE_ID = tbCashbox
bonpos_ust.BON_ID = tbBonId
bonpos_ust.UST_SCHLUESSEL = 1
bonpos_ust.POS_NETTO = "10"
bonpos_ust.POS_UST = "1,9"
bonpos_ust.POS_BRUTTO = "11,9"
bonpos_ust.POS_ZEILE = poszeile
poszeile = poszeile + 1
ret = xCom.AddPositionToReceiptVBA(tbCashbox, bonpos, bonpos_ust, tbTransNr)
If ret <> 0 Then
MsgBox ("DSFinVK Bibliothek wurde initialisiert! ErrorCode = " + Str$(ret))
End If
End Sub
' Decodes a base-64 encoded string (BSTR type).
' 1999 – 2004 Antonin Foller, http://www.motobit.com
' 1.01 – solves problem with Access And 'Compare Database' (InStr)
Function Base64Decode(ByVal base64String)
'rfc1521
'1999 Antonin Foller, Motobit Software, http://Motobit.cz
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim dataLength, sOut, groupBegin
'remove white spaces, If any
base64String = Replace(base64String, vbCrLf, "")
base64String = Replace(base64String, vbTab, "")
base64String = Replace(base64String, " ", "")
'The source must consists from groups with Len of 4 chars
dataLength = Len(base64String)
If dataLength Mod 4 <> 0 Then
Err.Raise 1, "Base64Decode", "Bad Base64 string."
Exit Function
End If
' Now decode each group:
For groupBegin = 1 To dataLength Step 4
Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
' Each data group encodes up To 3 actual bytes.
numDataBytes = 3
nGroup = 0
For CharCounter = 0 To 3
' Convert each character into 6 bits of data, And add it To
' an integer For temporary storage. If a character is a '=', there
' is one fewer data byte. (There can only be a maximum of 2 '=' In
' the whole string.)
thisChar = Mid(base64String, groupBegin + CharCounter, 1)
If thisChar = "=" Then
numDataBytes = numDataBytes – 1
thisData = 0
Else
thisData = InStr(1, Base64, thisChar, vbBinaryCompare) – 1
End If
If thisData = -1 Then
Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
Exit Function
End If
nGroup = 64 * nGroup + thisData
Next
'Hex splits the long To 6 groups with 4 bits
nGroup = Hex(nGroup)
'Add leading zeros
nGroup = String(6 – Len(nGroup), "0") & nGroup
'Convert the 3 byte hex integer (6 chars) To 3 characters
pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 5, 2)))
'add numDataBytes characters To out string
sOut = sOut & Left(pOut, numDataBytes)
Next
Base64Decode = sOut
End Function
Hauptstraße 85
A-7361 Frankenau-Unterpullendorf