Registriert seit: 29. Dez 2006
Ort: NRW
854 Beiträge
Delphi 12 Athens
|
AW: FastReport TfrxUserDataSet Summe ziehen
18. Feb 2025, 17:56
Hallo Zusammen,
ist die Frage schlecht erklärt oder so einfach?
Ich habe leider kein Beispiel im Internet oder im Handbuch für TfrxUserDataSet gefunden...
Ich habe es, damit ich weiterkomme, jetzt so gelöst, aber schön ist etwas anderes...
Delphi-Quellcode:
procedure TForm1.btnCreateLabel1Click(Sender: TObject);
var Rprt: TfrxReport;
frxData: TfrxComponent;
begin
Rprt:= TfrxReport.Create(nil);
JsDataProforma:= TJSONArray.Create;
Try
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "1","description": "Paket englisch", "price": "20,50", "mwst": "0,19"}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "1","description": "Paket französisch", "price": "25,50", "mwst": "0,19"}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "1","description": "Paket deutsch", "price": "30,50", "mwst": "0,19"}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
JsDataProforma.AddElement(TJSONObject.ParseJSONValue('{"qty": "","description": "", "price": "", "mwst": ""}') as TJSONObject);
frxDataSet.RangeBegin:= rbFirst;
frxDataSet.RangeEnd:= reCount;
frxDataSet.RangeEndCount:= JsDataProforma.Count;
Rprt.OnGetValue:= frxRprtProformaOnGetValue;
Rprt.LoadFromFile(extractfilepath(paramstr(0)) + '.\Res\Test.fr3');
frxData:= Rprt.FindObject('DataItems');
(frxData as Tfrxmasterdata).DataSet:= frxDataSet;
Rprt.ShowReport(True);
Finally
Rprt.Free;
End;
end;
Und im OnGetValue dann wild herumgestrikt...
Delphi-Quellcode:
procedure TForm1.frxRprtProformaOnGetValue(const VarName: string; var Value: Variant);
var JsData, JsPrewData: TJSONObject;
qtyValue, totalValue, priceValue, nettoKum, mwstKum, bruttoKum, mwst: string;
begin
if JsDataProforma.Items[frxDataSet.RecNo] is TJSONObject then begin
JsData:= TJSONObject(JsDataProforma.Items[frxDataSet.RecNo]);
if frxDataSet.RecNo = 0 then begin
nettoKum:= '0';
bruttoKum:= '0'; //Immer nettoKum * mitgeliefertem MwSt-Satz
mwstKum:= '0';
end
else begin
JsPrewData:= TJSONObject(JsDataProforma.Items[frxDataSet.RecNo -1]);
JsPrewData.TryGetValue<string>('netto', nettoKum);
nettoKum:= StringReplace(nettoKum,' €','',[]);
nettoKum:= StringReplace(nettoKum,'.','',[rfReplaceAll]);
JsPrewData.TryGetValue<string>('mwstKum', mwstKum);
mwstKum:= StringReplace(mwstKum,' €','',[]);
mwstKum:= StringReplace(mwstKum,'.','',[rfReplaceAll]);
JsPrewData.TryGetValue<string>('brutto', bruttoKum);
bruttoKum:= StringReplace(bruttoKum,' €','',[]);
bruttoKum:= StringReplace(bruttoKum,'.','',[rfReplaceAll]);
end;
Value:= JsData.GetValue<string>(VarName);
if VarName = 'price' then begin
Try
if (JsData.TryGetValue<string>('price', priceValue)) and
(JsData.TryGetValue<string>('qty', qtyValue)) and
(StringReplace(priceValue,' ','',[rfReplaceAll]) <> '') and
(StringReplace(qtyValue,' ','',[rfReplaceAll]) <> '') then begin
totalValue:= FloatToStr(StrToFloat(priceValue) * StrToInt(qtyValue));
nettoKum:= FloatToStr(StrToFloat(nettoKum) + StrToFloat(totalValue));
JsData.AddPair('total', Format('%2n',[StrToFloat(totalValue)]) + ' €');
if (JsData.TryGetValue<string>('mwst', mwst)) and
(StringReplace(mwst,' ','',[rfReplaceAll]) <> '') then begin
mwstkum:= FloatToStr(StrToFloat(nettoKum) * StrToFloat(mwst));
bruttoKum:= FloatToStr(StrToFloat(nettoKum) * (1 + StrToFloat(mwst)));
end;
end
else begin
JsData.AddPair('total', '');
end;
if StringReplace(Value,' ','',[rfIgnoreCase, rfReplaceAll]) <> '' then begin
Value:= Value + ' €';
end;
JsData.AddPair('netto', Format('%2n',[StrToFloat(nettoKum)]) + ' €');
JsData.AddPair('brutto', Format('%2n',[StrToFloat(bruttoKum)]) + ' €');
JsData.AddPair('mwstKum', Format('%2n',[StrToFloat(mwstKum)]) + ' €');
if (StringReplace(mwst,' ','',[rfReplaceAll]) = '') then begin //Nur zum Anzeigen unterhalb der Tabelle
JsPrewData.TryGetValue<string>('mwst', mwst);
JsData.RemovePair('mwst');
JsData.AddPair('mwst', mwst);
end;
Except
Value:= '';
End;
end;
end;
end;
Was dann rauskommt sieht so aus, wie in dem Bild.
Vielen Dank
Patrick
Patrick
|