bic / wave-cli-app

0 stars 0 forks source link

display_bill(order, use_callbacks) #32

Open paulbalomiri opened 11 years ago

paulbalomiri commented 11 years ago

A function regenerating the table containing the ordered items and their prices

The function display_bill is a wrapper around calculate_bill_items() and display_bill_table()

products= {
    "offers": [
        {
            "id": 123,
            "name": "Stiuca batuta",
            "price": 24,
            "options": [
                {
                    "id": 345,
                    "name": "tacamuri metalice gratuite",
                    "qty_included": "1",
                    "price": "5"
                },
                {
                    "id": 456,
                    "name": "tacamuri metalice",
                    "price": 5
                }
            ],
            "vat_percent_default": 24
        }
    ]
};

display_bill(order, use_callbacks) {
  table_content=calculate_bill_items(order,products);
  display_bill_table(table_content);
  if(use_callbacks){
   setTotalPrice(table_content.total, table_content.tips);
  }

}

display_bill(order, use_callbacks)

Within the function table_content is created by _calculate_billitems and consumed by _display_billtable, both functions being described below

The table_content variable used in the example above can be anything as long as it contains

This function calculates the contents of the table as displayed in the "Nota de plata detaliata" part of the order view (See #21 )

Return value condition: the JSON structure must contain a "total" and a "tips" entry both having stringified currency values

The function must match the ids supplied in the order against the per offer options and the global options.

In the table the product and the options are listed one beneath the other with their respective prices also being listed independently

offer_changer mechanism

In the case of a offer option having the "offer_changer":"true" in their description the following names can be formed:

In case the orders.offers[id=a].qty >1 the included options are also multiplied. Example:

in this case the bill shall contain:

This function displays the table content as supplied in table_content

See #21 for the way the table shall be structured.

CSS

The page shall contain the needed css, as the page will not be loaded using whe web, and thus has no possibility to load additional content.

amneacsu commented 11 years ago

Am pus pe server o varianta preliminara. Ruleaza asta:

node /home/andrei/display_bill/display_bill.js

Functioneaza dar e putin barbar. Discutam cum mai modificam structura in products.json si order.json.

paulbalomiri commented 11 years ago

Salut,

M-am uitat peste script, si imi pare corect. Pentru production mai trebuiesc implementate urmatoarele schimbari:

Structura (EBNF) , majuscute = terminal:

name= PRODUCT |  PRODUCT , optionlist
optionlist= option | optionlist , SI, option 
option = CU  OPTIONNAME | CU numeric OPTIONNAME

Structura asta trebuie tradus pe un pom corespunzator. Exemplu: stiuca batuta, 1 supa(3 incluse) , 5 tacamuri(2) incluse, 1 sos(1 inclus)

              |-------------.
              | name        |
              |.............|
 ,__________..='_        `._
 |PRODUCT       |        ,''''|
 |stiuca batuta |      .'|AND |
 '`''''''''''''''    .'  '`'''`.
         ,_________.'_          `-.
         | SUPA       |          ,''''|
         | qty:1,inc:3|          |AND |
         '`'''''''''''           .-'''-.
                              .-'       `.
                     ,_____.='____   ,____`=._____
                     | TACAMURI   |  | SOS        |
                     | qty:5,inc:2|  | qty:1,inc:1|
                     '`'''''''''''   '`'''''''''''

Pomul se rezolva recursiv intr-un set de functii (localizabile):

                   |-------------.
                   | name        |
                   |.............|
      ,__________..='_        `._
      |PRODUCT       |        ,''''|
      |stiuca batuta |      .'|AND |
      '`''''''''''''''    .'  '`'''`.
              ,_________.'_          `-.
              | SUPA       |   ,'''''''''''''''|
              | qty:1,inc:3|   | cu 3 tacamuri |
              '`'''''''''''    | suplimentare  |
                               `...............|

In final dupa ce pomul a fost rezolvalt recursiv va trebui sa rezulte stiuca batuta cu 2 supe si cu 3 tacamuri

paulbalomiri commented 10 years ago

Testsuite

A Python Testsuite, named test_javascript.py is available to ease with quick testcase generation in the project libs/maivic-mobilpay-server.

Installation

In order to use it Python PyV8 and all it's dependencies must be installed.

The testsuite accepts tests from the directory https://github.com/bic/maivic-server/blob/master/libs/maivic-mobilpay-server/res/javascript and executes the function with the same name from the same named file like this: