Skip to content

Commit

Permalink
Add 'void' command
Browse files Browse the repository at this point in the history
  • Loading branch information
Juerd committed Jan 19, 2023
1 parent f479060 commit 10d1965
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugins/products.pod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ products - RevBank plugin for selling products
=head1 SYNOPISIS

8710447032756 0.80 Festini Peer
4029764001807,clubmate 1.40 Club-Mate +pf
4029764001807,clubmate 1.40 Club-Mate +half +pf
pf 0.15@+pfand Pfand NRW-Flasche
+half -50% 50% discount \o/

=head1 DESCRIPTION

Expand Down
38 changes: 35 additions & 3 deletions plugins/statiegeld_tokens
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!perl

# TODO:
# voiding of tokens
# querying of tokens
# expiry of tokens

use List::Util;

HELP void => "Destroy deposit tokens";

my $ttl = 100 * 86400; # expiry time in seconds
my $filename = "revbank.statiegeld";

Expand Down Expand Up @@ -159,6 +158,9 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
$entry->quantity($available);
$warnings_by_type{$type}++;
}
if ($entry->attribute('statiegeld_VOID_TOKENS')) {
$cart->delete($entry);
}

splice @{ $tokens_by_type->{$type} }, 0, $entry->quantity;
$tokens_changed++;
Expand Down Expand Up @@ -197,3 +199,33 @@ sub hook_user_info ($class, $username, @) {
@info = ("none") if not @info;
print "Deposit tokens: ", join(", ", @info), "\n";
}

sub command($self, $cart, $command, @) {
$command eq 'void' or return NEXT;

my $found =0;
for my $entry ($cart->entries('plugin')) {
next if $entry->attribute('plugin') ne 'statiegeld';
$found++;
}
$found or return REJECT, "Add deposit returns first.";

return "\e[31;1mDeposit token destruction mode.\e[0m\n\n"
. "The tokens will be deleted irrevokably and you will NOT RECEIVE THE MONEY.\n"
. "Type 'yes' if you are sure", \&void;
}

sub void :Tab(yes,no) ($self, $cart, $input, @) {
if ($input ne 'yes') {
print "Destruction cancelled.\n";
return ACCEPT;
}

for my $entry ($cart->entries('plugin')) {
next if $entry->attribute('plugin') ne 'statiegeld';
$entry->attribute('statiegeld_VOID_TOKENS', 1);
}

print "\e[31;1mDeposit token destruction mode activated.\e[0m\n";
return ACCEPT;
}
29 changes: 27 additions & 2 deletions revbank.accounts
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
juerd +163.48 2022-06-04_02:19:56 +@2021-12-03_18:27:54
bla -36.00 2022-01-19_17:11:25 -@2022-01-19_17:00:43
-cash -89663.00 2023-01-19_02:25:17 -@2022-08-28_23:45:54
+sales/products +627.00 2023-01-19_05:23:33 +@2022-08-28_23:46:08
ZeroCool +4 2022-08-29_17:46:21 +@2022-08-28_23:51:21
CrashOverride -108.52 2023-01-05_20:49:17 -@2022-08-29_17:52:51
xyzzy -95.07 2023-01-19_05:23:33 -@2023-01-19_03:11:44
aoeu -20.67 2022-12-25_04:07:20 -@2022-12-25_01:56:03
juerd -26.05 2023-01-19_03:11:06 -@2023-01-16_06:01:47
+sales/market +16.00 2023-01-16_05:44:46 +@2022-08-29_17:40:38
-undo 0.00 2022-08-29_16:13
-pfand +0.75 2022-12-12_22:30:11 +@2022-11-24_22:32:35
meh 0.00 2022-10-29_00:23:10
mekker +0 2022-10-29_01:03:27 0@2022-10-29_01:03:27
#foo 0.00 2022-11-01_04:26:16
testje -215.00 2022-11-01_04:43:28 -@2022-11-01_04:27:53
-deposits/reimburse -12.34 2022-12-12_23:34:33 -@2022-12-12_23:34:33
+sales/unlisted +0.15 2022-12-24_05:40:39 +@2022-12-24_05:40:39
+sta 0.00 2022-12-24_21:13:52
+test 0.00 2022-12-24_21:13:52
+statiegeld +40.80 2023-01-19_05:23:33 +@2022-12-24_21:35:01
+stroomgebruik +0.80 2022-12-24_22:35:47 +@2022-12-24_22:35:47
+sales/batt +2.40 2023-01-05_20:39:46 +@2022-12-24_22:30:08
-korting +0.00 2022-12-25_04:28:09 0@2022-12-25_04:28:09
-deposits/other -321.00 2023-01-16_04:24:21 -@2023-01-07_00:35:46
-bounties -45.00 2022-12-25_05:05:39 -@2022-12-25_04:23:46
-expenses/bounties -20.00 2022-12-25_05:06:40 -@2022-12-25_05:06:34
kookpotje +3.00 2023-01-05_20:49:17 +@2023-01-05_20:49:17
-deposits/iban 0.00 2023-01-16_05:47:03
4 changes: 2 additions & 2 deletions revbank.market
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Price =
#aeouaoeuaeou# Price =
# Seller Barcode Seller + Space Description

