// Export Debitoren.csv
// nachbearbeiteter Code
// s.a. 2024-08-16
using craftsReport.Interfaces;

namespace craftsReport.modules
{
	public class rkddat_xbs : IReportModule
	{
		public IReportHost HostObject { set; get; }

		public rkddat_xbs()
		{
		}

		// Debitorenausgabe
		public bool Execute()
		{
			HostObject.DefineRecord("Dest", "ADRESSSTAMM", 0, 0, HostObject.EvalString(@""));

			SUB_subKopfZeile();
			while(!HostObject.TestEof("Dest"))
			{
				SUB_DestLoop();
				HostObject.SkipRecord("Dest");
			}

			return true;
		}

		bool SUB_DestLoop()
		{
			if (HostObject.CompareString("Dest.FIBUKONTO", "<", HostObject.EvalString(@"10000          ")))
				return true;
			if (HostObject.CompareString("Dest.FIBUKONTO", ">", HostObject.EvalString(@"59999          ")))
				return true;

			SUB_subDestZeile();
			return true;
		}

		bool SUB_subKopfZeile()
		{
			HostObject.WriteLine("Konto;Name1;Name2;;UStId;Strasse;;Plz;Ort;;;;;Telefon1;Fax;;;;;;;;;;;;;;;;;");
			return true;
		}

		bool SUB_subDestZeile()
		{
			HostObject.WriteLine(HostObject.EvalString(@"$[Dest.FIBUKONTO];$[Dest.NAME1];$[Dest.NAME2];;$[Dest.UstId1];$[Dest.STRASSE];;$[Dest.PLZ<5];$[Dest.ORT];;;;;$[Dest.TELEFON1];$[Dest.FaxNummer];;;;;;;;;;;;;;;;;"));
			return true;
		}
	}
}
