GithubHelp home page GithubHelp logo

webd97 / rewe-ebon-parser Goto Github PK

View Code? Open in Web Editor NEW
40.0 7.0 3.0 321 KB

This library parses REWE eBons into JS objects

Home Page: https://www.npmjs.com/package/rewe-ebon-parser

TypeScript 99.02% JavaScript 0.98%
rewe ebon payback

rewe-ebon-parser's Introduction

REWE eBon parser

This library parses REWE eBons into JS objects.

Installation

$ npm install --save rewe-ebon-parser

Usage

async function main() {
    const dataBuffer = fs.readFileSync('ebon.pdf');
    const receipt = await parseEBon(dataBuffer);
    console.log(JSON.stringify(receipt, undefined, 2));
}

main().catch(console.error);

The parser will perform a quick check in order to find out if it missed an item of the eBon by comparing the eBon's total sum and its own total sum. If there is a mismatch, an Error is thrown:

Error: Something went wrong when parsing the eBon: The eBon states a total sum of 50.27 but the parser only found items worth 45.69.

If this happens to you, it is likely that your eBon uses a slightly different format. In this case, please open an issue on GitHub.

Example

{
  "date": "2019-12-07T16:21:00.000Z",
  "market": "0449",
  "cashier": "545454",
  "checkout": "3",
  "vatin": "DE812706034",
  "items": [
    {
      "taxCategory": "B",
      "name": "SCHW.SCHINKEN",
      "amount": 1,
      "subTotal": 1.99,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "GULASCHSUPPE",
      "amount": 1,
      "subTotal": 2.99,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "SCHINKENWURST",
      "amount": 1,
      "subTotal": 0.99,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "TEEWURST FEIN",
      "amount": 1,
      "subTotal": 0.99,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "ROHSCHINKEN GEW.",
      "amount": 1,
      "subTotal": 1.79,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "CARACTERE SCHEI.",
      "amount": 1,
      "subTotal": 1.49,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "OFENKAESE WUERZ.",
      "amount": 1,
      "subTotal": 2.69,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "1688 MEHRKORN",
      "amount": 1,
      "subTotal": 1.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "BUTTERTOAST",
      "amount": 1,
      "subTotal": 0.69,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "SONNTAGSBROETCH.",
      "amount": 1,
      "subTotal": 0.99,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "BIO EIER M+L KLA",
      "amount": 1,
      "subTotal": 2.15,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "RAMA M.BUTTER+ME",
      "amount": 1,
      "subTotal": 1.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "H-MILCH GVO-FREI",
      "amount": 4,
      "subTotal": 2.92,
      "paybackQualified": true,
      "unit": "Stk",
      "pricePerUnit": 0.73
    },
    {
      "taxCategory": "B",
      "name": "TK HAE.CORD.BLEU",
      "amount": 1,
      "subTotal": 2.89,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "PIZZA SALAMI",
      "amount": 1,
      "subTotal": 2.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "STEINOFEN PIZZA",
      "amount": 1,
      "subTotal": 2.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "JA! WEIZENMEHL",
      "amount": 1,
      "subTotal": 0.39,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "FUSILLI",
      "amount": 1,
      "subTotal": 0.39,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "PENNE RIGATE",
      "amount": 1,
      "subTotal": 0.39,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "SPAGHETTIGERICHT",
      "amount": 1,
      "subTotal": 0.69,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "LECKER F. RUEH.",
      "amount": 1,
      "subTotal": 3.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "SAMT R. FRUECHTE",
      "amount": 1,
      "subTotal": 2.19,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "CRUNCHIPS WESTER",
      "amount": 1,
      "subTotal": 1.39,
      "paybackQualified": true
    },
    {
      "taxCategory": "B",
      "name": "CRUNCHIPS CHEESE",
      "amount": 1,
      "subTotal": 1.39,
      "paybackQualified": true
    },
    {
      "taxCategory": "A",
      "name": "FRUEH KOELSCH",
      "amount": 1,
      "subTotal": 4.29,
      "paybackQualified": true
    },
    {
      "taxCategory": "A",
      "name": "PFAND 0,48 EUR",
      "amount": 1,
      "subTotal": 0.48,
      "paybackQualified": false
    },
    {
      "taxCategory": "A",
      "name": "GAFFEL FASSBRAUS",
      "amount": 1,
      "subTotal": 3.79,
      "paybackQualified": true
    },
    {
      "taxCategory": "A",
      "name": "PFAND 0,48 EUR",
      "amount": 1,
      "subTotal": 0.48,
      "paybackQualified": false
    },
    {
      "taxCategory": "B",
      "name": "LUNGO KAPSELN",
      "amount": 2,
      "subTotal": 3.98,
      "paybackQualified": true,
      "unit": "Stk",
      "pricePerUnit": 1.99
    },
    {
      "taxCategory": "A",
      "name": "Mitarbeiterrabatt 5%",
      "amount": 1,
      "subTotal": -0.4,
      "paybackQualified": false
    },
    {
      "taxCategory": "B",
      "name": "Mitarbeiterrabatt 5%",
      "amount": 1,
      "subTotal": -2.2,
      "paybackQualified": false
    }
  ],
  "total": 50.27,
  "given": [
    {
      "type": "REWE Guthaben",
      "value": 30
    },
    {
      "type": "EC-Cash",
      "value": 20.27
    }
  ],
  "payback": {
    "card": "#########9334",
    "pointsBefore": 4,
    "earnedPoints": 405,
    "basePoints": 24,
    "couponPoints": 381,
    "qualifiedRevenue": 49.31,
    "usedCoupons": [
      {
        "name": "eCoupon 10FACH P. Milch",
        "points": 9
      },
      {
        "name": "eCoupon 10FACH Punkte Bier",
        "points": 27
      },
      {
        "name": "eCoupon 15FACH Punkte",
        "points": 336
      },
      {
        "name": "Coupon Brotaufstrich10-fach",
        "points": 9
      }
    ],
    "usedREWECredit": 30,
    "newREWECredit": 0
  },
  "taxDetails": {
    "total": {
      "net": 46.17,
      "tax": 4.1,
      "gross": 50.27
    },
    "A": {
      "taxPercent": 19,
      "net": 7.26,
      "tax": 1.38,
      "gross": 8.64
    },
    "B": {
      "taxPercent": 7,
      "net": 38.91,
      "tax": 2.72,
      "gross": 41.63
    }
  }
}

rewe-ebon-parser's People

Contributors

bitowl avatar crawlercode avatar dependabot[bot] avatar webd97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rewe-ebon-parser's Issues

Floating point error in missing item check

Thank you for building this library. I'm using it to automatically parse incoming mails containing eBons into a database, so that we can easily distribute costs via Splitwise.

This anonymized eBon 2020-03-13T19_17_00.000Z.pdf produces the following error:
Error: Something went wrong when parsing the eBon: The eBon states a total sum of 1964.9999999999998 but the parser only found items worth 1965.

My quick workaround was to round the totals to two after-comma digits before comparing them:

if (realTotalInCents.toFixed(2) != totalInCents.toFixed(2)) {

Item name cut off at ampersand (&)

Hi,

the parser seems to have a problem with an ampersand "&" in the product name. I had the item "BUD & TERENCE" on my ebon
What i received back from the parser was " TERENCE" (notice the leading space).

Edit: Had a short look, it probably just needs an adjustment of the regex in line 38

Payback parsing not working anymore

I found a new format for the payback section on my latest ebon:

      Ihre REWE PAYBACK Vorteile heute
     PAYBACK Karten-Nr.: #############
      Punktestand vor Einkauf: 6.922
    Punktestand entspricht: 69,22 EUR

    Sie erhalten 14 PAYBACK Punkte auf 
   einen PAYBACK Umsatz von 29,79 EUR!  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.