From 10d1965bf04568705afeb54b7b58a3d8c29f443c Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Thu, 19 Jan 2023 05:25:31 +0100 Subject: [PATCH] Add 'void' command --- plugins/products.pod | 3 +- plugins/statiegeld_tokens | 38 +++++++++++++++++++++++-- revbank.accounts | 29 ++++++++++++++++++-- revbank.market | 4 +-- revbank.plugins | 5 +++- revbank.products | 58 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 9 deletions(-) diff --git a/plugins/products.pod b/plugins/products.pod index 8d42ba1..c989018 100644 --- a/plugins/products.pod +++ b/plugins/products.pod @@ -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 diff --git a/plugins/statiegeld_tokens b/plugins/statiegeld_tokens index 6c0d7c7..05699fa 100644 --- a/plugins/statiegeld_tokens +++ b/plugins/statiegeld_tokens @@ -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"; @@ -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++; @@ -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; +} diff --git a/revbank.accounts b/revbank.accounts index 7b3c499..18c9bd0 100644 --- a/revbank.accounts +++ b/revbank.accounts @@ -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 diff --git a/revbank.market b/revbank.market index 34bb477..b1153f2 100644 --- a/revbank.market +++ b/revbank.market @@ -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 diff --git a/revbank.plugins b/revbank.plugins index 5a16028..927549e 100644 --- a/revbank.plugins +++ b/revbank.plugins @@ -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)) diff --git a/revbank.products b/revbank.products index 7e70f78..9c60328 100644 --- a/revbank.products +++ b/revbank.products @@ -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. @@ -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 +