Skip to content

Instantly share code, notes, and snippets.

@IlyasDeckers
Last active February 11, 2021 08:34
Show Gist options
  • Save IlyasDeckers/9b0aa5817d2f13a9808af7339fac0400 to your computer and use it in GitHub Desktop.
Save IlyasDeckers/9b0aa5817d2f13a9808af7339fac0400 to your computer and use it in GitHub Desktop.
Venice SDK

Zoals gevraagd vind u hier de de code die gebruikt word om de aankoopfacturen op te vragen. Dit staat ondertussen al meer dan 3 jaar in productie zonder problemen, alles is begonnen wanneer we een nieuw boekjaar (2021) hebben aangemaakt.

Uitleg over de code

PurchaseModule.cs
Hier worden de HTTP requests afgehandeld en word FindPurchaseById aangesproken om de aankoop factuur op te halen.

Purchase.cs
Het purchase model.

SDK.cs
Hier bevind zich de methode FindPurchaseById.

Indien nodig kan ik nog enkele andere classes toevoegen aan dit document die gebruikt worden voor authenticatie en om het project te bootstrappen, maar deze lijken mij hier overbodig.

Voorbeeld van requests

Een factuur opvragen uit het nieuwe boekjaar (AKP1, doc_num 26) werkt perfect.

curl https://d3venice.3d-apps.be/venice/purchases/2021/AKP1/26

{
   "doc_num":26,
   "sup_num":197,
   "sys_num":"319",
   "book":"AKP1",
   "exp_date":"1/19/2021 12:00:00 AM",
   "doc_date":"1/9/2021 12:00:00 AM",
   "book_date":"1/31/2021 12:00:00 AM",
   "is_ticked":true,
   "doc_type":0,
   "remark":"",
   "totalDocC":-185.51,
   "tsm_num":"710145418788",
   "vat_0":0.0,
   "vat_6":0.0,
   "vat_12":0.0,
   "normalDetail4DocC":-153.31,
   "vatDedInvNormDocC":-32.2,
   "reference":"",
   "baseNormalDocC":-153.31,
   "baseIcServicesDocC":0.0,
   "vatDueInvIcDocC":0.0,
   "vatDueCreNormDocC":0.0,
   "pdf":null,
   "pdfName":null,
   "details":null
}

Een aankoop factuur opvragen uit 2020 dat niet overgedragen is naar 2021. Hier ziet u dat alle waardes terugkomen als 0 of als null.

curl https://d3venice.3d-apps.be/venice/purchases/2020/AKP09/40
[
     "doc_num" => 0,
     "sup_num" => 0,
     "sys_num" => null,
     "book" => null,
     "exp_date" => null,
     "doc_date" => null,
     "book_date" => null,
     "is_ticked" => false,
     "doc_type" => 0,
     "remark" => null,
     "totalDocC" => 0.0,
     "tsm_num" => null,
     "vat_0" => 0.0,
     "vat_6" => 0.0,
     "vat_12" => 0.0,
     "normalDetail4DocC" => 0.0,
     "vatDedInvNormDocC" => 0.0,
     "reference" => null,
     "baseNormalDocC" => 0.0,
     "baseIcServicesDocC" => 0.0,
     "vatDueInvIcDocC" => 0.0,
     "vatDueCreNormDocC" => 0.0,
     "pdf" => null,
     "pdfName" => null,
     "details" => null,
   ]

Als ik hetzelfde factuur opvraag uit onze testomgeving voor het nieuwe boekjaar is aangemaakt komt dit wel juist terug, nadat ik een nieuw boekjaar aanmaak faalt het terug. Als ik een backup uit productie gebruik nadat 2021 is aangemaakt, de named database schrap en opnieuw aanmaak, dan komt dit factuur ook juist terug. Doe ik deze stappen in productie lost dit niets op. (Laurent heeft dit ook geprobeerd na enkele SQL errors)

Als ik een factuur opvraag in de gui van Venice of via een query in PSQL word de data gevonden. Het probleem doet zich enkel voor bij het opvragen van het factuur via de SDK.

Het enige grote verschil tussen de testomgeving en productie omgeving is dat de PSQL versie verschilt. (v14 test, v11 prod)

Hieruit concludeer ik dat er echt iets mis is met de data in onze Venice installatie na het aanmaken van het nieuwe boejaar, we zitten hier al weken op te zoeken zonder enig resultaat. Indien nodig kan ik enkele test cases opmaken die het probleem zeer duidelijk illustreren met een demonstratie van wat er hier is uitgelegd.

UPDATE: In de testomgeving waren de problemen met aankoopfacturen initieel ook met de backup uit productie. ODBC gaf de melding de huidige inhoud van de named database kon niet bepaald worden. Na het schrappen van de named database en het opnieuw aanmaken was dit opgelost. Als ik het dossier verwijder en de backup terugplaats is komen de aankoopfacturen nog juist terug.

