Registriert seit: 15. Mär 2005
672 Beiträge
FreePascal / Lazarus
|
AW: Bon Drucker ansteuern
30. Jul 2010, 09:30
ich hab hier mal aus einem ca 10 Jahren alten Quellcode einen Teil extrahiert, der noch heute im Einsatz ist mit einem Epson TM88 (ist ziemlich ähnlich, nur mit Parallelport).
Das ist nicht schön, aber läuft und sollte alles können was du angefragt hast, schneiden geht mit printer.NewPage; oder printer.Enddoc; Falls nicht ist irgendwas im Treiber nicht korrekt eingestellt.
Gruß
Holger
www.ibexpert.com
p.s.: Der langjährige spätabendliche Aufenthalt in Hotelbars und Kneipen nach Konferenzen diente ausschließlich dazu, die Prozesse für dieses Softwareprojekt besser zu verstehen und zu verbessern
Delphi-Quellcode:
procedure Tfrm_kasse.drucke_kundenbeleg(teilrechnung:Boolean);
procedure smm;
begin
setmapmode(printer.Handle,mm_lometric);
printer.Canvas.Font.Name:='Arial';
printer.Canvas.Font.Height:=45;
end;
var p,i:integer;
s,beleg_id:string;
sum:Double;
tbl,tblp:TIBOTable;
seite:integer;
procedure printkopf;
begin
p:=-10;
smm;
s:=ini.ReadString('ADR','NAME1','INIFILE.NAME1');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME2','INIFILE.NAME2');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME3','INIFILE.NAME3');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME4','INIFILE.NAME4');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME5','');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME6','');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME7','');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:=ini.ReadString('ADR','NAME8','');
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='Rechnung vom '+dateToStr(date);
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='Tisch:'+tbl_tisch.FieldByName('bez').AsString+':'+tbl_tisch.FieldByName('bezeichnung').AsString;
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='Belegnr:'+tbl.FieldByName('NR').AsString;
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
end;
begin
seite:=1;
if teilrechnung
then
begin
tbl:=tbl_beleg2;
tblp:=tbl_beleg_positionen2;
end
else
begin
tbl:=tbl_beleg;
tblp:=tbl_beleg_positionen;
end;
tbl.refresh;
tblp.refresh;
beleg_id:=tbl.FieldByName('id').AsString;
qry.SQL.Text:='select bez,bezeichnung,einzelpreis,sum(anzahl) as anzahl from beleg_positionen where beleg_id='+beleg_id+' group by bez,bezeichnung,einzelpreis';
qry.Open;
if qry.RecordCount>=8 then
begin
printer.begindoc;
p:=-10;
while not qry.eof do
begin
if p<-2500
then
begin
printer.NewPage;
smm;
p:=100;
end;
smm;
printer.Canvas.TextOut(10,p,qry.FieldByName('anzahl').AsString);
smm;
printer.Canvas.TextOut(60,p,qry.FieldByName('bezeichnung').AsString);
smm;
s:=floattostrf(qry.FieldByName('Einzelpreis').Asfloat,fffixed,15,2);
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
p:=p-100;
qry.Next;
end;
printer.Canvas.TextOut(390,p-200,'-');
printer.enddoc;
end;
qry.Close;
printer.begindoc;
tblp.First;
printkopf;
p:=p-50;
sum:=0;
while not tblp.eof do
begin
if p<-2500
then
begin
smm;
p:=p-50;
printer.Canvas.TextOut(350,p,'-'+inttostr(seite)+'-');
printer.NewPage;
seite:=seite+1;
smm;
printkopf;
p:=p-50;
printer.Canvas.TextOut(350,p,'-'+inttostr(seite)+'-');
end;
p:=p-50;
smm;
printer.Canvas.TextOut(10,p,tblp.FieldByName('anzahl').AsString);
smm;
printer.Canvas.TextOut(60,p,tblp.FieldByName('bezeichnung').AsString);
smm;
s:=floattostrf(tblp.FieldByName('Einzelpreis').Asfloat,fffixed,15,2);
printer.Canvas.TextOut(580-printer.Canvas.textwidth(s),p,s);
smm;
s:=floattostrf(tblp.FieldByName('Einzelpreis').Asfloat*tblp.FieldByName('anzahl').AsFloat,fffixed,15,2);
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
sum:=sum+tblp.FieldByName('Einzelpreis').Asfloat*tblp.FieldByName('anzahl').AsFloat;
tblp.Edit;
tblp.FieldByName('status').AsString:='R';
tblp.post;
tblp.Next;
end;
p:=p-50;
printer.Canvas.TextOut(10,p,'----------------------------------------------------');
p:=p-50;
printer.Canvas.TextOut(10,p,'SUMME');
s:=floattostrf(sum,fffixed,15,2)+'€';
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
smm;
p:=p-50;
p:=p-50;
p:=p-50;
qry2.Close;
qry2.sql.Text:='select '+#13#10+
' case b.ah '+#13#10+
' when ''J'' then cast(a.ust_ah as numeric(18,2)) '+#13#10+
' when ''N'' then cast(a.ust_ih as numeric(18,2)) '+#13#10+
' end Mwst, '+#13#10+
' sum(cast(bp.einzelpreis*bp.anzahl as numeric(18,2))) brutto, '+#13#10+
' sum(case b.ah '+#13#10+
' when ''J'' then cast((bp.einzelpreis*bp.anzahl)*100/(100+a.ust_ah) as numeric(18,2)) '+#13#10+
' when ''N'' then cast((bp.einzelpreis*bp.anzahl)*100/(100+a.ust_ih) as numeric(18,2)) '+#13#10+
' end) netto, '+#13#10+
' sum(case b.ah '+#13#10+
' when ''J'' then cast((bp.einzelpreis*bp.anzahl)*a.ust_ah/(100+a.ust_ah) as numeric(18,2)) '+#13#10+
' when ''N'' then cast((bp.einzelpreis*bp.anzahl)*a.ust_ih/(100+a.ust_ih) as numeric(18,2)) '+#13#10+
' end) Steuer '+#13#10+
' from beleg b '+#13#10+
' join beleg_positionen bp on bp.beleg_id=b.id '+#13#10+
' join artikel a on a.id=bp.artikel_id '+#13#10+
' where '+#13#10+
' b.id='+tbl_beleg.fieldbyname('ID').AsString+#13#10+
' group by 1';//hk
s:='Mwst %';
printer.Canvas.TextOut(200-printer.Canvas.textwidth(s),p,s);
s:='Summe';
printer.Canvas.TextOut(370-printer.Canvas.textwidth(s),p,s);
s:='Netto';
printer.Canvas.TextOut(540-printer.Canvas.textwidth(s),p,s);
s:='Mwst';
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
smm;
p:=p-50;
qry2.open;
while not qry2.Eof do
begin
s:=floattostrf(qry2.Fields[0].AsFloat,fffixed,15,2)+'%';
printer.Canvas.TextOut(200-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[1].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(370-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[2].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(540-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[3].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
smm;
p:=p-50;
qry2.Next;
end;
qry2.Close;
if MessageDlg('ohne Bewirtungsbeleg?',mtConfirmation,[mbYes,mbNo],0)=mrNo then
begin
printer.NewPage;
printkopf;
p:=p-50;
smm;
s:='Bewirtungsaufwand Angaben';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='(Par. 4, Abs. 5, Ziff. 2 EkStg)';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
s:='Mwst %';
printer.Canvas.TextOut(200-printer.Canvas.textwidth(s),p,s);
s:='Summe';
printer.Canvas.TextOut(370-printer.Canvas.textwidth(s),p,s);
s:='Netto';
printer.Canvas.TextOut(540-printer.Canvas.textwidth(s),p,s);
s:='Mwst';
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
smm;
p:=p-50;
qry2.open;
while not qry2.Eof do
begin
s:=floattostrf(qry2.Fields[0].AsFloat,fffixed,15,2)+'%';
printer.Canvas.TextOut(200-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[1].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(370-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[2].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(540-printer.Canvas.textwidth(s),p,s);
s:=floattostrf(qry2.Fields[3].AsFloat,fffixed,15,2)+'€';
printer.Canvas.TextOut(710-printer.Canvas.textwidth(s),p,s);
smm;
p:=p-50;
qry2.Next;
end;
qry2.Close;
p:=p-50;
smm;
s:='';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
smm;
s:='Tip:';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Gesamt:';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Unterschrift Kellner';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Bewirtete Personen';
printer.Canvas.TextOut(20,p,s);
for i:=1 to 4 do
begin
p:=p-50;
smm;
s:='';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
end;
p:=p-50;
smm;
s:='Anlass der Bewirtung';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Höhe der Aufwendungen';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='bei Bewirtung im Restaurant';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='in anderen Fällen';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Ort Datum';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
p:=p-50;
smm;
s:='Unterschrift';
printer.Canvas.TextOut(20,p,s);
p:=p-100;
smm;
s:='..........................................................';
printer.Canvas.TextOut(20,p,s);
end;
p:=p-50;
s:='Vielen Dank für Ihren Besuch !';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
p:=p-50;
s:='Beehren Sie uns recht bald wieder !';
printer.Canvas.TextOut(390-round(printer.Canvas.textwidth(s)/2),p,s);
printer.Canvas.TextOut(390,p-200,'-');
printer.enddoc;
if teilrechnung
then
begin
tbl.Edit;
tbl.FieldByName('status').AsString:='1';
tbl.post;
end;
end;
Geändert von mkinzler (30. Jul 2010 um 09:34 Uhr)
Grund: Code-Tag durch Delphi-Tag ersetzt
|