From 338053e0dbc884b432069aca3f59938fd66e4234 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 5 Mar 2025 02:38:17 -0800 Subject: [PATCH 1/2] hledger-flow: btcpayserver: add taxed_as INCOME tag All 'IN' direction is INCOME by default. --- .../accounts/btcpayserver/btcpayserver-shared.rules | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules index 18ec31b..ca58e18 100644 --- a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules +++ b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules @@ -38,21 +38,23 @@ if %Accounted ^[^a-z]*$ # Comment # +# NOTE: all IN assumed to be INCOME + # Default comment -comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction +comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction, taxed_as:INCOME # Comment w/ item code if %InvoiceItemCode [a-z0-9] - comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, item_code:%InvoiceItemCode, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction + comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, item_code:%InvoiceItemCode, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction, taxed_as:INCOME # Comment w/ buyer email if %BuyerEmail [a-z0-9] - comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, email:%BuyerEmail, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction + comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, email:%BuyerEmail, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction, taxed_as:INCOME # Comment w/ both item code + buyer email if %InvoiceItemCode [a-z0-9] & %BuyerEmail [a-z0-9] - comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, item_code:%InvoiceItemCode, email:%BuyerEmail, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction + comment created:%InvoiceCreatedDate, expired:%InvoiceExpirationDate, store_id:%StoreId, order_id:%OrderId, invoice_id:%InvoiceId, item_code:%InvoiceItemCode, email:%BuyerEmail, type:%PaymentType, to_address:%Destination, txid:%txid, index:%index, status:%InvoiceStatus, direction:%direction, taxed_as:INCOME # Comment for "Wallets" export if %direction ^OUT$ From 99c7075742d0b0abe54772080a2c390631c1c9cd Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 5 Mar 2025 02:39:12 -0800 Subject: [PATCH 2/2] hledger-flow: btcpayserver: add local timezone support --- .../btcpayserver/btcpayserver-shared.bash | 30 +++++++++++++++---- .../btcpayserver/btcpayserver-shared.rules | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.bash b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.bash index cb74e17..f188f68 100755 --- a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.bash +++ b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.bash @@ -77,13 +77,29 @@ function btcpayserver::legacy() if (NR<2 || $1 !~ global_year) next - printf $1 OFS # ReceivedDate + # ReceivedDate (w/ local timezone added) + sub(/ /, "T", $1) # HACK: makes arg-friendly by removing space + cmd = "date \"+%F %T %z\" --date="$1 | getline date + printf date OFS + printf $2 OFS # StoreId printf $3 OFS # OrderId printf $4 OFS # InvoiceId - printf $5 OFS # InvoiceCreatedDate - printf $6 OFS # InvoiceExpirationDate - printf $7 OFS # InvoiceMonitoringDate + + # InvoiceCreatedDate (w/ local timezone added) + sub(/ /, "T", $5) + cmd = "date \"+%F %T %z\" --date="$5 | getline date + printf date OFS + + # InvoiceExpirationDate (w/ local timezone added) + sub(/ /, "T", $6) + cmd = "date \"+%F %T %z\" --date="$6 | getline date + printf date OFS + + # InvoiceMonitoringDate (w/ local timezone added) + sub(/ /, "T", $7) + cmd = "date \"+%F %T %z\" --date="$7 | getline date + printf date OFS # PaymentId # NOTE: BTCPay Server will append the block index as "-N" to the txid @@ -160,7 +176,11 @@ function btcpayserver::wallets() if ($6 !~ /^-/) next - printf $1 OFS # Date (ReceivedDate) + # Date (ReceivedDate w/ local timezone added) + sub(/ /, "T", $1) # HACK: makes arg-friendly by removing space + cmd = "date \"+%F %T %z\" --date="$1 | getline date + printf date OFS + printf OFS # (StoreId) printf OFS # (OrderId) printf $4 OFS # InvoiceId (InvoiceId) diff --git a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules index ca58e18..1140695 100644 --- a/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules +++ b/container/src/hledger-flow/accounts/btcpayserver/btcpayserver-shared.rules @@ -19,7 +19,7 @@ fields ReceivedDate,StoreId,OrderId,InvoiceId,InvoiceCreatedDate,InvoiceExpirationDate,InvoiceMonitoringDate,txid,index,Destination,PaymentType,CryptoCode,Paid,NetworkFee,ConversionRate,PaidCurrency,InvoiceCurrency,InvoiceDue,InvoicePrice,InvoiceItemCode,InvoiceItemDesc,InvoiceFullStatus,InvoiceStatus,InvoiceExceptionStatus,BuyerEmail,Accounted,direction,subaccount # NOTE: BTCPayServer exports to localtime -date-format %Y-%m-%d %H:%M:%S +date-format %Y-%m-%d %H:%M:%S %z date %ReceivedDate description %ReceivedDate