<?php
use \sven\sys\core as CORE;
CORE::setLogin(true);
CORE::addReplacement('head', 'TITLE', 'Kalkulation');

$mysql = new \sven\sys\mysql\mysql();
$fluent = $mysql->getBuilder();

$options = "";
if($auth->loggedIn()) {
	$query = $fluent->from('t_artikel')->select('t_artikel.*');
	$rows = $query->fetchAll();
	foreach ($rows as $id => $row) {
		$selected = (($row->ID === "1") ? "selected" : "");
		$options .= "<option value='{$row->ID}|{$row->Einkaufspreis}|{$row->Anzahl_pro_Palette}' $selected>{$row->Name}</option>";
	}
}

CORE::addReplacement('main', 'FILE', <<<EOF
<div class="container" id="calc-page">
				<div class="row">
					<div class="col-md-12">
						<h2>Gewinnkalkulation</h2>

						<div class="input-group mb-md-3" id="products-selector">
							<label for="products">Produkt</label>
							<select class="custom-select" id="products">
								<!-- <option value="%PRICE%|%PLT_COUNT%"></option> -->
								$options
							</select>
						</div>
						<div class="my-md-4 form-row">
							<div class="form-group col-md-6">
								<label for="selected-price">Preis (GE)</label>
								<input type="text" class="form-control" id="selected-price" placeholder="Preis" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="selected-plt">Anzahl pro Palette (ME)</label>
								<input type="text" class="form-control" id="selected-plt" placeholder="Anzahl pro Palette" disabled>
							</div>
						</div>
						<div class="form-row">
							<div class="col-md-1"></div>
							<div class="form-group col-md-2">
								<label for="rabatt">Rabatt (%)</label>
								<input type="text" class="form-control" id="rabatt" placeholder="Rabatt">
							</div>
							<div class="form-group col-md-2">
								<label for="skonto">Skonto (%)</label>
								<input type="text" class="form-control" id="skonto" placeholder="Skonto">
							</div>
							<div class="form-group col-md-2">
								<label for="bezugskosten">Bezugskosten (%)</label>
								<input type="text" class="form-control" id="bezugskosten" placeholder="Bezugskosten">
							</div>
							<div class="form-group col-md-2">
								<label for="handelskosten">Handelskosten (%)</label>
								<input type="text" class="form-control" id="handelskosten" placeholder="Handelskosten">
							</div>
							<div class="form-group col-md-2">
								<label for="gewinnzuschlag">Gewinnzuschlag (%)</label>
								<input type="text" class="form-control" id="gewinnzuschlag" placeholder="Gewinnzuschlag">
							</div>
						</div>

						<hr />
						<!-- CALCULATION FIELDS -->
						<h3> Rechnung </h3>

						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="listeneinkaufspreis">Listeneinkaufspreis (GE)</label>
								<input type="text" class="form-control" id="listeneinkaufspreis" placeholder="Listeneinkaufspreis" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="selbstkosten">Selbstkosten (GE) | <span class="info"> &darr; Handelskosten </span></label>
								<input type="text" class="form-control selbstkosten" placeholder="Selbstkosten" disabled>
							</div>
						</div>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="zieleinkaufspreis">Zieleinkaufspreis (GE) | <span class="info">&darr; Rabatt </span></label>
								<input type="text" class="form-control" id="zieleinkaufspreis" placeholder="Zieleinkaufspreis" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="angebotspreis">Angebotspreis (GE) | <span class="info">&darr; Gewinnzuschlag </span></label>
								<input type="text" class="form-control" id="angebotspreis" placeholder="Angebotspreis" disabled>
							</div>
						</div>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="bareinkaufspreis">Bareinkaufspreis (GE) | <span class="info">&darr; Skonto </span></label>
								<input type="text" class="form-control" id="bareinkaufspreis" placeholder="Bareinkaufspreis" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="angebotspreis_mwst">Angebotspreis(MwSt.) (19%) (GE) | <span class="info">&darr; Mehrwertsteuer </span></label>
								<input type="text" class="form-control" id="angebotspreis_mwst" placeholder="Angebotspreis (MwSt.)" disabled>
							</div>
						</div>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="bezugspreis">Bezugspreis (GE) | <span class="info">&darr; Bezugskosten </span></label>
								<input type="text" class="form-control" id="bezugspreis" placeholder="Bezugspreis" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="angebotspreis_stk">Angebotspreis pro Stück (GE)</label>
								<input type="text" class="form-control" id="angebotspreis_stk" placeholder="Angebotspreis (Stückzahl)" disabled>
							</div>
						</div>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="selbstkosten">Selbstkosten (GE)</label>
								<input type="text" class="form-control selbstkosten" placeholder="Selbstkosten" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="rohgewinn">Rohgewinn (GE)</label>
								<input type="text" class="form-control bg-success" id="rohgewinn" placeholder="Rohgewinn" disabled>
							</div>
						</div>

						<hr />
						<!-- Konkurrenzvergleich -->
						<h3> Konkurrenzpreis </h3>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="selbstkosten">Selbstkosten (GE)</label>
								<input type="text" class="form-control selbstkosten" placeholder="Selbstkosten" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="konkurrenzpreis">Konkurrenzpreis (GE)</label>
								<input type="text" class="form-control" id="konkurrenzpreis" placeholder="Konkurrenzpreis">
							</div>
						</div>
						<div class="form-row">
							<div class="form-group col-md-6">
								<label for="gewinn">Gewinn (GE)</label>
								<input type="text" class="form-control" id="gewinn" placeholder="Gewinn" disabled>
							</div>
							<div class="form-group col-md-6">
								<label for="gewinnPrcnt">Gewinn (%)</label>
								<input type="text" class="form-control" id="gewinnPrcnt" placeholder="Gewinn in Prozent" disabled>
							</div>
						</div>
					</div>
				</div>
			</div>
EOF
);
?>
