72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"code.tnxs.net/taxnexus/lib/api/stash/stash_client/stash_pdf"
|
||
|
"code.tnxs.net/taxnexus/lib/api/stash/stash_models"
|
||
|
)
|
||
|
|
||
|
type StashPDFParams struct {
|
||
|
document *Document
|
||
|
account *Account
|
||
|
objectType string
|
||
|
principal *User
|
||
|
}
|
||
|
|
||
|
func StashPDF(params StashPDFParams) (*Document, error) {
|
||
|
sugar.Debugf("render.stashPDF: 📥")
|
||
|
var title string
|
||
|
var fileName string
|
||
|
var description string
|
||
|
var ref string
|
||
|
switch params.objectType {
|
||
|
case "account":
|
||
|
title = "Taxnexus Report for " + params.account.Name
|
||
|
fileName = "Taxnexus Report for " + params.account.Name + ".pdf"
|
||
|
description = "Account Report generated by render"
|
||
|
ref = "render.getAccounts"
|
||
|
case "tax_summary":
|
||
|
title = "Taxnexus Tax Report for " + params.account.Name
|
||
|
fileName = params.account.Name + " Tax Report.pdf"
|
||
|
description = "CDTFA Quarterly District Sales and Use Tax for "
|
||
|
ref = "render.getTaxes"
|
||
|
}
|
||
|
|
||
|
todoString := "todo" // todo #5
|
||
|
stashParams := stash_pdf.NewPostPdfsParamsWithTimeout(getTimeout)
|
||
|
stashParams.PDFRequest = &stash_models.PDFRequest{
|
||
|
Meta: &stash_models.RequestMeta{
|
||
|
TaxnexusAccount: &todoString,
|
||
|
},
|
||
|
Data: []*stash_models.NewPDF{
|
||
|
{
|
||
|
Description: description,
|
||
|
Filename: fileName,
|
||
|
HTML: params.document.HTML,
|
||
|
ObjectType: params.document.SagaType,
|
||
|
OwnerID: "fabric", // todo #6 make OwnerID in new PDF real
|
||
|
ParentID: params.document.ParentID,
|
||
|
Ref: ref,
|
||
|
Title: title,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
response, err := stashClient.StashPdf.PostPdfs(stashParams, params.principal.Auth)
|
||
|
if err != nil {
|
||
|
sugar.Errorf("render.stashPDF: 💣 ⛔ post PDF to stash error %w", err)
|
||
|
return nil, err
|
||
|
}
|
||
|
var newObj *stash_models.Document
|
||
|
for _, itm := range response.Payload.Data { // single iteration execution
|
||
|
newObj = itm
|
||
|
}
|
||
|
sugar.Debugf("render.stashPDF: 👍 📤")
|
||
|
return &Document{
|
||
|
ID: newObj.ID,
|
||
|
Filename: params.account.Name + fileName,
|
||
|
SagaType: params.document.SagaType,
|
||
|
ParentID: params.document.ParentID,
|
||
|
Title: title + params.account.Name,
|
||
|
URI: newObj.URI,
|
||
|
}, nil
|
||
|
}
|