Juerd sku81873 6.00 2.00 Cijfertjes/ledjes/knopjes-module
Juerd sku81873 6 2 Cijfertjes/ledjes/knopjes-module

5 changes: 4 additions & 1 deletion revbank.plugins
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ adduser
edit

beep_terminal
dinnerbonus

# Then, plugins that apply heuristics

repeat
statiegeld
statiegeld_tokens
products # matches product IDs (barcodes)
market # also matches product IDs
withdraw # matches amounts
users # matches usernames
deposit # wants to be after 'users'
#deposit_methods # Extra options for 'deposit'. Edit/configure first!
deposit_methods # Extra options for 'deposit'. Edit/configure first!
#deposit_iban_qr # QR code display, edit/configure first! (needs qrencode(1))
58 changes: 58 additions & 0 deletions revbank.products
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
### THIS IS THE EXAMPLE FILE; DON'T ADD PRODUCTS, BUT MAKE A NEW FILE ###

# Deze in principe niet veranderen want dat heeft invloed op producten
# die al eerder verkocht zijn. Omschrijving aanpassen kan geen kwaad.
+sb 0.15@+statiegeld Statiegeld blikje
+sf 0.15@+statiegeld Statiegeld plastic flesje
+sm 0.15@+statiegeld Statiegeld Mehrwegflasche
matekrat 1.50@+statiegeld Statiegeld matekrat excl. inhoud

# Let op: als een product een statiegeld addon (bijv. +sb) heeft, dat niet
# meer veranderen, want dan kan het product niet meer worden ingeleverd.



# Empty lines and lines beginning with # are ignored.

Expand All @@ -23,3 +34,50 @@
05414359710322 0.50 Chips
05414359710315 0.50 Chips
zakjechips 0.50 Chips


clubmate,4029764001807 1.40 Club-Mate +sm
87124385 1.10 Chocomel
8710447032756 0.80 Festini peer
tostikaas 1.15 Tosti kaas
4001724035848 5.10 Pizza Veggie Mix

cola,5000112638745 0.90 Coca-Cola Zero, blik 33 cl +korting +sb
pizza 4.50 Pizza +sgo
+korting -50% Yay korting

dinges 0.00 Dingeskitje +aa +pcb +koppla +j +korting
aa 0.20@+sales/batt Batterij
pcb 0.80 pcb
koppla 5.00 Koppla
j 0.10@juerd Gratis geld voor juerd

#moo 2,151 bla
#meh 1.00 blaaat +mekker
bla -5

#aap 1.00 ding +noot
#noot 9.99 dinges deze niet
#+noot 2.00 dinges +mies
#mies 3.00 donges +aap

sgo 0.80@+stroomgebruik Stroomgebruik oven

nietsb -0.15@+statiegeld WHoaaa

korting -0.10@-korting Korting \o/

BOUNTY1 -10.00@-expenses/bounties Bedankt voor dingen!! +j
BOUNTY2 -5.00@-expenses/bounties Bedankt en zo


example_id 1.00 Example product +something
+something 1.00 Product that has an id that starts with plus
example,+alias 1.00 Product that has an alias that starts with plus


example_id1 1.00 Example product+something
example_id2 1.00 Example product + something
more_stuff 1.00 Example product with +something but not at the end
bbq 1.00 3+ pieces of meat

0 comments on commit 10d1965

Please sign in to comment.