-
Notifications
You must be signed in to change notification settings - Fork 12
/
invoice_write_repository.go
546 lines (489 loc) · 22.7 KB
/
invoice_write_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
package repository
import (
"context"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
neo4jenum "github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/enum"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/model"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-neo4j-repository/tracing"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
"time"
)
type InvoiceCreateFields struct {
ContractId string `json:"contractId"`
Currency neo4jenum.Currency `json:"currency"`
DryRun bool `json:"dryRun"`
OffCycle bool `json:"offCycle"`
Postpaid bool `json:"postpaid"`
Preview bool `json:"preview"`
PeriodStartDate time.Time `json:"periodStartDate"`
PeriodEndDate time.Time `json:"periodEndDate"`
CreatedAt time.Time `json:"createdAt"`
IssuedDate time.Time `json:"issuedDate"`
DueDate time.Time `json:"dueDate"`
SourceFields model.Source `json:"sourceFields"`
BillingCycleInMonths int64 `json:"billingCycleInMonths"`
Status neo4jenum.InvoiceStatus `json:"status"`
Note string `json:"note"`
}
type InvoiceFillFields struct {
Amount float64 `json:"amount"`
VAT float64 `json:"vat"`
TotalAmount float64 `json:"totalAmount"`
UpdatedAt time.Time `json:"updatedAt"`
ContractId string `json:"contractId"`
Currency neo4jenum.Currency `json:"currency"`
DryRun bool `json:"dryRun"`
OffCycle bool `json:"offCycle"`
Postpaid bool `json:"postpaid"`
Preview bool `json:"preview"`
InvoiceNumber string `json:"invoiceNumber"`
PeriodStartDate time.Time `json:"periodStartDate"`
PeriodEndDate time.Time `json:"periodEndDate"`
BillingCycleInMonths int64 `json:"billingCycleInMonths"`
Status neo4jenum.InvoiceStatus `json:"status"`
Note string `json:"note"`
CustomerName string `json:"customerName"`
CustomerEmail string `json:"customerEmail"`
CustomerAddressLine1 string `json:"customerAddressLine1"`
CustomerAddressLine2 string `json:"customerAddressLine2"`
CustomerAddressZip string `json:"customerAddressZip"`
CustomerAddressLocality string `json:"customerAddressLocality"`
CustomerAddressCountry string `json:"customerAddressCountry"`
CustomerAddressRegion string `json:"customerAddressRegion"`
ProviderLogoRepositoryFileId string `json:"providerLogoRepositoryFileId"`
ProviderName string `json:"providerName"`
ProviderEmail string `json:"providerEmail"`
ProviderAddressLine1 string `json:"providerAddressLine1"`
ProviderAddressLine2 string `json:"providerAddressLine2"`
ProviderAddressZip string `json:"providerAddressZip"`
ProviderAddressLocality string `json:"providerAddressLocality"`
ProviderAddressCountry string `json:"providerAddressCountry"`
ProviderAddressRegion string `json:"providerAddressRegion"`
}
type InvoiceUpdateFields struct {
UpdatedAt time.Time `json:"updatedAt"`
Status neo4jenum.InvoiceStatus `json:"status"`
PaymentLink string `json:"paymentLink"`
UpdateStatus bool `json:"updateStatus"`
UpdatePaymentLink bool `json:"updatePaymentLink"`
}
type InvoiceWriteRepository interface {
CreateInvoiceForContract(ctx context.Context, tenant, invoiceId string, data InvoiceCreateFields) error
FillInvoice(ctx context.Context, tenant, invoiceId string, data InvoiceFillFields) error
InvoicePdfGenerated(ctx context.Context, tenant, id, repositoryFileId string, updatedAt time.Time) error
UpdateInvoice(ctx context.Context, tenant, invoiceId string, data InvoiceUpdateFields) error
MarkInvoiceFinalizedEventSent(ctx context.Context, tenant, invoiceId string) error
MarkPayNotificationRequested(ctx context.Context, tenant, invoiceId string, requestedAt time.Time) error
MarkPaymentLinkRequested(ctx context.Context, tenant, invoiceId string) error
SetPaidInvoiceNotificationSentAt(ctx context.Context, tenant, invoiceId string) error
SetPayInvoiceNotificationSentAt(ctx context.Context, tenant, invoiceId string) error
DeleteInitializedInvoice(ctx context.Context, tenant, invoiceId string) error
DeletePreviewCycleInvoices(ctx context.Context, tenant, contractId, skipInvoiceId string) error
DeletePreviewCycleInitializedInvoices(ctx context.Context, tenant, contractId, skipInvoiceId string) error
DeleteDryRunInvoice(ctx context.Context, tenant, invoiceId string) error
}
type invoiceWriteRepository struct {
driver *neo4j.DriverWithContext
database string
}
func NewInvoiceWriteRepository(driver *neo4j.DriverWithContext, database string) InvoiceWriteRepository {
return &invoiceWriteRepository{
driver: driver,
database: database,
}
}
func (r *invoiceWriteRepository) CreateInvoiceForContract(ctx context.Context, tenant, invoiceId string, data InvoiceCreateFields) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.CreateInvoiceForContract")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
tracing.LogObjectAsJson(span, "data", data)
cypher := fmt.Sprintf(`MATCH (t:Tenant {name:$tenant})<-[:CONTRACT_BELONGS_TO_TENANT]-(c:Contract {id:$contractId})
MERGE (t)<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
ON CREATE SET
i.updatedAt=$updatedAt,
i.status=$status
SET
i:Invoice_%s,
i.createdAt=$createdAt,
i.dueDate=$dueDate,
i.issuedDate=$issuedDate,
i.source=$source,
i.sourceOfTruth=$sourceOfTruth,
i.appSource=$appSource,
i.dryRun=$dryRun,
i.offCycle=$offCycle,
i.postpaid=$postpaid,
i.preview=$preview,
i.currency=$currency,
i.periodStartDate=$periodStart,
i.periodEndDate=$periodEnd,
i.billingCycleInMonths=$billingCycleInMonths,
i.note=$note
WITH c, i
MERGE (c)-[:HAS_INVOICE]->(i)
`, tenant)
params := map[string]any{
"tenant": tenant,
"contractId": data.ContractId,
"invoiceId": invoiceId,
"createdAt": data.CreatedAt,
"updatedAt": data.CreatedAt,
"dueDate": utils.ToNeo4jDateAsAny(&data.DueDate),
"issuedDate": utils.ToDate(data.IssuedDate),
"source": data.SourceFields.Source,
"sourceOfTruth": data.SourceFields.Source,
"appSource": data.SourceFields.AppSource,
"dryRun": data.DryRun,
"offCycle": data.OffCycle,
"postpaid": data.Postpaid,
"preview": data.Preview,
"currency": data.Currency.String(),
"periodStart": utils.ToNeo4jDateAsAny(&data.PeriodStartDate),
"periodEnd": utils.ToNeo4jDateAsAny(&data.PeriodEndDate),
"billingCycleInMonths": data.BillingCycleInMonths,
"status": data.Status.String(),
"note": data.Note,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) FillInvoice(ctx context.Context, tenant, invoiceId string, data InvoiceFillFields) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.FillInvoice")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (t:Tenant {name:$tenant})<-[:CONTRACT_BELONGS_TO_TENANT]-(c:Contract {id:$contractId})
MERGE (t)<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
ON CREATE SET
i:Invoice_%s,
i.currency=$currency,
i.dryRun=$dryRun,
i.offCycle=$offCycle,
i.postpaid=$postpaid,
i.preview=$preview,
i.periodStartDate=$periodStart,
i.periodEndDate=$periodEnd,
i.billingCycleInMonths=$billingCycleInMonths
SET
i.updatedAt=$updatedAt,
i.number=$number,
i.amount=$amount,
i.vat=$vat,
i.totalAmount=$totalAmount,
i.status=$status,
i.note=$note,
i.customerName=$customerName,
i.customerEmail=$customerEmail,
i.customerAddressLine1=$customerAddressLine1,
i.customerAddressLine2=$customerAddressLine2,
i.customerAddressZip=$customerAddressZip,
i.customerAddressLocality=$customerAddressLocality,
i.customerAddressCountry=$customerAddressCountry,
i.customerAddressRegion=$customerAddressRegion,
i.providerLogoRepositoryFileId=$providerLogoRepositoryFileId,
i.providerName=$providerName,
i.providerEmail=$providerEmail,
i.providerAddressLine1=$providerAddressLine1,
i.providerAddressLine2=$providerAddressLine2,
i.providerAddressZip=$providerAddressZip,
i.providerAddressLocality=$providerAddressLocality,
i.providerAddressCountry=$providerAddressCountry,
i.providerAddressRegion=$providerAddressRegion
WITH c, i
MERGE (c)-[:HAS_INVOICE]->(i)
`, tenant)
params := map[string]any{
"tenant": tenant,
"contractId": data.ContractId,
"invoiceId": invoiceId,
"updatedAt": data.UpdatedAt,
"amount": data.Amount,
"vat": data.VAT,
"totalAmount": data.TotalAmount,
"dryRun": data.DryRun,
"offCycle": data.OffCycle,
"postpaid": data.Postpaid,
"preview": data.Preview,
"number": data.InvoiceNumber,
"currency": data.Currency.String(),
"periodStart": utils.ToNeo4jDateAsAny(&data.PeriodStartDate),
"periodEnd": utils.ToNeo4jDateAsAny(&data.PeriodEndDate),
"billingCycleInMonths": data.BillingCycleInMonths,
"status": data.Status.String(),
"note": data.Note,
"customerName": data.CustomerName,
"customerEmail": data.CustomerEmail,
"customerAddressLine1": data.CustomerAddressLine1,
"customerAddressLine2": data.CustomerAddressLine2,
"customerAddressZip": data.CustomerAddressZip,
"customerAddressLocality": data.CustomerAddressLocality,
"customerAddressCountry": data.CustomerAddressCountry,
"customerAddressRegion": data.CustomerAddressRegion,
"providerLogoRepositoryFileId": data.ProviderLogoRepositoryFileId,
"providerName": data.ProviderName,
"providerEmail": data.ProviderEmail,
"providerAddressLine1": data.ProviderAddressLine1,
"providerAddressLine2": data.ProviderAddressLine2,
"providerAddressZip": data.ProviderAddressZip,
"providerAddressLocality": data.ProviderAddressLocality,
"providerAddressCountry": data.ProviderAddressCountry,
"providerAddressRegion": data.ProviderAddressRegion,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) UpdateInvoice(ctx context.Context, tenant, invoiceId string, data InvoiceUpdateFields) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.UpdateInvoice")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := `MATCH (t:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
SET i.updatedAt=$updatedAt`
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"updatedAt": data.UpdatedAt,
}
if data.UpdateStatus && data.Status.String() != "" {
cypher += `, i.status=$status`
params["status"] = data.Status.String()
}
if data.UpdatePaymentLink {
cypher += `, i.paymentLink=$paymentLink`
params["paymentLink"] = data.PaymentLink
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) InvoicePdfGenerated(ctx context.Context, tenant, id, repositoryFileId string, updatedAt time.Time) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoicingCycleWriteRepository.Update")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, id)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice_%s {id:$id})
SET
i.repositoryFileId=$repositoryFileId,
i.updatedAt=$updatedAt`, tenant)
params := map[string]any{
"tenant": tenant,
"id": id,
"updatedAt": updatedAt,
"repositoryFileId": repositoryFileId,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) MarkInvoiceFinalizedEventSent(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.MarkInvoiceFinalizedEventSent")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
WHERE i:Invoice_%s
SET i.techInvoiceFinalizedSentAt=$now`, tenant)
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"now": utils.Now(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) MarkPayNotificationRequested(ctx context.Context, tenant, invoiceId string, requestedAt time.Time) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.MarkPayNotificationRequested")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := `MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
SET i.techPayNotificationRequestedAt=$requestedAt`
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"requestedAt": requestedAt,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) SetPaidInvoiceNotificationSentAt(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.SetPaidInvoiceNotificationSentAt")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
WHERE i:Invoice_%s
SET i.techPaidInvoiceNotificationSentAt=$now`, tenant)
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"now": utils.Now(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) SetPayInvoiceNotificationSentAt(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.SetPayInvoiceNotificationSentAt")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
WHERE i:Invoice_%s
SET i.techPayInvoiceNotificationSentAt=$now`, tenant)
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"now": utils.Now(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) DeleteInitializedInvoice(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.DeleteInitializedInvoice")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[r1:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})<-[r2:HAS_INVOICE]-(:Contract)
WHERE i:Invoice_%s AND i.status=$initializedStatus
DELETE r1,r2,i`, tenant)
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"initializedStatus": neo4jenum.InvoiceStatusInitialized.String(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) DeletePreviewCycleInvoices(ctx context.Context, tenant, contractId, skipInvoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceReadRepository.DeletePreviewCycleInvoices")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.LogFields(log.String("contractId", contractId), log.String("skipInvoiceId", skipInvoiceId))
cypher := `MATCH (:Tenant {name:$tenant})<-[:CONTRACT_BELONGS_TO_TENANT]-(c:Contract{id:$contractId})-[:HAS_INVOICE]->(i:Invoice {dryRun:true, preview: true, offCycle: false})
WHERE i.id <> $skipInvoiceId
OPTIONAL MATCH (i)-[:HAS_INVOICE_LINE]->(il:InvoiceLine)
DETACH DELETE i, il`
params := map[string]any{
"tenant": tenant,
"contractId": contractId,
"skipInvoiceId": skipInvoiceId,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) DeletePreviewCycleInitializedInvoices(ctx context.Context, tenant, contractId, skipInvoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceReadRepository.DeletePreviewCycleInitializedInvoices")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.LogFields(log.String("contractId", contractId), log.String("skipInvoiceId", skipInvoiceId))
cypher := `MATCH (:Tenant {name:$tenant})<-[:CONTRACT_BELONGS_TO_TENANT]-(c:Contract{id:$contractId})-[:HAS_INVOICE]->(i:Invoice {dryRun:true, preview: true, offCycle: false})
WHERE i.id <> $skipInvoiceId and i.status=$initializedStatus
OPTIONAL MATCH (i)-[:HAS_INVOICE_LINE]->(il:InvoiceLine)
DETACH DELETE i, il`
params := map[string]any{
"tenant": tenant,
"contractId": contractId,
"skipInvoiceId": skipInvoiceId,
"initializedStatus": neo4jenum.InvoiceStatusInitialized.String(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) MarkPaymentLinkRequested(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceWriteRepository.MarkPaymentLinkRequested")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.SetTag(tracing.SpanTagEntityId, invoiceId)
cypher := fmt.Sprintf(`MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId})
WHERE i:Invoice_%s
SET i.techPaymentLinkRequestedAt=$now`, tenant)
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
"now": utils.Now(),
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}
func (r *invoiceWriteRepository) DeleteDryRunInvoice(ctx context.Context, tenant, invoiceId string) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InvoiceReadRepository.DeleteDryRunInvoice")
defer span.Finish()
tracing.SetNeo4jRepositorySpanTags(span, tenant)
span.LogFields(log.String("invoiceId", invoiceId))
cypher := `MATCH (:Tenant {name:$tenant})<-[:INVOICE_BELONGS_TO_TENANT]-(i:Invoice {id:$invoiceId, dryRun:true})
OPTIONAL MATCH (i)-[:HAS_INVOICE_LINE]->(il:InvoiceLine)
DETACH DELETE i, il`
params := map[string]any{
"tenant": tenant,
"invoiceId": invoiceId,
}
span.LogFields(log.String("cypher", cypher))
tracing.LogObjectAsJson(span, "params", params)
err := utils.ExecuteWriteQuery(ctx, *r.driver, cypher, params)
if err != nil {
tracing.TraceErr(span, err)
}
return err
}