It is not possible to print a document in the internal module through the API

1

I'm developing a web application that launches internal documents in Spring ERP. I have this code:

PriEngine.Engine.Comercial.Internos.Actualiza(invoice)
Dim file As String = "C:\temp\" & invoice.Tipodoc & invoice.Serie & invoice.NumDoc & ".pdf"
PriEngine.Engine.Comercial.Internos.ImprimeDocumento(invoice.Tipodoc, invoice.Serie, invoice.NumDoc, Filial:="000", DestinoPDF:=file)

The problem is as follows: The Update works extremely well, but the PrintDocument does not, I already created the folder and nothing. No mistake even gives. Can someone help me?

    
asked by anonymous 28.06.2018 / 10:16

3 answers

4

I have version 9.15 and can print. In this example I'm reading an existing document: .WinForms VB.Net:

        Dim objERP As New Interop.ErpBS900.ErpBS
        objERP.AbreEmpresaTrabalho(eTipoPlataforma, Empresa, Utilizador, Password)

        Dim objDocInterno As Interop.GcpBE900.GcpBEDocumentoInterno = objERP.Comercial.Internos.EditaID("B1094E8F-EF7B-11E6-80EF-000C292974C4")
        Dim sFicheiro As String = "C:\ABC\DocInterno.pdf"
        objERP.Comercial.Internos.ImprimeDocumento(objDocInterno.Tipodoc, objDocInterno.Serie, objDocInterno.NumDoc, objDocInterno.Filial, 1, "", False, sFicheiro)

.Web C #:

        Interop.ErpBS900.ErpBS objERP = new Interop.ErpBS900.ErpBS();
        objERP.AbreEmpresaTrabalho(eTipoPlataforma, Empresa, Utilizador, Password);

        Interop.GcpBE900.GcpBEDocumentoInterno objDocInterno = objERP.Comercial.Internos.EditaID("B1094E8F-EF7B-11E6-80EF-000C292974C4");
        string sFicheiro = "C:\ABC\DocInterno.pdf";
        objERP.Comercial.Internos.ImprimeDocumento(objDocInterno.get_Tipodoc(), objDocInterno.get_Serie(), objDocInterno.get_NumDoc(), objDocInterno.get_Filial(), 1, "", false, sFicheiro);
    
28.06.2018 / 17:29
3

In version 9 I can not print either. Alternatively you can use this example that is available on GitHub. link

public static void PrintInvoice(StdBSInterfPub pso,
    ErpBS bso,
    string reportPath,
    string DocType,
    string DocSeries,
    int DocNumber)
{
    var reportTemplate = "GCPILS01";

    try
    {
        var strSelFormula = $"{{CabecDoc.TipoDoc}}=\'{DocType}\' and {{CabecDoc.Serie}} = \'{DocSeries}\' AND {{CabecDoc.NumDoc}}={Convert.ToString(DocNumber)}";

        pso.Mapas.Inicializar("VND");

        var strFormula = new StringBuilder();
        strFormula.Append($"StringVar Nome:='{bso.Contexto.IDNome}';");
        strFormula.Append($"StringVar Morada:='{bso.Contexto.IDMorada}';");
        strFormula.Append($"StringVar Localidade:='{bso.Contexto.IDLocalidade}';");
        strFormula.Append($"StringVar CodPostal:='{bso.Contexto.IDCodPostal} {bso.Contexto.IDCodPostalLocal}';");
        strFormula.Append($"StringVar Telefone:='{bso.Contexto.IDTelefone}';");
        strFormula.Append($"StringVar Fax:='{bso.Contexto.IDFax}';");
        strFormula.Append($"StringVar Contribuinte:='{bso.Contexto.IFNIF}';");
        strFormula.Append($"StringVar CapitalSocial:='{bso.Contexto.ICCapitalSocial}';");
        strFormula.Append($"StringVar Conservatoria:='{bso.Contexto.ICConservatoria}';");
        strFormula.Append($"StringVar Matricula:='{bso.Contexto.ICMatricula}';");
        strFormula.Append($"StringVar MoedaCapitalSocial:='{bso.Contexto.ICMoedaCapSocial}';");

        pso.Mapas.SetFormula("DadosEmpresa", strFormula.ToString());

        var strParametros = new StringBuilder();
        strParametros.Append("NumberVar TipoDesc;");
        strParametros.Append("NumberVar DecQde;");
        strParametros.Append("NumberVar DecPrecUnit;");
        strParametros.Append("StringVar MotivoIsencao;");
        strParametros.Append("BooleanVar UltimaPag;");
        strParametros.Append("StringVar PRI_TextoCertificacao;");
        strParametros.Append("TipoDesc:= 0;");
        strParametros.Append("DecQde:=3;");
        strParametros.Append($"DecPrecUnit:={pso.FuncoesGlobais.DaCasasDecimais("Moedas", "DecArredonda")};");
        strParametros.Append("UltimaPag:=False;");
        strParametros.Append($"PRI_TextoCertificacao:='{bso.Vendas.Documentos.DevolveTextoAssinaturaDoc(DocType, DocSeries, DocNumber, "000")}';");

        pso.Mapas.SetFormula("InicializaParametros", strParametros.ToString());
        pso.Mapas.Destino = 0;
        pso.Mapas.SetFileProp(StdBSTipos.CRPEExportFormat.efPdf, reportPath);

        pso.Mapas.ImprimeListagem(reportTemplate, "Invoice", "P", 1, "N", strSelFormula, 0, false, true);
    }
    catch (Exception ex)
    {
        throw new Exception("Error while printing the document. \n" + ex.Message);
    }
}
    
28.06.2018 / 10:28
0

One of the possible options to implement the intended, will follow the example provided by Sergio Sereno, since PriEngine as mentioned in the comments is not prepared to work in web environment strong> and using this example you need to indicate the print map, which in this case is "GCPILS01" . In this sense, for version 9 and as referred by Manuel Quelhas, reinforced the option to use objERP.Comercial.Internos.ImprimeDocumento() instead of PriEngine.Engine.Comercial.Internos.ImprimeDocumento() thus avoiding problems of this type.

    
02.07.2018 / 11:10