Create a new Beleg from an isolated .NET DLL

pneusoft

Neues Mitglied
What are the options available to create a new receipt from an isolated .NET DLL. I was able to create a new mandant object and also used the DcmContextBelegProxyServiceCall to initialize a beleg. But the BelId is always set to zero. Doesn't Sage automatically create a BelID? Is there any such parameters for it?

Here is what I have tried.

Session session;
Mandant mandant;
session = ApplicationEngine.CreateSession("ccc", ApplicationToken.Abf, null, new NamePasswordCredential("Sage", ""));
mandant = session.CreateMandant(1);
var beleg = new Sagede.OfficeLine.Wawi.BelegEngine.Beleg(mandant, Erfassungsart.Verkauf);
var data = new DataContainer();
var context = new DcmContextBelegProxyServiceCall(beleg, new NamedParameters(), "", data, false);
context.SetSystemContext(DcmDefinitionManager.DcmListId.BelegProxyAfterServiceCall, "VVA", new ParameterBag(), false, mandant);


Does anyone have a working code snippet to create a new beleg using .net library classes. Also, will be same approach be applicable to other objects such as Customers, Adress and so on?

Thanks
 
Hi,
usually I create & initialize a Beleg like that. Don't know whether this applies to your project or not.
Code:
var beleg = new Sagede.OfficeLine.Wawi.BelegEngine.Beleg(mandant, Erfassungsart.Verkauf);
beleg.Initialize("VVA", DateTime.Now, (short)DateTime.Now.Year);
Afterwards, beleg.Handle (aka BelID) is 0 until it is saved. But even before saving, beleg.HandleNew contains its "future BelID" given by Sage BelegEngine.
Code:
if (beleg.Handle == 0 && beleg.HandleNew != 0)
{
      // do nothing - everything alright
}
if (beleg.Calculate(true) && beleg.Validate()) beleg.Save(true);

You need a different approach for customers, adresses, etc.; afaik the classes in Sagede.OfficeLine.Data.Entities.Main.
 
Zuletzt bearbeitet:
Thanks fotr the reply.
I have tried your solution. But it is not able to create receipt. Here is my code.

Code:
 session session;
            Client client;
            session = ApplicationEngine.CreateSession ("xxxx", ApplicationToken.Abf, null, new NamePasswordCredential ("Sage", ""));
            client = session.CreateMandant (1);
            var beleg = new Sagede.OfficeLine.Wawi.BelegEngine.Beleg (client, entry type.sale);
            var olderDate = new DateTime (2020, 8, 23);
            beleg.Initialize ("VVA", olderDate, (short) olderDate.Year);
            if (! beleg.SetKonto ("D100000", false))
            {
                beleg.Errors.AppendErrorWithSource (0, "Customer Invalid", "A0Konto");
            }
            var position = new Sagede.OfficeLine.Wawi.BelegEngine.BelegPosition (beleg);
         
            position.Initialize (position type.Article);
            position.SetArtikel ("0101940750162050001", 0);
            position.quantity = 1;
            position.RefreshBasis Amount (true, 2);
            position.Calculate ();
            beleg.Positionen.Add (position);
            if (occupied.Handle == 0 && occupied.HandleNew! = 0)
            {
                // do nothing - everything alright
            }
            if (beleg.Calculate (true) && beleg.Validate ())
            {
                var state = occupancy. Save (false);
            }


This is error message i get from beleg.Errors object =
Error in the sales receipt entry
An error occurred while saving the receipt.

I tried to run the SQL profiler against the Sage db and found that the insert statement fails.
Error converting data type varchar to datetime.

Did you have to manually set the Datetime format on SQL while creating vouchers? Have you come across this issue?
PS, I am running an English Localized Machine. We have also tested it on an German Localized Machine
Thanks
 
Zuletzt bearbeitet:
Hmm, I don't remember issues with those formats - but I work on german localized machines only, so maybe there is some problem. As you mention having tested it on a german localized machine: did you use german localization on all three relevant systems (client, application server and database server)?
 
Zurück
Oben