Als venice volledig word verwijderd en opnieuw word geinstalleerd geeft ODBC terug de melding de huidige inhoud van de named database kon niet bepaald worden, maar de aankoopfacturen komen wel juist terug. De problematiek valt niet meer te hercreeeren in de testomgeving...

using Newtonsoft.Json;
using System.Collections.Generic;
namespace VeniceWebConnect.Models
{
public class Purchase
{
[JsonProperty("doc_num")]
public int pDocNum { get; set; }
[JsonProperty("sup_num")]
public int pSupNum { get; set; }
[JsonProperty("sys_num")]
public string pSysNum { get; set; }
[JsonProperty("book")]
public string pBook { get; set; }
[JsonProperty("exp_date")]
public string pExpDate { get; set; }
[JsonProperty("doc_date")]
public string pDocDate { get; set; }
[JsonProperty("book_date")]
public string pBookDate { get; set; }
[JsonProperty("is_ticked")]
public bool pIsTicked { get; set; }
[JsonProperty("doc_type")]
public int pDocType { get; set; }
[JsonProperty("remark")]
public string pRemark { get; set; }
[JsonProperty("totalDocC")]
public double pTotalDocC { get; set; }
[JsonProperty("tsm_num")]
public string pTsmNumber { get; set; }
[JsonProperty("vat_0")]
public double pNormalDetail1DocC { get; set; }
[JsonProperty("vat_6")]
public double pNormalDetail2DocC { get; set; }
[JsonProperty("vat_12")]
public double pNormalDetail3DocC { get; set; }
[JsonProperty("normalDetail4DocC")]
public double pNormalDetail4DocC { get; set; }
[JsonProperty("vatDedInvNormDocC")]
public double pVatDedInvNormDocC { get; set; }
[JsonProperty("reference")]
public string pSupRef { get; set; }
[JsonProperty("baseNormalDocC")]
public double pBaseNormalDocC { get; set; }
[JsonProperty("baseIcServicesDocC")]
public double pBaseIcServicesDocC { get; set; }
[JsonProperty("vatDueInvIcDocC")]
public double pVatDueInvIcDocC { get; set; }
[JsonProperty("vatDueCreNormDocC")]
public double pVatDueCreNormDocC { get; set; }
[JsonProperty("pdf")]
[VenicePropertyIgnore]
public string pdf { get; set; }
[JsonProperty("pdfName")]
[VenicePropertyIgnore]
public string pdfName { get; set; }
[JsonProperty("details")]
[VenicePropertyIgnore]
public List<PurchaseDetail> details { get; set; }
}
}
using Nancy;
using Nancy.Security;
using Nancy.ModelBinding;
namespace VeniceWebConnect.Modules
{
public class PurchaseModule : NancyModule
{
public PurchaseModule() : base("/venice/purchases")
{
this.RequiresHttps();
this.RequiresAuthentication();
Get["/{year}/{book}/{id}"] = parameters =>
{
Models.Purchase dictionary = null;
using (SDK sdk = new SDK())
{
dictionary = sdk.FindPurchaseById((short)parameters.year, (string)parameters.book, (int)parameters.id);
}
return Response.AsJson(dictionary);
};
}
}
}
using System;
using System.Collections.Generic;
using ClSdk;
namespace VeniceWebConnect
{
public class SDK : IDisposable
{
private bool disposed;
public Venice oVenice { get; set; }
public Dossier oDossier { get; set; }
public Year oYear { get; set; }
public SInvce oSInvce { get; set; }
public Sales oSale { get; set; }
public Purch oPurch { get; set; }
public Custm oCustm { get; set; }
public Suppl oSuppl { get; set; }
// Deze methode word gebruikt om de aankoopfacturen op te vragen.
public Models.Purchase FindPurchaseById(short year, string book, int id)
{
Models.Purchase purchase = new Models.Purchase();
oYear = oDossier.CreateYearContext(year);
oPurch = oYear.CreatePurch(true);
if (!oPurch.SeekByDocNum(eSeekMode.smEqual, year, book, id))
{
throw new Exception("Purchase Not Found");
}
return (Models.Purchase) Util.ObjectToModel(oPurch, purchase);
}
~SDK()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
Console.WriteLine("Disposing SDK");
if (oCustm != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCustm);
if (oSuppl != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSuppl);
if (oSInvce != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSInvce);
if (oSale != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSale);
if (oPurch != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPurch);
if (oYear != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oYear);
if (oDossier != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDossier);
if (oVenice != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oVenice);
// Force garbage collection.
GC.Collect();
// Wait for all finalizers to complete before continuing.
// Without this call to GC.WaitForPendingFinalizers,
// the worker loop below might execute at the same time
// as the finalizers.
// With this call, the worker loop executes only after
// all finalizers have been called.
GC.WaitForPendingFinalizers();
}
disposed = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment