Import initial din SVN ROAAUTO/Trunk @HEAD
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
* PLUGIN email factura, recapitulatie si alte documente pdf cu aceeasi structura ca factura.pdf
|
||||
* MARIUS MUTU
|
||||
* V 23.02.2016
|
||||
* INSTALARE: Se copie fisierul prg in directorul ROA\[APLICATIE]\PLUGIN\
|
||||
* FOLOSIRE: In formularul Vizualizare facturi se apasa butonul listare
|
||||
* copiat din oproceduri_facturare.prg:email_facturi
|
||||
|
||||
Lparameters toFacturiForm, toDate
|
||||
*** Trimit email la facturile alese, sau la factura de pe inregistrarea curenta
|
||||
|
||||
Local laFiles[1], lcBody, lcClient, lcDir, lcEmail, lcErrorMessage, lcFacturaFile, lcFile
|
||||
Local lcFileName, lcFiles, lcNume, lcRaportEmail, lcRecapitulatiaFile, lcScheletonFile
|
||||
Local lcSerieFactura, lcSubject, lcTipDocument, lcTo, lcWhere, ldDataFactura, llClearErrors
|
||||
Local llJustPDF, llListareFactura, llListareRecapitulatia, llListareAlteDocumente, llSilent, llSucces, lnFile, lnFiles
|
||||
Local lnIdVanzare, lnNumarFactura, lnRecno, loDate, loMail
|
||||
|
||||
loMail = getoEmail() && email.prg
|
||||
|
||||
lcWhere = ""
|
||||
llListareFactura = .T.
|
||||
llGenerareFactura = .T.
|
||||
llListareRecapitulatia = .T.
|
||||
llGenerareRecapitulatia = .T.
|
||||
llListareAlteDocumente = .T.
|
||||
If Type('toDate') = 'O'
|
||||
llListareFactura = Iif(Type('toDate.nListareFactura') = 'N', Inlist(toDate.nListareFactura, 1, 2), .T.)
|
||||
llGenerareFactura = Iif(Type('toDate.nListareFactura') = 'N', toDate.nListareFactura = 2, .F.)
|
||||
|
||||
llListareRecapitulatia = Iif(Type('toDate.nListareRecapitulatia') = 'N', Inlist(toDate.nListareRecapitulatia, 1, 2), .F.)
|
||||
llGenerareRecapitulatia = Iif(Type('toDate.nListareRecapitulatia') = 'N', toDate.nListareRecapitulatia = 2, .F.)
|
||||
|
||||
llListareAlteDocumente = Iif(Type('toDate.nListareAlteDocumente') = 'L', toDate.nListareAlteDocumente = 1, .F.)
|
||||
Endif
|
||||
|
||||
Select crsFacturi
|
||||
lnRecno = Recno()
|
||||
Locate For ales = 1
|
||||
If !Found()
|
||||
Goto m.lnRecno
|
||||
lcWhere = m.lcWhere + 'recno() = ' + Alltrim(Str(m.lnRecno))
|
||||
Else
|
||||
lcWhere = m.lcWhere + 'ales = 1'
|
||||
Endif
|
||||
|
||||
lcRaportEmail = Addbs(gcTempPath) + "email_" + Ttoc(Datetime(), 1) + '.xls'
|
||||
|
||||
Select F.id_vanzare, F.data_act, F.numar_act, F.serie_act, F.total_fara_tva, F.total_tva, F.total_cu_tva, F.client, ;
|
||||
email_facturare, Cast(Null As L) As email_succes, Cast(Null As c(250)) As email_mesaj ;
|
||||
From crsFacturi F ;
|
||||
Where &lcWhere ;
|
||||
Into Cursor cEmail Readwrite
|
||||
|
||||
lcSubjectTemplate = loMail.cSubject
|
||||
lcBodyTemplate = loMail.cHtmlBody
|
||||
Sele cEmail
|
||||
Scan
|
||||
lcFiles = ""
|
||||
ldDataFactura = data_act
|
||||
lcSerieFactura = Alltrim(serie_act)
|
||||
lnNumarFactura = numar_act
|
||||
lcNume = Upper(Alltrim(client))
|
||||
lcClient = m.lcNume
|
||||
lnIdVanzare = id_vanzare
|
||||
loDate = Null
|
||||
|
||||
lcSubject = m.lcSubjectTemplate
|
||||
lcSubject = Strtran(m.lcSubject, '<nrfact>', Alltrim(Str(m.lnNumarFactura)), 1, 1, 1)
|
||||
lcSubject = Strtran(m.lcSubject, '<datafact>', Alltrim(Dtoc(m.ldDataFactura)), 1, 1, 1)
|
||||
lcSubject = Strtran(m.lcSubject, '<client>', m.lcClient, 1, 1, 1)
|
||||
loMail.cSubject = m.lcSubject
|
||||
|
||||
lcBody = m.lcBodyTemplate
|
||||
lcBody = Strtran(m.lcBody, '<nrfact>', Alltrim(Str(m.lnNumarFactura)), 1, 10, 1)
|
||||
lcBody = Strtran(m.lcBody, '<datafact>', Alltrim(Dtoc(m.ldDataFactura)), 1, 10, 1)
|
||||
lcBody = Strtran(m.lcBody, '<client>', m.lcClient, 1, 10, 1)
|
||||
loMail.cHtmlBody = m.lcBody
|
||||
|
||||
* Generare PDF factura
|
||||
lcFacturaFile = GetPDFFacturaFile(m.ldDataFactura, m.lnNumarFactura)
|
||||
If m.llListareFactura
|
||||
If !File(m.lcFacturaFile) And m.llGenerareFactura
|
||||
llSilent = .F.
|
||||
llJustPDF = .T.
|
||||
lcTipDocument = 'FACTURA'
|
||||
loDate = toFacturiForm.do_listare_document(m.lnIdVanzare, m.llSilent, m.llJustPDF, m.lcTipDocument) && .ListareDocument(m.llSilent, m.llJustPDF, "cEmail")
|
||||
Endif
|
||||
loMail.EmailSetAttachment(m.lcFacturaFile)
|
||||
lcFiles = m.lcFiles + Iif(File(m.lcFacturaFile), m.lcFacturaFile, "")
|
||||
Endif && llListareFactura
|
||||
|
||||
* Generare PDF recapitulatie
|
||||
lcRecapitulatiaFile = GetPDFRecapitulatiaFile(ldDataFactura, m.lnNumarFactura)
|
||||
If m.llListareRecapitulatia
|
||||
If !File(m.lcRecapitulatiaFile) And m.llGenerareRecapitulatia
|
||||
llSilent = .F.
|
||||
llJustPDF = .T.
|
||||
lcTipDocument = 'RECAPITULATIE'
|
||||
loDate = toFacturiForm.do_listare_document(m.lnIdVanzare, m.llSilent, m.llJustPDF, m.lcTipDocument) && .ListareDocument(m.llSilent, m.llJustPDF, "cEmail")
|
||||
Endif
|
||||
loMail.EmailSetAttachment(m.lcRecapitulatiaFile)
|
||||
lcFiles = m.lcFiles + Iif(File(m.lcRecapitulatiaFile), "," + m.lcRecapitulatiaFile, "")
|
||||
Endif && llListareRecapitulatia
|
||||
|
||||
* Atasez alte documente cu aceeasi structura ca factura.pdf
|
||||
If m.llListareAlteDocumente
|
||||
lcScheletonFile = Strtran(lcFacturaFile, 'factura', '*', 1, 10, 1) && d:\roa\pdf\20200402_12346_*.pdf (_recapitulatia.pdf, _situatie_stationare.pdf, _declaratie_comandant.pdf)
|
||||
lcDir = Addbs(Justpath(m.lcFacturaFile))
|
||||
lnFiles = Adir(laFiles, m.lcScheletonFile)
|
||||
For lnFile = 1 To m.lnFiles
|
||||
lcFileName = laFiles[m.lnFile, 1]
|
||||
* Nu mai atasez factura.pdf si recapitulatie.pdf
|
||||
If Inlist(Lower(m.lcFileName), Lower(JUSTFNAME(m.lcFacturaFile)), Lower(JUSTFNAME(m.lcRecapitulatiaFile)))
|
||||
Loop
|
||||
Endif
|
||||
lcFile = m.lcDir + m.lcFileName
|
||||
loMail.EmailSetAttachment(m.lcFile)
|
||||
lcFiles = m.lcFiles + Iif(File(m.lcFile), m.lcFile, "")
|
||||
Endfor
|
||||
Endif && llListareAlteDocumente
|
||||
|
||||
* Email
|
||||
Wait Window 'Email ' + Alltrim(Transform(Recno('cEmail'))) + '/' + Alltrim(Transform(Reccount('cEmail'))) + ' Client: ' + m.lcClient + ' Factura: ' + Alltrim(Str(m.lnNumarFactura)) Nowait
|
||||
lcEmail = Alltrim(Nvl(cEmail.email_facturare, '')) && am adaugat direct in crsFacturi.email_facturare, ca sa nu mai folosesc loDate.oClient.email_facturare, daca fisierele pdf sunt deja listate
|
||||
lcTo = Iif(!Empty(Nvl(m.lcEmail, '')), m.lcEmail, '')
|
||||
loMail.cTo = m.lcTo
|
||||
|
||||
llSucces = .T.
|
||||
lcErrorMessage = ''
|
||||
If loMail.Send() > 0
|
||||
llClearErrors = .T.
|
||||
lcErrorMessage = loMail.GetErrorMessage(m.llClearErrors)
|
||||
llSucces = .F.
|
||||
Endif
|
||||
Replace email_succes With m.llSucces, email_mesaj With Left(m.lcErrorMessage, 250) In cEmail
|
||||
|
||||
If Inkey(0.5) = 27 && 'ESC'
|
||||
If AMESSAGEBOX('Doriti sa intrerupeti operatia?', 4 + 32, _Screen.Caption) = 6
|
||||
Exit
|
||||
Endif
|
||||
Endif
|
||||
Endscan
|
||||
|
||||
Select cEmail
|
||||
Copy To (m.lcRaportEmail) Type Xl5
|
||||
OPEN_DEFAULT_APP(m.lcRaportEmail)
|
||||
|
||||
Use In (Select('cEmail'))
|
||||
|
||||
Select crsFacturi
|
||||
Go lnRecno
|
||||
175
COMUN/Plugin/listare_facturi_omv_petrom_pdf_si_xml.prg
Normal file
175
COMUN/Plugin/listare_facturi_omv_petrom_pdf_si_xml.prg
Normal file
@@ -0,0 +1,175 @@
|
||||
Lparameters toFacturiForm, toDate
|
||||
Local lcBody, lcBodyTemplate, lcClickSignPDF, lcClient, lcContract, lcDivizia, lcEmail
|
||||
Local lcErrorMessage, lcFacturaFile, lcFileSemnat, lcFiles, lcNume, lcRaportEmail, lcRun, lcSelect
|
||||
Local lcSerieFactura, lcSql, lcSubject, lcSubjectTemplate, lcTipDocument, lcTo, lcValuta, lcWhere
|
||||
Local lcXML, lcXMLFile, ldDataFactura, llClearErrors, llForceExit, llGenerareFactura, llInValuta
|
||||
Local llJustPDF, llListareFactura, llSilent, llSucces, lnCurs, lnIdFact, lnIdVanzare, lnNumarFactura
|
||||
Local lnOptDivizia, lnRecno, lnValoare, loDate, loMail
|
||||
|
||||
lcSelect = Select()
|
||||
|
||||
lcClickSignPDF = [C:\Program Files (x86)\clickSignPdf\clickSignPdfProfessional.exe]
|
||||
If !File(m.lcClickSignPDF)
|
||||
lcClickSignPDF = [C:\Program Files\clickSignPdf\clickSignPdfProfessional.exe]
|
||||
Endif
|
||||
If !File(m.lcClickSignPDF)
|
||||
If AMESSAGEBOX('Nu este instalat clickSIGNpdf.exe! Continuati?',4+32,_Screen.Caption) <> 6
|
||||
Return
|
||||
Endif
|
||||
Endif
|
||||
|
||||
loMail = getoEmail() && email.prg
|
||||
|
||||
lcWhere = ""
|
||||
llListareFactura = .T.
|
||||
llGenerareFactura = .T.
|
||||
If Type('toDate') = 'O'
|
||||
llListareFactura = Iif(Type('toDate.nListareFactura') = 'N', Inlist(toDate.nListareFactura, 1, 2), .T.)
|
||||
llGenerareFactura = Iif(Type('toDate.nListareFactura') = 'N', toDate.nListareFactura = 2, .T.)
|
||||
Endif
|
||||
|
||||
Select crsFacturi
|
||||
lnRecno = Recno()
|
||||
Locate For ales = 1
|
||||
If !Found()
|
||||
Goto m.lnRecno
|
||||
lcWhere = m.lcWhere + 'recno() = ' + Alltrim(Str(m.lnRecno))
|
||||
Else
|
||||
lcWhere = m.lcWhere + 'ales = 1'
|
||||
Endif
|
||||
|
||||
lcRaportEmail = Addbs(gcTempPath) + "email_" + Ttoc(Datetime(), 1) + '.xls'
|
||||
|
||||
Select F.id_vanzare, F.data_act, F.numar_act, F.serie_act, F.total_fara_tva, F.total_tva, F.total_cu_tva, F.client, F.valuta, F.contract, F.Curs, F.in_valuta,;
|
||||
f.valval, F.tvaval, F.totval, F.email_facturare, Cast(Null As L) As email_succes, Cast(Null As c(250)) As email_mesaj ;
|
||||
From crsFacturi F ;
|
||||
Where &lcWhere ;
|
||||
Into Cursor cEmail Readwrite
|
||||
|
||||
lcSubjectTemplate = loMail.cSubject
|
||||
lcBodyTemplate = loMail.cHtmlBody
|
||||
|
||||
If Reccount('cEmail') > 0
|
||||
|
||||
lcFiles = ""
|
||||
Sele cEmail
|
||||
Scan
|
||||
ldDataFactura = data_act
|
||||
lcSerieFactura = Alltrim(serie_act)
|
||||
lnNumarFactura = numar_act
|
||||
lcNume = Upper(Alltrim(client))
|
||||
lcClient = m.lcNume
|
||||
lnIdVanzare = id_vanzare
|
||||
loDate = Null
|
||||
lcValuta = Upper(Alltrim(valuta))
|
||||
lcContract = Alltrim(Nvl(contract, ''))
|
||||
lnCurs = Curs
|
||||
llInValuta = (Nvl(in_valuta,0) = 1)
|
||||
|
||||
lcValuta = Upper(Alltrim(Nvl(valuta,'')))
|
||||
Do Case
|
||||
Case !m.llInValuta
|
||||
lcValuta = 'RON'
|
||||
Case Left(m.lcValuta,3) = 'EUR' && EURO
|
||||
lcValuta = 'EUR'
|
||||
Endcase
|
||||
lnValoare = Iif(m.llInValuta, totval, total_cu_tva)
|
||||
|
||||
lcSubject = m.lcSubjectTemplate
|
||||
lcSubject = Strtran(m.lcSubject, '<nrfact>', Alltrim(Str(m.lnNumarFactura)), 1, 1, 1)
|
||||
lcSubject = Strtran(m.lcSubject, '<datafact>', Alltrim(Dtoc(m.ldDataFactura)), 1, 1, 1)
|
||||
lcSubject = Strtran(m.lcSubject, '<client>', m.lcClient, 1, 1, 1)
|
||||
loMail.cSubject = m.lcSubject
|
||||
|
||||
lcBody = m.lcBodyTemplate
|
||||
lcBody = Strtran(m.lcBody, '<nrfact>', Alltrim(Str(m.lnNumarFactura)), 1, 10, 1)
|
||||
lcBody = Strtran(m.lcBody, '<datafact>', Alltrim(Dtoc(m.ldDataFactura)), 1, 10, 1)
|
||||
lcBody = Strtran(m.lcBody, '<client>', m.lcClient, 1, 10, 1)
|
||||
loMail.cHtmlBody = m.lcBody
|
||||
|
||||
* Generare PDF factura
|
||||
lcFacturaFile = GetPDFFacturaFile(m.ldDataFactura, m.lnNumarFactura)
|
||||
lcFacturaValutaFile = GetPDFFacturaValutaFile(m.ldDataFactura, m.lnNumarFactura)
|
||||
If m.llListareFactura
|
||||
If !File(m.lcFacturaFile) And m.llGenerareFactura
|
||||
llSilent = .F.
|
||||
llJustPDF = .T.
|
||||
lcTipDocument = 'FACTURA'
|
||||
loDate = toFacturiForm.do_listare_document(m.lnIdVanzare, m.llSilent, m.llJustPDF, m.lcTipDocument) && .ListareDocument(m.llSilent, m.llJustPDF, "cEmail")
|
||||
Endif
|
||||
Endif && llListareFactura
|
||||
|
||||
If File(m.lcFacturaValutaFile) And File(m.lcFacturaFile)
|
||||
lnRaspuns = AMESSAGEBOX('Doriti semnarea facturii in valuta (DA) sau a facturii in lei (NU)?',4+32,_Screen.Caption)
|
||||
If m.lnRaspuns = 6
|
||||
lcFacturaFile = m.lcFacturaValutaFile
|
||||
Endif
|
||||
Endif
|
||||
* Semnare PDF
|
||||
* Lansare utilitar certsign.ro
|
||||
OPEN_DEFAULT_APP(Justpath(m.lcFacturaFile)) && deschid directorul facturii
|
||||
If File(m.lcClickSignPDF)
|
||||
lcRun = [! /N "] + m.lcClickSignPDF + [" -i "] + m.lcFacturaFile + ["]
|
||||
&lcRun
|
||||
Endif
|
||||
|
||||
lcFileSemnat = Strtran(m.lcFacturaFile, Juststem(m.lcFacturaFile), Juststem(m.lcFacturaFile) + '_signed')
|
||||
|
||||
AMESSAGEBOX('Se verifica fisierul ' + lcFileSemnat + Chr(13) + Chr(10) + 'Apasati OK cand s-a semnat pdf-ul.',0, _Screen.Caption)
|
||||
*WAIT WINDOW 'Se asteapta semnarea fisierului ' + m.lcFacturaFile NOWAIT
|
||||
|
||||
llForceExit = .F.
|
||||
Do While .T.
|
||||
If File(m.lcFileSemnat)
|
||||
Exit
|
||||
Endif
|
||||
Wait Window 'Se verifica ' + m.lcFileSemnat Nowait
|
||||
If Inkey(1) = 27 && 'ESC'
|
||||
If AMESSAGEBOX('Doriti sa intrerupeti operatia?',4+32, _Screen.Caption) = 6
|
||||
llForceExit = .T.
|
||||
Exit
|
||||
Endif
|
||||
Endif
|
||||
Enddo
|
||||
|
||||
If m.llForceExit
|
||||
Exit
|
||||
Endif
|
||||
|
||||
If File(m.lcFileSemnat)
|
||||
loMail.EmailSetAttachment(m.lcFileSemnat)
|
||||
Endif
|
||||
|
||||
* Email
|
||||
Wait Window 'Email ' + Alltrim(Transform(Recno('cEmail'))) + '/' + Alltrim(Transform(Reccount('cEmail'))) + ' Client: ' + m.lcClient + ' Factura: ' + Alltrim(Str(m.lnNumarFactura)) Nowait
|
||||
lcEmail = Alltrim(Nvl(cEmail.email_facturare, '')) && am adaugat direct in crsFacturi.email_facturare, ca sa nu mai folosesc loDate.oClient.email_facturare, daca fisierele pdf sunt deja listate
|
||||
lcTo = Iif(!Empty(Nvl(m.lcEmail, '')), m.lcEmail, '')
|
||||
loMail.cTo = m.lcTo
|
||||
|
||||
llSucces = .T.
|
||||
lcErrorMessage = ''
|
||||
If loMail.Send() > 0
|
||||
llClearErrors = .T.
|
||||
lcErrorMessage = loMail.GetErrorMessage(m.llClearErrors)
|
||||
llSucces = .F.
|
||||
Endif
|
||||
Replace email_succes With m.llSucces, email_mesaj With Left(m.lcErrorMessage, 250) In cEmail
|
||||
|
||||
If Inkey(0.5) = 27 && 'ESC'
|
||||
If AMESSAGEBOX('Doriti sa intrerupeti operatia?', 4 + 32, _Screen.Caption) = 6
|
||||
Exit
|
||||
Endif
|
||||
Endif
|
||||
Endscan
|
||||
|
||||
Select cEmail
|
||||
Copy To (m.lcRaportEmail) Type Xl5
|
||||
OPEN_DEFAULT_APP(m.lcRaportEmail)
|
||||
ENDIF && Reccount('cEmail')
|
||||
|
||||
Use In (Select('cEmail'))
|
||||
|
||||
Select (m.lcSelect)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user