1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
const
escNewLine = AnsiChar(10); // New line (LF line feed)
escUnerlineOn = AnsiChar(27) + AnsiChar(45) + AnsiChar(1); // Unerline On
escUnerlineOnx2 = AnsiChar(27) + AnsiChar(45) + AnsiChar(2); // Unerline On x 2
escUnerlineOff = AnsiChar(27) + AnsiChar(45) + AnsiChar(0); // Unerline Off
escBoldOn = AnsiChar(27) + AnsiChar(69) + AnsiChar(1); // Bold On
escBoldOff = AnsiChar(27) + AnsiChar(69) + AnsiChar(0); // Bold Off
escNegativeOn = AnsiChar(29) + AnsiChar(66) + AnsiChar(1); // White On Black On'
escNegativeOff = AnsiChar(29) + AnsiChar(66) + AnsiChar(0); // White On Black Off
esc8CpiOn = AnsiChar(29) + AnsiChar(33) + AnsiChar(16); // Font Size x2 On
esc8CpiOff = AnsiChar(29) + AnsiChar(33) + AnsiChar(0); // Font Size x2 Off
esc16Cpi = AnsiChar(27) + AnsiChar(77) + AnsiChar(48); // Font A - Normal Font
esc20Cpi = AnsiChar(27) + AnsiChar(77) + AnsiChar(49); // Font B - Small Font
escReset = AnsiChar(27) + AnsiChar(64); //AnsiChar(27) + AnsiChar(77) + AnsiChar(48); // Reset Printer
escFeedAndCut = AnsiChar(29) + AnsiChar(86) + AnsiChar(65)+ AnsiChar(20); // Partial Cut and feed
escFormFeed = AnsiChar(12);
escAlignLeft = AnsiChar(27) + AnsiChar(97) + AnsiChar(0); // Align Text to the Left (ancien 48)
escAlignCenter = AnsiChar(27) + AnsiChar(97) + AnsiChar(1); // Align Text to the Center
escAlignRight = AnsiChar(27) + AnsiChar(97) + AnsiChar(2); // Align Text to the Right
gsFeedandCut = AnsiChar(29) + AnsiChar(86) + AnsiChar(48) ;
...
procedure TDatas.EnteteTicket(const Hprinter : THandle; var D : TDateTime; const NoTicket : String = '0');
var LogoFileName,s : String;
Sl : TStringList;
i : integer;
dwBytesWritten: DWord;
DocumentDataAnsi: AnsiString;
begin
if d=0 then d:=now;
s:=ligne(nbcticket,'',Noticket);
s:=ligne(nbcticket,s,formatdateTime('dd/mm/yy hh:nn',D),TAlignLayout.Right);
DocumentDataAnsi:=esc16cpi+escAlignLeft+AnsiString(s)+escNewLine;
WritePrinter(hPrinter, @DocumentDataAnsi[1],Length(DocumentDataAnsi),dwBytesWritten);
LogoFileName:=System.IOUtils.TPath.Combine(Datas.parametres.DepotPref,'Logo.txt');
Sl:=TStringList.Create;
try
sl.LoadFromFile(LogoFileName);
for i:=0 to sl.Count-1 do
begin
if i=0 then DocumentDataAnsi:=esc16cpi+escAlignLeft+escBoldOn+AnsiString(sl[i])+escboldoff+escnewline
else DocumentDataAnsi := esc20Cpi+AnsiString(sl[i])+escNewLine;
WritePrinter(hPrinter, @DocumentDataAnsi[1],Length(DocumentDataAnsi),dwBytesWritten);
end;
finally
sl.Free;
end;
// ligne vide
DocumentDataAnsi := esc20Cpi+escNewLine;
WritePrinter(hPrinter, @DocumentDataAnsi[1],Length(DocumentDataAnsi),dwBytesWritten);
end;
procedure TDatas.imprimerticket(const numero : integer=0);
var hPrinter: THandle;
DocInfo: TDocInfo1;
dwBytesWritten: DWord;
DocumentDataAnsi: AnsiString;
s : string;
d : tdateTime;
total,tva : currency;
{$IFDEF DEBUG}F : TextFile; {$ENDIF}
begin
total:=0;
tva:=0;
fdlignesTicket.Open('',[numero]);
fdLignesTicket.First;
{$IFDEF DEBUG}
AssignFile(f,'ticket'+numero.ToString+'.txt');
rewrite(f);
while not fdLignesTicket.eof do
begin
if FDLignesTicketSOLDE.AsString='N' then s:=' ' else s:=AnsiChar(169);
s:=ligne(nbcticket,'',format('%s%s-%s %s',[s,fdLignesTicketMODELE.asString,
fdLignesTicketASSORTIMENT.asString,
fdLignesTicketPOINTURE.asString]));
s:=Ligne(nbcticket,s,Format('%3.2f',[fdlignesTicketPRIX_TTC.asCurrency]),TalignLayout.Right);
Writeln(f,s);
s:=AnsiString(' '+fdlignesTicketDESCRIPTION.asString);
Writeln(f,s);
if FDLignesTicketMNT_REMISE.AsCurrency>0 then
begin
s:=Ligne(nbcticket,'',Format('Remise -%3.2f',[fdlignesTicketMNT_REMISE.asCurrency]),TalignLayout.Right);
writeln(f,s);
end;
writeln(f,'');
total:=total+fdlignesTicketPRIX_TTC.asCurrency-fdlignesTicketMNT_REMISE.asCurrency;
tva:=tva+FDLignesTicketTVA.AsCurrency;
fdlignesTicket.Next;
end;
s:=ligne(nbcticket,'',format('TOTAL %7.2f',[total]),TalignLayout.Right);
writeln(f,s);
s:=ligne(nbcticket,'',format('Dont T.V.A %7.2f',[tva]),TalignLayout.Right);
writeln(f,s);
Closefile(f);
{$ELSE}
OpenPrinter(PChar(parametres.Imprimante), hPrinter, nil);
DocInfo.pOutputFile:= nil;
DocInfo.pDatatype:= 'RAW';
DocInfo.pDocName:= PChar('Ticket '+Numero.ToString);
StartDocPrinter(hPrinter, 1, @DocInfo);
StartPagePrinter(hPrinter);
if fdLignesTicketDATE_VENTE.IsNull
then d:=now
else d:=fdLignesTicket.FieldByName('DATE_VENTE').AsDateTime;
EnteteTicket(hprinter,d,numero.ToString);
{ imprimer lignes}
while not fdLignesTicket.eof do
begin
if FDLignesTicketSOLDE.AsString='N' then s:=' ' else s:=AnsiChar(169);
s:=ligne(nbcticket,'',format('%s%s-%s %s',[s,fdLignesTicketMODELE.asString,
fdLignesTicketASSORTIMENT.asString,
fdLignesTicketPOINTURE.asString]));
s:=Ligne(nbcticket,s,Format('%3.2f',[fdlignesTicketPRIX_TTC.asCurrency]),TalignLayout.Right);
DocumentDataAnsi:=escAlignLeft+esc20cpi+AnsiString(s)+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
// DocumentDataAnsi := esc20Cpi+escAlignRight+System.AnsiStrings.Format('%3.2f',[fdlignesTicketPRIX_TTC.asCurrency])+escNewLine;
// WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
DocumentDataAnsi := esc20Cpi+escAlignLeft+AnsiString(' '+fdlignesTicketDESCRIPTION.asString)+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
if FDLignesTicketMNT_REMISE.AsCurrency>0 then
begin
s:=Ligne(nbcticket,'',Format('Remise -%3.2f',[fdlignesTicketMNT_REMISE.asCurrency]),TalignLayout.Right);
DocumentDataAnsi := esc20Cpi+escAlignLeft+AnsiString(s)+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
end;
DocumentDataAnsi :=escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
total:=total+fdlignesTicketPRIX_TTC.asCurrency-fdlignesTicketMNT_REMISE.asCurrency;
tva:=tva+fdlignesTicketTVA.asCurrency;
fdlignesTicket.Next;
end;
DocumentDataAnsi := esc20Cpi+escAlignRight+AnsiString(StringofChar('-',20))+escNewLine+escAlignLeft;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
s:=ligne(nbcticket,'',format('TOTAL %7.2f',[total]),TalignLayout.Right);
documentDataAnsi := esc16Cpi+escBoldOn+escAlignCenter+AnsiString(s)+escboldoff+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
s:=ligne(nbcticket,'',format('Dont T.V.A %7.2f',[tva]),TalignLayout.Right);
documentDataAnsi := esc16Cpi+escAlignCenter+AnsiString(s)+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
documentDataAnsi := escNewLine+escNewLine;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
DocumentDataAnsi := escFeedAndCut;
WritePrinter(hPrinter,@DocumentDataAnsi[1],length(DocumentDataAnsi),dwBytesWritten);
DocumentDataAnsi :=chr(13);
WritePrinter(hPrinter,@DocumentDataAnsi[1],1,dwBytesWritten);
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
{$ENDIF}
end; |
Partager