<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8">
    <meta lang="de">
    <title>Inventur</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="css/lib/materialize.min.css">
    <link rel="manifest" href="manifest.json">
</head>

<body>
    <div id="app">
        <nav class="nav-extended teal" >
            <div class="nav-wrapper container">
                <a href="#" class="brand-logo">Inventur</a>
            </div>
            <div class="nav-content container">
                <ul class="tabs tabs-transparent">
                    <li class="tab"><a href="#article" @click="view = 'article';">Artikelliste</a></li>
                    <li class="tab"><a href="#inventory" class="active" @click="view = 'inventur';">Inventur</a></li>
                    <li class="tab"><a href="#calc" @click="view = 'calc';">Rechner</a></li>
                </ul>
            </div>
        </nav>
        <div class="container">
            <div class="valign-wrapper" style="height: 90vh" v-if="!ready">
                <div class="progress">
                    <div class="indeterminate"></div>
                </div>
            </div>
            <div class="col s12" id="article" v-if="ready">
                <div v-for="(a, index) in articles" class="card">
                    <div class="card-content row">
                        <span class="card-title">{{ a.name }}</span>
                        <div class="input-field inline col s12">
                            <input v-model="a.name" placeholder="Artikelname" class="validate" :id="'a_name_'+index">
                            <label :for="'a_name_'+index" class="active">Name</label>
                        </div>
                        <div class="input-field col s8">
                            <input v-model.number="a.content.size" placeholder="Gesamtinhalt" type="number" class="validate" step="0.01" :id="'a_csize_'+index">
                            <label :for="'a_csize_'+index" class="active">Gesamtinhalt</label>
                        </div>
                        <div class="input-field col s4">
                            <input v-model="a.dimension" placeholder="Dimension" class="validate" :id="'a_dim_'+index" max="5">
                            <label :for="'a_dim_'+index" class="active">Dimension</label>
                            <span class="helper-text">z.B. Liter(l), Stück(Stk.)</span>
                        </div>
                        
                        <div class="input-field col s4">
                            <input v-model.number="a.portion.size" placeholder="Gesamtinhalt" type="number" class="validate" step="0.01" :id="'a_psize_'+index" max="5">
                            <label :for="'a_psize_'+index" class="active">Portionsinhalt</label> 
                        </div>
                        <div class="input-field col s4">
                            <input v-model="a.portion.type" placeholder="Art" class="validate" :id="'a_ptype_'+index" max="5">
                            <label :for="'a_ptype_'+index" class="active">Portionsbezeichnung</label>
                        </div>
                        <div class="input-field col s4">
                            <input v-model.number="a.portion.price" placeholder="Preis" type="number" step="0.01" class="validate" :id="'a_pprice_'+index">
                            <label :for="'a_pprice_'+index" class="active">Portionspreis in €</label>
                        </div>
                        
                        <div class="col s12 right">
                            <span class="right">Gesamtpreis {{ a.ContentPrice | currency }}</span> 
                        </div>
                        
                    </div>
                    <div class="card-action">
                        <a class="" href="#">Artikel löschen</a>
                    </div>
                </div>
                <div slot="footer">
                    
                </div>
            </div>
            <div class="col s12" id="inventory" v-if="ready">
                <div v-for="(a, index) in inventory.ug" class="card hoverable">
                    <div class="card-content row">
                        <div class="col s12 m2">{{ a.article.name }}</div>
                        <div class="input-field col s6 m2">
                            <input v-model.number="a.start" placeholder="Anfang" title="Anfang" type="number" :step="a.StepSize" :id="'i_s_'+index">
                            <label :for="'i_s_'+index" class="active">Beginn</label>
                        </div>
                        <div class="input-field col s6 m2 inline">
                            <input v-model.number="a.fetched" placeholder="Zugang" title="Zugang" type="number" :step="a.StepSize" :id="'i_f_'+index">
                            <label :for="'i_f_'+index" class="active">Zugang</label>
                        </div>
                        <div class="input-field col s6 m2">
                            <input v-model.number="a.end" placeholder="Ende" title="Ende" type="number" :step="a.StepSize" :id="'i_e_'+index">
                            <label :for="'i_e_'+index" class="active">Ende</label>
                        </div>
                        <div class="input-field col s6 m2">
                            <input v-model.number="a.lost" placeholder="Verlust" title="Verlust" type="number" :step="a.StepSize" :id="'i_l_'+index">
                            <label :for="'i_l_'+index" class="active">Verlust</label>
                        </div>
                        <div class="col m2 right right-align"> <b>{{a.article.portion.price | currency }} &times; {{ a.Sold | number(a.PortionPrecision) }} {{ a.article.PortionType }} <br/>&equals; {{ a.Sale | currency }}</b></div>
                    </div>
                    
                </div>
                <div class="card teal lighten-2 white-text">
                    <div class="card-content">
                        <h5>Gesamtsumme: {{ sales_ug | currency }}</h5>
                    </div>
                </div>
            </div>
            <div class="col s12" id="calc" v-if="ready">
                <div class="row">
                    <div class="col s12 m4 card darken-4 grey grey-text text-lighten-2">
                        <table class="card-content">
                            <tr v-for="item in bonned(bon)">
                                <td class="right">{{ item.count }} &times;</td>
                                <td>{{ item.name }}</td>
                                <td class="right">{{ item.price * item.count | currency }}</td>
                            </tr>
                            <tr class="white-text">
                                <th class="right">{{ bon_sum > 0 ?bon_sum: "" }}</th>
                                <th>{{ bon_sum > 0 ? "Artikel": ""}}</th>
                                <th class="right">{{ bon_price }}</th>
                            </tr>
                        </table>
                    </div>
                    <div class="col s12 m8">
                        <div class="row">
                            <div class="col s4" v-for="a in bon">
                                <button class="waves-effect waves-light btn-large btn-flat col s12"  @click="a.count++;">{{ a.name }}</button>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col s4">
                                <button class="waves-effect waves-light btn-large orange col s12" @click="resetBon">Reset</button>
                            </div>
                        </div>
                    </div>
                </div>
    
            </div>
        </div>
        <div class="fixed-action-btn">
            <a href="#" class="btn-floating btn-large" :class="[ view == 'article' ? 'orange' : (view == 'inventur' ? 'teal' : 'brown') ]">
                <i class="large material-icons">more</i>
            </a>
            <ul>
                <li v-if="view == 'article'">
                    <a href="#" class="btn-floating tooltipped" data-position="left" @click="storeArticles" data-tooltip="Artikelliste speichern"><i class="material-icons">save</i></a>
                </li>
                <li v-if="view == 'article'">
                    <a href="#" class="btn-floating tooltipped" data-position="left" @click="addArticle" data-tooltip="Artikel hinzufügen"><i class="material-icons">add</i></a>
                </li>
                <li v-if="view == 'inventur'">
                    <a href="#" class="btn-floating tooltipped" data-position="left" @click="storeArticles" data-tooltip="Artikelliste speichern"><i class="material-icons">save</i></a>
                </li>
                <li v-if="view == 'inventur'">
                    <a href="#" class="btn-floating tooltipped" data-position="left" @click="addArticle" data-tooltip="Artikel hinzufügen"><i class="material-icons">add</i></a>
                </li>
            </ul>
        </div>
        
    </div>
    <script src="js/lib/jquery.min.js"></script>
    <script src="js/lib/materialize.min.js"></script>
    <script src="js/lib/moment-with-locales.min.js"></script>
    <script src="js/lib/accounting.min.js"></script>
    <script src="js/lib/vue-dev.js"></script>
    <script src="js/lib/vue-resource.min.js"></script>
    <script src="js/site.js"></script>
    <script src="js/app.js"></script>
    <script src="js/model/article.js"></script>
    <script src="js/model/inventory_article.js"></script>
    <script>
        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('serviceWorker.js')
                .then(function(registration) {
                    console.log("[ServiceWorker] registration successful with scope: ", registration.scope);
                }).catch(function(err){
                    console.error("[ServiceWorker] registration failed: ", err);
                })
        }
    </script>
</body>

</html>
