Exemple #1
0
function tekstopslag($sort, $id)
{
    global $bgcolor;
    global $bgcolor5;
    global $db;
    global $sqhost;
    global $squser;
    global $sqpass;
    $linjebg = NULL;
    sidehoved($id, "ordre.php", "", $fokus, "Kundeordre {$id} - Vareopslag");
    //#cho "host: $sqhost<br>dbname: $db<br>user: $squser<br>pasword: $sqpass";
    //print "<td width=100% align=\"center\">\n";
    print "<form name=\"ordre\" action=\"ordre.php?id={$id}\" method=\"post\">\n";
    print "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"ordretekstSort\">\n";
    //print "<tbody class=\"dataTableLink dataTableZebra\">\n";
    // indsæt sagens omfang her
    $r = db_fetch_array(db_select("select * from ordrer where id='{$id}'", __FILE__ . " linje " . __LINE__));
    $sag_id = $r['sag_id'] * 1;
    #20140425 indsat '*1'
    if ($sag_id) {
        #20140425 Kaldes kun hvis sag_id
        $r = db_fetch_array(db_select("select * from sager where id='{$sag_id}'", __FILE__ . " linje " . __LINE__));
        $omfang = $r['omfang'];
        if ($omfang) {
            print "<tbody class=\"dataTableLink dataTableBottomBorderGray\">\n";
            print "<tr><td colspan=\"2\"><p style=\"text-align:center;\"><b>Omfang</b></p></td><td align=\"left\" title=\"" . findtekst(491, $sprog_id) . "\" style=\"width:800px;\"><!--tekst 491--><a href=\"ordre.php?id={$id}&amp;tekst_sag_id={$sag_id}\">{$omfang}</a></td>\n";
            print "<td colspan=\"2\">&nbsp;</td>\n";
            print "</tr>\n";
            print "</tbody>\n";
        }
    }
    print "<tbody class=\"dataTableLink dataTableZebra ordretekstListe\">\n";
    $x = 0;
    $q = db_select("select * from ordretekster order by sort", __FILE__ . " linje " . __LINE__);
    while ($r = db_fetch_array($q)) {
        $x++;
        print "<tr id=\"order_{$r['id']}\">\n";
        print "<td class=\"dragHandle\">&nbsp;</td>\n";
        print "<td align=\"center\"><input type=\"checkbox\" title=\"Afkryds ved insættelse af flere tekster\" name=\"linjetekster[]\" value=\"{$r['id']}\"></td><td align=\"left\" title=\"" . findtekst(491, $sprog_id) . "\" style=\"width:800px;\"><!--tekst 491--><a href=\"ordre.php?id={$id}&amp;tekst_id={$r['id']}\">" . nl2br($r[tekst]) . "</a></td>\n";
        print "<td title=\"Ret tekst\" align=\"right\"><a href=\"ret_tekst_ordre.php?id={$id}&amp;tekst_id={$r['id']}\"><span style=\"width:16px; display:block;\"><span class=\"checkmark\"></span></span></a></td>\n";
        print "<td title=\"" . findtekst(492, $sprog_id) . "\" align=\"left\"><!--tekst 492--><a href=\"ordre.php?id={$id}&amp;tekst_id={$r['id']}&amp;slet_tekst={$r['id']}\" onclick=\"return confirm('" . findtekst(493, $sprog_id) . "')\"><!--Tekst 493--><span style=\"width:16px; display:block;\"><span class=\"xmark\"></span></span></a></td>\n";
        print "</tr>\n";
    }
    print "</tbody>\n";
    print "<tbody class=\"dataTableTopBorderGray\">\n";
    //<input class=\"inputbox\" type=\"text\" title=\"Hvis teksten skal være fed sættes <b> foran teksten og </b> efter teksten (F.eks. <b>Lorem ipsum</b>). Det samme gøres ved Italic, bare med <i> og </i>.\" style=\"text-align:left;width:800px;\" name=\"ny_linjetekst\">
    print "<tr><td valign=\"top\" colspan=\"2\"><input type=\"hidden\" name=\"id\" value=\"{$id}\"><span style=\"display:block;margin-top:3px;\">Ny fast tekst</span></td><td><textarea class=\"textAreaSager autosize kontrolskema_font\" name=\"ny_linjetekst\" rows=\"1\" cols=\"10\" style=\"height:16px;width:800px;\" title=\"Hvis teksten skal være fed sættes &lt;b&gt; foran teksten og &lt;/b&gt; efter teksten (F.eks. &lt;b&gt;Lorem ipsum&lt;/b&gt;). Det samme gøres ved Italic, bare med &lt;i&gt; og &lt;/i&gt;. Hvis der skal insættes en blank linje bruges &lt;i&gt;&lt;/i&gt; uden tekst imellem.\"></textarea></td>\n";
    print "<td colspan=\"2\" valign=\"bottom\"><input type=\"submit\" class=\"button gray medium\" accesskey=\"g\" value=\"Gem/Indsæt\" name=\"tekstlinjer\" onclick=\"javascript:docChange = false;\"></td>\n";
    print "</tr>\n";
    print "</tbody></table></form></td></tr></tbody></table>\n";
    print "</div>";
    print "</div><!-- end of wrapper -->\n";
    ?>
	<script type="text/javascript">
			// Function som sortere i table
		$("document").ready(function() {
			$(".ordretekstSort .ordretekstListe").tableDnD({
				onDragClass: "highlight",
				onDrop: function(table, row) {
				var orders = $.tableDnD.serialize();
				$.post('../debitor/sort.php', { orders : orders });
				},
				dragHandle: ".dragHandle"
			});
		});
		$("document").ready(function() {
			$(".ordretekstListe tr").hover(function() {
							$(this.cells[0]).addClass('showDragHandle');
				}, function() {
							$(this.cells[0]).removeClass('showDragHandle');
				});
		});
		</script>
	<?php 
    print "</body>\n";
    print "</html>\n";
    exit;
}
Exemple #2
0
function vareopslag($sort, $fokus, $id, $vis)
{
    global $kontonr;
    global $font;
    if (!$kontonr && $id) {
        $query = db_select("select kontonr from ordrer where id = {$id}");
        if ($row = db_fetch_array($query)) {
            $kontonr = trim($row[kontonr]);
        }
    }
    if ($kontonr) {
        $query = db_select("select id from adresser where kontonr = '{$kontonr}'");
        if ($row = db_fetch_array($query)) {
            $leverandor = $row[id];
        }
    }
    sidehoved($id, "ordre.php", "../lager/varekort.php", $fokus, "Produktionsordre {$id}");
    #	print"<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody>";
    #	print"<tr><td valign=\"top\">";
    print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"100%\" valign = \"top\">";
    print "<tbody><tr>";
    print "<td><small><b>{$font}<a href=ordre.php?sort=varenr&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Varenr</a></b></small></td>";
    print "<td><small><b>{$font}<a href=ordre.php?sort=beskrivelse&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Beskrivelse</a></b></small></td>";
    print "<td align=right><small><b>{$font}<a href=ordre.php?sort=salgspris&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Salgspris</a></b></small></td>";
    print "<td align=right><small><b>{$font} Kostpris</b></small></td>";
    print "<td align=right><small><b>{$font} Beholdning</b></small></td>";
    print "<td width=2%></td>";
    print "<td align><small><b>{$font} Leverand&oslash;r</b></small></td>";
    if ($kontonr) {
        if ($vis) {
            print "<td align=right><small>{$font}<a href=ordre.php?sort={$sort}&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}>Vis alle lev.</a></small></td>";
        } else {
            print "<td align=right><small>{$font}<a href=ordre.php?sort={$sort}&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis=1>Vis aktuel lev.</a></small></td>";
        }
    }
    print " </tr>";
    $sort = $_GET['sort'];
    if (!$sort) {
        $sort = varenr;
    }
    $vare_id = array();
    if ($vis && $leverandor) {
        $temp = " and lev_id = " . $leverandor;
    }
    $x = 0;
    $query = db_select("select * from vare_lev");
    while ($row = db_fetch_array($query)) {
        $x++;
        $vare_id[$x] = $row[vare_id];
    }
    if (!$kontonr) {
        $x++;
    } elseif ($x > 1) {
        print "<td colspan=9><hr></td>";
    }
    $query = db_select("select * from varer where lukket != '1' order by {$sort}");
    while ($row = db_fetch_array($query)) {
        $varenr = trim($row[varenr]);
        $vist = 0;
        $query2 = db_select("select * from vare_lev where vare_id = {$row['id']} {$temp}");
        while ($row2 = db_fetch_array($query2)) {
            print "<tr>";
            print "<td><small>{$font}<a href=\"ordre.php?varenr={$varenr}&fokus={$fokus}&konto_id={$row2['lev_id']}&id={$id}\">{$varenr}</a></small></td>";
            print "<td><small>{$font} {$row['beskrivelse']}<br></small></td>";
            $salgspris = dkdecimal($row[salgspris]);
            print "<td align=right><small>{$font} {$salgspris}<br></small></td>";
            $kostpris = dkdecimal($row2[kostpris]);
            print "<td align=right><small>{$font} {$kostpris}<br></small></td>";
            print "<td align=right><small>{$font} {$row['beholdning']}<br></small></td>";
            print "<td></td>";
            $levquery = db_select("select kontonr, firmanavn from adresser where id={$row2['lev_id']}");
            if ($levrow = db_fetch_array($levquery)) {
                print "<td><small>{$font} {$levrow['kontonr']} - {$levrow['firmanavn']}</small></td>";
            } else {
                print "<td></td>";
            }
            print "<td align=right><a href=\"../lager/varekort.php?returside=../kreditor/ordre.php&ordre_id={$id}&fokus={$fokus}&id={$row['id']}\">{$font}<small>Ret</a></td>";
            print "</tr>";
            $vist = 1;
        }
        if (!in_array($row[id], $vare_id) && $vist == 0 && $row['samlevare'] != 'on') {
            print "<tr>";
            print "<td><small>{$font}<a href=\"ordre.php?varenr={$varenr}&fokus={$fokus}&id={$id}\">{$row['varenr']}</a></small></td>";
            print "<td><small>{$font} {$row['beskrivelse']}<br></small></td>";
            $salgspris = dkdecimal($row[salgspris]);
            print "<td align=right><small>{$font} {$salgspris}<br></small></td>";
            $kostpris = dkdecimal($row[kostpris]);
            print "<td align=right><small>{$font} {$kostpris}<br></small></td>";
            print "<td></td><td></td><td></td>";
            print "<td align=right><a href=\"../lager/varekort.php?returside=../kreditor/ordre.php&ordre_id={$id}&fokus={$fokus}&id={$row['id']}\">{$font}<small>Ret</a></td>";
            print "</tr>";
        }
    }
    print "</tbody></table></td></tr></tbody></table>";
    exit;
}
Exemple #3
0
function ordreside($id, $regnskab)
{
    #	print "<!--Function ordreside start-->";
    global $art;
    global $bgcolor;
    global $bgcolor5;
    global $bogfor;
    global $bruger_id;
    global $brugsamletpris;
    global $brugsamletpris;
    global $brugernavn;
    global $bruttosum;
    global $bruttosaetsum;
    global $charset;
    global $db_encode;
    global $db_id;
    global $difkto;
    global $fokus;
    global $fakturadate;
    global $fakturadato;
    global $genfakt;
    global $hurtigfakt;
    global $incl_moms;
    global $oio;
    global $omkunde;
    global $ordresum;
    global $procentfakt;
    global $procenttillag;
    global $procentvare;
    global $returside;
    global $rvid;
    global $rvnr;
    global $samlet_pris;
    global $samlet_rabat;
    global $samlet_rabatpct;
    global $sprog_id;
    global $sprog;
    global $submit;
    global $svnr;
    global $varenr;
    global $vis_projekt;
    global $vis_saet;
    #20150306 varenr
    $id *= 1;
    $r = db_fetch_array(db_select("select * from ordrer where id='{$id}'", __FILE__ . " linje " . __LINE__));
    $sag_id = $r['sag_id'] * 1;
    if ($sag_id) {
        $returside = urlencode("../sager/sager.php?funktion=vis_sag&amp;sag_id={$sag_id}&amp;konto_id={$konto_id}");
    }
    if (!$returside) {
        if ($popup) {
            $returside = "../includes/luk.php";
        } else {
            $returside = "ordreliste.php";
        }
    }
    $addr1 = NULL;
    $addr2 = NULL;
    $batchvare = NULL;
    $betalingsbet = NULL;
    $betalingsdage = NULL;
    $bynavn = NULL;
    $debitorkort = NULL;
    $dbsum = NULL;
    $dkantal = NULL;
    $cvrnr = NULL;
    $ean = NULL;
    $email = NULL;
    $felt_1 = NULL;
    $felt_2 = NULL;
    $felt_3 = NULL;
    $felt_4 = NULL;
    $felt_5 = NULL;
    $firmanavn = NULL;
    $institution = NULL;
    $ko_ant = array();
    $kontakt = NULL;
    $kontakt_tlf = NULL;
    $konto_id = NULL;
    $kontonr = NULL;
    $kostsum = NULL;
    $kred_ord_id = NULL;
    $krediteret = NULL;
    $kundeordnr = NULL;
    $land = NULL;
    $levdato = NULL;
    $levdiff = NULL;
    $lev_addr1 = NULL;
    $lev_addr2 = NULL;
    $lev_bynavn = NULL;
    $lev_kontakt = NULL;
    $lev_max = NULL;
    $lev_navn = NULL;
    $lev_postnr = NULL;
    $lev_pbs = NULL;
    $lev_pbs_nr = NULL;
    $linjebg = NULL;
    $mail_fakt = NULL;
    $momsfri = NULL;
    $momssats = NULL;
    $momssum = NULL;
    $oio_fakt = NULL;
    $ordredato = NULL;
    $ordrenr = NULL;
    $pbs_nr = NULL;
    $postnr = NULL;
    $prev_id = NULL;
    $reserveret = NULL;
    $status = NULL;
    $tidl_lev = NULL;
    $udskriv_til = NULL;
    $valutakurs = NULL;
    $vis_lev_addr = NULL;
    $y = NULL;
    if (!$id) {
        $fokus = 'kontonr';
    }
    if ($id) {
        $query = db_select("select * from ordrer where id = '{$id}'", __FILE__ . " linje " . __LINE__);
        $row = db_fetch_array($query);
        $konto_id = $row['konto_id'] * 1;
        $kontonr = HtmlEntities($row['kontonr'], ENT_COMPAT, $charset);
        $firmanavn = HtmlEntities($row['firmanavn'], ENT_COMPAT, $charset);
        $addr1 = HtmlEntities($row['addr1'], ENT_COMPAT, $charset);
        $addr2 = HtmlEntities($row['addr2'], ENT_COMPAT, $charset);
        $postnr = HtmlEntities($row['postnr'], ENT_COMPAT, $charset);
        $bynavn = HtmlEntities($row['bynavn'], ENT_COMPAT, $charset);
        $land = HtmlEntities($row['land'], ENT_COMPAT, $charset);
        $kontakt = HtmlEntities($row['kontakt'], ENT_COMPAT, $charset);
        $kontakt_tlf = HtmlEntities($row['kontakt_tlf'], ENT_COMPAT, $charset);
        $kundeordnr = HtmlEntities($row['kundeordnr'], ENT_COMPAT, $charset);
        $lev_navn = HtmlEntities($row['lev_navn'], ENT_COMPAT, $charset);
        $lev_addr1 = HtmlEntities($row['lev_addr1'], ENT_COMPAT, $charset);
        $lev_addr2 = HtmlEntities($row['lev_addr2'], ENT_COMPAT, $charset);
        $lev_postnr = HtmlEntities($row['lev_postnr'], ENT_COMPAT, $charset);
        $lev_bynavn = HtmlEntities($row['lev_bynavn'], ENT_COMPAT, $charset);
        $lev_kontakt = HtmlEntities($row['lev_kontakt'], ENT_COMPAT, $charset);
        $vis_lev_addr = $row['vis_lev_addr'];
        $felt_1 = HtmlEntities($row['felt_1'], ENT_COMPAT, $charset);
        $felt_2 = HtmlEntities($row['felt_2'], ENT_COMPAT, $charset);
        $felt_3 = HtmlEntities($row['felt_3'], ENT_COMPAT, $charset);
        $felt_4 = HtmlEntities($row['felt_4'], ENT_COMPAT, $charset);
        $felt_5 = HtmlEntities($row['felt_5'], ENT_COMPAT, $charset);
        $cvrnr = $row['cvrnr'];
        $ean = HtmlEntities($row['ean'], ENT_COMPAT, $charset);
        $institution = HtmlEntities($row['institution'], ENT_COMPAT, $charset);
        $email = HtmlEntities($row['email'], ENT_COMPAT, $charset);
        $mail_fakt = $row['mail_fakt'];
        $udskriv_til = $row['udskriv_til'];
        $mail_bilag = $row['mail_bilag'];
        #20131122 tilføj $mail_bilag til visning
        $betalingsbet = trim($row['betalingsbet']);
        $betalingsdage = $row['betalingsdage'];
        $valuta = $row['valuta'];
        $valutakurs = $row['valutakurs'] * 1;
        if (!$valutakurs) {
            $valutakurs = 100;
        }
        $projekt[0] = $row['projekt'];
        $formularsprog = $row['sprog'];
        $pbs = $row['pbs'];
        $afd = $row['afd'];
        $sum = $row['sum'];
        $moms = $row['moms'];
        $ref = trim(HtmlEntities($row['ref'], ENT_COMPAT, $charset));
        $fakturanr = HtmlEntities($row['fakturanr'], ENT_COMPAT, $charset);
        $lev_adr = HtmlEntities($row['lev_adr'], ENT_COMPAT, $charset);
        $ordrenr = $row['ordrenr'];
        $kred_ord_id = $row['kred_ord_id'] * 1;
        $restordre = $row['restordre'];
        if ($row['ordredate']) {
            $ordredate = $row['ordredate'];
        } else {
            $ordredate = date("y-m-d");
        }
        $ordredato = dkdato($ordredate);
        if ($row['levdate']) {
            $levdato = dkdato($row['levdate']);
        }
        if ($row['fakturadate']) {
            $fakturadate = $row['fakturadate'];
            $fakturadato = dkdato($row['fakturadate']);
        }
        if ($row['nextfakt']) {
            $genfakt = dkdato($row['nextfakt']);
        }
        $momssats = $row['momssats'];
        $procenttillag = $row['procenttillag'] * 1;
        $status = $row['status'];
        if (!$status) {
            $status = 0;
        }
        $kontonr = $row['kontonr'];
        $art = $row['art'];
        $mail_subj = HtmlEntities($row['mail_subj'], ENT_COMPAT, $charset);
        $mail_text = HtmlEntities(str_replace("<br>", "\n", $row['mail_text']), ENT_COMPAT, $charset);
        $dokument = $row['dokument'];
        $sag_id = $row['sag_id'] * 1;
        $sagsnr = $row['sagsnr'] * 1;
        $tilbudnr = $row['tilbudnr'];
        $datotid = $row['datotid'];
        $nr = $row['nr'] * 1;
        if (!$returside && $row['returside']) {
            $returside = $row['returside'];
        }
        $row['omvbet'] ? $omkunde = 'on' : ($omkunde = '');
        #		if ($brugernavn && !$ref) $ref=$brugernavn; #flyttet til efter 'ikke faktureret'
        #		if ($returside=='../includes/luk.php' && !$popup) $returside='';
        $x = 0;
        $krediteret = '';
        $q = db_select("select art,pbs_nr,pbs from adresser where art = 'S' or id = '{$konto_id}'", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            if ($r['art'] == 'S') {
                $lev_pbs_nr = $r['pbs_nr'];
                $lev_pbs = $r['pbs'];
            } else {
                $pbs_nr = $r['pbs_nr'];
            }
        }
        $query = db_select("select id,ordrenr from ordrer where kred_ord_id = '{$id}'", __FILE__ . " linje " . __LINE__);
        while ($row2 = db_fetch_array($query)) {
            $x++;
            if ($x > 1) {
                $krediteret = $krediteret . ",";
            }
            $krediteret = $krediteret . "<a href=\"ordre.php?id={$row2['id']}\">{$row2['ordrenr']}</a>";
        }
        if ($status < 3) {
            if (substr($fokus, 0, 4) != 'dkan' && substr($fokus, 0, 4) != 'pris') {
                $fokus = 'vare0';
            }
            #20151019
        } else {
            $fokus = '';
        }
    } else {
        $r = db_fetch_array(db_select("select ansatte.navn as ref,ansatte.afd as afd from ansatte,brugere where ansatte.id = " . nr_cast("brugere.ansat_id") . " and brugere.brugernavn='{$brugernavn}'", __FILE__ . " linje " . __LINE__));
        $ref = $r['ref'];
        $afd = $r['afd'];
    }
    $afd *= 1;
    $afd_navn = NULL;
    if ($r = db_fetch_array(db_select("select beskrivelse from grupper where art = 'AFD' and kodenr = '{$afd}'", __FILE__ . " linje " . __LINE__))) {
        $afd_navn = $r['beskrivelse'];
    }
    ($r = db_fetch_array(db_select("select * from grupper where ART = 'bilag' and (box6 ='on' or (box1 !='' and box2 !='' and box3 !=''))", __FILE__ . " linje " . __LINE__))) ? $bilag = 1 : ($bilag = 0);
    if (db_fetch_array(db_select("select * from grupper where art = 'DIV' and kodenr = '2' and box7='on'", __FILE__ . " linje " . __LINE__))) {
        $url = "jobkort.php?returside=ordre.php&konto_id={$konto_id}&ordre_id={$id}";
        $jobkort = "<a href={$url} style=\"text-decoration:none\"><input type=\"button\" style=\"width:75px\" value=\"jobkort\" onClick=\"window.navigate('{$url}')\"></a>";
        $url = "debitorkort.php?returside=ordre.php&konto_id={$konto_id}&ordre_id={$id}";
        $debitorkort = "<a href={$url} style=\"text-decoration:none\"><input type=\"button\" style=\"width:75px\" value=\"debitorkort\" onClick=\"window.navigate('{$url}')\"></a>";
    } else {
        $jobkort = NULL;
    }
    #cho "procentfakt $procentfakt $default_procenttillag<br>";
    ######### pile ########## tilfoejet 20080210
    if ($status == 0) {
        $tmp = "tilbud";
    } elseif ($status >= 3) {
        $tmp = "faktura";
    } else {
        $tmp = "ordrer";
    }
    #cho "$status select box1 from grupper where art = 'OLV' and kodenr = '$bruger_id' and  kode='$tmp'<br>\n";
    $r = db_fetch_array(db_select("select box1 from grupper where art = 'OLV' and kodenr = '{$bruger_id}' and  kode='{$tmp}'", __FILE__ . " linje " . __LINE__));
    $ordreliste = explode(",", $r['box1']);
    $x = 0;
    $next_id = 0;
    while ($ordreliste[$x]) {
        if ($ordreliste[$x] == $id) {
            if (isset($ordreliste[$x - 1])) {
                $prev_id = $ordreliste[$x - 1];
            } else {
                $prev_id = NULL;
            }
            if (isset($ordreliste[$x + 1])) {
                $next_id = $ordreliste[$x + 1];
            } else {
                $next_id = NULL;
            }
        }
        $x++;
    }
    ######### elip ##########
    if ($art == 'DK') {
        $query = db_select("select ordrenr from ordrer where id = '{$kred_ord_id}'", __FILE__ . " linje " . __LINE__);
        $row2 = db_fetch_array($query);
        if ($kred_ord_id) {
            sidehoved($id, "{$returside}", "", "", "Kunde kreditnota {$ordrenr} (kreditering af ordre nr: <a href=\"ordre.php?id={$kred_ord_id}\">{$row2['ordrenr']}</a>)");
        } else {
            sidehoved($id, "{$returside}", "", "", "Kunde kreditnota {$ordrenr}");
        }
    } elseif ($krediteret) {
        sidehoved($id, "{$returside}", "", "", "Kundeordre {$ordrenr} ( krediteret p&aring; KN nr: {$krediteret} )");
    } else {
        if ($returside == "ordreliste.php") {
            sidehoved($id, "{$returside}", "", "", "Kundeordre {$ordrenr} - {$temp}");
        } else {
            sidehoved($id, "{$returside}", "", "", "Kundeordre {$ordrenr} - {$temp}");
        }
    }
    if (!$status) {
        $status = 0;
    }
    if ($status >= 3) {
        print "<form name=\"ordre\" id=\"1\" action=\"ordre.php?id={$id}&amp;sag_id={$sag_id}&amp;returside={$returside}\" method=\"post\">\n";
        print "<input type=\"hidden\" name=\"ordrenr\" value=\"{$ordrenr}\">";
        print "<input type=\"hidden\" name=\"status\" value=\"{$status}\">";
        print "<input type=\"hidden\" name=\"id\" value=\"{$id}\">";
        print "<input type=\"hidden\" name=\"art\" value=\"{$art}\">";
        print "<input type=\"hidden\" name=\"kred_ord_id\" value=\"{$kred_ord_id}\">\n";
        print "<input type=\"hidden\" name=\"konto_id\" value=\"{$konto_id}\">";
        print "<input type=\"hidden\" name=\"kontonr\" value=\"{$kontonr}\">";
        print "<input type=\"hidden\" name=\"firmanavn\" value=\"{$firmanavn}\">";
        print "<input type=\"hidden\" name=\"addr1\" value=\"{$addr1}\">";
        print "<input type=\"hidden\" name=\"addr2\" value=\"{$addr2}\">";
        print "<input type=\"hidden\" name=\"postnr\" value=\"{$postnr}\">";
        print "<input type=\"hidden\" name=\"bynavn\" value=\"{$bynavn}\">";
        print "<input type=\"hidden\" name=\"land\" value=\"{$land}\">";
        print "<input type=\"hidden\" name=\"kontakt\" value=\"{$kontakt}\">";
        print "<input type=\"hidden\" name=\"kontakt_tlf\" value=\"{$kontakt_tlf}\">";
        print "<input type=\"hidden\" name=\"kundeordnr\" value=\"{$kundeordnr}\">\n";
        print "<input type=\"hidden\" name=\"lev_navn\" value=\"{$lev_navn}\">";
        print "<input type=\"hidden\" name=\"lev_addr1\" value=\"{$lev_addr1}\">";
        print "<input type=\"hidden\" name=\"lev_addr2\" value=\"{$lev_addr2}\">";
        print "<input type=\"hidden\" name=\"lev_postnr\" value=\"{$lev_postnr}\">";
        print "<input type=\"hidden\" name=\"lev_bynavn\" value=\"{$lev_bynavn}\">";
        print "<input type=\"hidden\" name=\"lev_kontakt\" value=\"{$lev_kontakt}\">";
        print "<input type=\"hidden\" name=\"levdato\" value=\"{$levdato}\">\n";
        print "<input type=\"hidden\" name=\"genfakt\" value=\"{$genfakt}\">";
        print "<input type=\"hidden\" name=\"cvrnr\" value=\"{$cvrnr}\">";
        print "<input type=\"hidden\" name=\"ean\" value=\"{$ean}\">";
        print "<input type=\"hidden\" name=\"institution\" value=\"{$institution}\">";
        print "<input type=\"hidden\" name=\"email\" value=\"{$email}\">";
        #		print "<input type=\"hidden\" name=\"mail_fakt\" value=\"$mail_fakt\">";
        print "<input type=\"hidden\" name=\"betalingsbet\" value=\"{$betalingsbet}\">";
        print "<input type=\"hidden\" name=\"betalingsdage\" value=\"{$betalingsdage}\">";
        print "<input type=\"hidden\" name=\"momssats\" value=\"" . dkdecimal($momssats) . "\">";
        print "<input type=\"hidden\" name=\"procenttillag\" value=\"" . dkdecimal($procenttillag) . "\">";
        print "<input type=\"hidden\" name=\"ref\" value=\"{$ref}\">";
        print "<input type=\"hidden\" name=\"fakturanr\" value=\"{$fakturanr}\">";
        print "<input type=\"hidden\" name=\"lev_adr\" value=\"{$lev_adr}\">";
        print "<input type=\"hidden\" name=\"valuta\" value=\"{$valuta}\">";
        print "<input type=\"hidden\" name=\"valutakurs\" value=\"{$valutakurs}\">";
        print "<input type=\"hidden\" name=\"projekt[0]\" value=\"{$projekt['0']}\">";
        #20130816
        print "<input type=\"hidden\" name=\"sprog\" value=\"{$formularsprog}\">";
        print "<input type=\"hidden\" name=\"pbs\" value=\"{$pbs}\">";
        print "<input type=\"hidden\" name=\"afd\" value=\"{$afd}\">";
        print "<input type=\"hidden\" name=\"sum\" value=\"{$sum}\">";
        print "<input type=\"hidden\" name=\"sag_id\" value=\"{$sag_id}\">";
        print "<input type=\"hidden\" name=\"sagsnr\" value=\"{$sagsnr}\">";
        print "<input type=\"hidden\" name=\"tilbudnr\" value=\"{$tilbudnr}\">";
        print "<input type=\"hidden\" name=\"datotid\" value=\"{$datotid}\">";
        print "<input type=\"hidden\" name=\"nr\" value=\"{$nr}\">";
        print "<input type=\"hidden\" name=\"returside\" value=\"{$returside}\">";
        print "<input type=\"hidden\" name=\"omkunde\" value=\"{$omkunde}\">";
        if ($mail_fakt) {
            $mail_fakt = "checked";
        }
        ##### pile ########	tilfoejet 20080210
        $alerttekst = findtekst(154, $sprog_id);
        $spantekst = findtekst(198, $sprog_id);
        print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"100%\" valign = \"top\"><tbody>\n";
        #Tabel 1 ->
        if ($prev_id) {
            print "<tr><td width=\"50%\" title=\"{$spantekst}\"><a href=\"javascript:confirmClose('ordre.php?id={$prev_id}&returside={$returside}','{$alerttekst}')\"><img src=\"../ikoner/left.png\" style=\"border: 0px solid; width: 15px; height: 15px;\"></a></span></td>\n";
        } else {
            print "<tr><td width=\"50%\"></td>\n";
        }
        $spantekst = findtekst(199, $sprog_id);
        if ($next_id) {
            print "<td width=\"50%\" align=\"right\" title=\"{$spantekst}\"><a href=\"javascript:confirmClose('ordre.php?id={$next_id}&returside={$returside}','{$alerttekst}')\"><img src=\"../ikoner/right.png\" style=\"border: 0px solid; width: 15px; height: 15px;\"></a></span></td></tr>\n";
        } else {
            print "<tr><td width=\"50%\"></td>\n";
        }
        print "</tbody></table>\n";
        # <- Tabel 1
        ##### pile ########
        print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\" valign = \"top\"><tbody>\n";
        #Tabel 2 ->
        $ordre_id = $id;
        print "<tr><td width=\"31%\" valign=\"top\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n";
        #Tabel 2.1 ->
        print "<tr><td width=\"100\"><b>Kontonr</b></td><td width=\"100\">{$kontonr}</td></tr>\n";
        print "<tr><td><b>Firmanavn</b></td><td>{$firmanavn}</td></tr>\n";
        print "<tr><td><b>Adresse</b></td><td>{$addr1}</td></tr>\n";
        print "<tr><td></td><td>{$addr2}</td></tr>\n";
        print "<tr><td><b>Postnr &amp; by</b></td><td>{$postnr} {$bynavn}</td></tr>\n";
        print "<tr><td><b>Land</b></td><td>{$land}</td></tr>\n";
        print "<tr><td><b>Att.</b></td><td>{$kontakt}</td></tr>\n";
        print "<tr><td><b>Ordrenr.</b></td><td>{$kundeordnr}</td></tr>\n";
        print "<tr><td><b>CVR-nr.</b></td><td>{$cvrnr}</td></tr>\n";
        print "<tr><td><b>EAN-nr.</b></td><td>{$ean}</td></tr>\n";
        print "<tr><td><b>Institution</b></td><td>{$institution}</td></tr>\n";
        print "</tbody></table></td>\n";
        #  <- Tabel 2.1
        print "<td width=\"38%\" valign=\"top\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n";
        #Tabel 2.2 ->
        $alerttekst = 'Husk at opdatere ved at klikke p&aring  [OK] til højre for feltet du har ændret!';
        print "<tr><td><b>E-mail</b></td><td width=\"105\"><input class=\"inputbox\" type=\"text\" name=\"email\" style=\"width:130px\" value=\"{$email}\" onchange=\"javascript:this.form.submit()\"></td></tr>\n";
        #		print "<tr><td><b>Edskriv til</b></td>"
        #		if ($email)
        print "<tr><td title=\"V&aelig;lg p&aring; hvilken m&aring;de dokumentet skal udskrives, gemmes eller sendes.\"><b>Udskriv til</b></td>\n";
        if ($mail_fakt) {
            $udskriv_til = "email";
        }
        #		if ($oioxml) $udskriv_til="oioxml";
        if ($oioubl) {
            $udskriv_til = "oioubl";
        }
        if ($lev_pbs_nr) {
            if ($pbs) {
                $udskriv_til = "PBS";
            }
        }
        if (!$udskriv_til) {
            $udskriv_til = "PDF";
        }
        print "<td><select class=\"inputbox\" name=\"udskriv_til\" onchange=\"this.form.submit()\">\n";
        /*
        		print "<option>$udskriv_til</option>\n";
        		if ($udskriv_til!="PDF") print "<option>PDF</option>\n";
        		if ($udskriv_til!="email" && $email) print "<option>email</option>\n";
        		if ($udskriv_til!="oioxml" && strlen($ean)==13) print "<option title=\"Kun ved fakturering/kreditering.\">oioxml</option>\n";
        		print "</SELECT></td></tr>\n";
        */
        print "<option>{$udskriv_til}</option>\n";
        if ($udskriv_til != "PDF") {
            print "<option>PDF</option>\n";
        }
        if ($udskriv_til != "PDF-tekst") {
            print "<option title=\"Udskrives som PDF uden baggrund\">PDF-tekst</option>\n";
        }
        if ($udskriv_til != "email") {
            print "<option title=\"Sendes som PDF via e-mail\">email</option>\n";
        }
        #		if ($udskriv_til!="oioxml") print "<option title=\"Kun ved fakturering/kreditering.\">oioxml</option>\n"; #PHR 20090803
        if (($pbs || $lev_pbs_nr) && $udskriv_til != "PBS") {
            print "<option value=\"PBS\">PBS</option>\n";
        }
        if ($udskriv_til != "oioubl") {
            print "<option title=\"Kun ved fakturering/kreditering.\">oioubl</option>\n";
        }
        #PHR 20090803
        #		if ($udskriv_til!="edifakt") print "<option title=\"Kun ved fakturering/kreditering.\">edifakt</option>\n"; #20140201
        $tmp = $pbs_nr * 1;
        # 20120822
        if ($lev_pbs_nr) {
            if ($tmp == 'L') {
                if ($pbs) {
                    print "<option value=\"PBS\">PBS</option>\n";
                } elseif ($tmp && $udskriv_til != "PBS" && $lev_pbs == 'B') {
                    print "<option title=\"Opkr&aelig;ves via PBS betalingsservice\">PBS</option>\n";
                }
            }
        }
        if ($udskriv_til != "historik" && db_fetch_array(db_select("select * from grupper where ART = 'bilag' and (box6 ='on' or (box1 !='' and box2 !='' and box3 !=''))", __FILE__ . " linje " . __LINE__))) {
            print "<option title=\"Gem en kopi og vedhæft kundens historik\">historik</option>\n";
        }
        print "</SELECT>";
        /*
        		print "<tr><td><b>Fakt som mail</td><td><input class=\"inputbox\" type=\"checkbox\" name=\"mail_fakt\" $mail_fakt></td></tr>\n";
        		if ($lev_pbs_nr) {
        			if ($pbs == "FI") $pbs_fi='checked';
        			elseif ($pbs == "BS") $pbs_bs='checked';
        			$title="PBS udsender FI-indbetalingskort";
        			if (!$pbs_bs) {
        				print "<td colspan=\"2\" title=\"$title\">Faktura via PBS (FI)</td><td title=\"$title\"><input class=\"inputbox\" type=\"checkbox\" name=\"pbs_fi\" $pbs_fi onchange=\"javascript:docChange = true;\"></td></tr>\n";
        				if ($pbs_nr && !$pbs_fi) print "<tr>\n";
        			}
        			$title="Opkr&aelig;ves via PBS's betalingsservice";
        			if ($pbs_nr && !$pbs_fi) print "<td colspan=\"2\" title=\"$title\">Opkr&aelig;v via PBS (BS)</td><td title=\"$title\"><input class=\"inputbox\" type=\"checkbox\" name=\"pbs_bs\" \"$pbs_bs\" onchange=\"javascript:docChange = true;\"></td></tr>\n";
        		} else print "</tr>\n";
        */
        print "<tr><td width=\"100\"><b>Ordredato</b></td><td width=\"100\">{$ordredato}</td></tr>\n";
        print "<tr><td><b>Leveringsdato</b></td><td>{$levdato}</td></tr>\n";
        print "<tr><td><b>Fakturadato</b></td><td>{$fakturadato}</td></tr>\n";
        print "<tr><td><b>Genfaktureres</b></td><td><input class=\"inputbox\" type=\"text\" name=\"genfakt\" size=\"7\" value=\"{$genfakt}\"><input type=\"submit\" value=\"OK\" name=\"submit\"></td></tr>\n";
        print "<tr><td><b>Betaling</b></td><td>{$betalingsbet}&nbsp;+&nbsp;{$betalingsdage}</td>\n";
        print "<tr><td><b>Vor ref.</b></td><td>{$ref} &nbsp; {$afd_navn}</td></tr>\n";
        print "<tr><td><b>Fakturanr</b></td><td>{$fakturanr}</td></tr>\n";
        $tmp = dkdecimal($valutakurs);
        if ($valuta) {
            print "<tr><td><b>Valuta / Kurs</b></td><td>{$valuta} / {$tmp}</td></tr>\n";
        }
        if ($projekt[0]) {
            print "<tr><td><b>Projekt</b></td><td>{$projekt['0']}</td></tr>\n";
        }
        print "</tbody></table></td>\n";
        # <- Tabel 2.2
        print "<td width=\"31%\" valign=\"top\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" valign=\"top\">\n";
        #Tabel 2.3 ->
        if ($vis_lev_addr) {
            print "<tr><td><b>Leveringsadresse</b><br />&nbsp;</td><td align=\"center\">{$jobkort} {$debitorkort}</td></tr>\n";
            print "<tr><td colspan=\"2\"><b><hr></b></tr>\n";
            print "<tr><td><b>Firmanavn</b></td><td colspan=\"2\">{$lev_navn}</td></tr>\n";
            print "<tr><td valign=\"top\"><b>Adresse</b></td><td colspan=\"2\">{$lev_addr1}</td></tr>\n";
            print "<tr><td></td><td colspan=\"2\">{$lev_addr2}</td></tr>\n";
            print "<tr><td><b>Postnr. &amp; by</b></td><td>{$lev_postnr} {$lev_bynavn}</td></tr>\n";
            print "<tr><td><b>Att.</b></td><td colspan=\"2\">{$lev_kontakt}</td></tr>\n";
            print "<tr><td colspan=\"2\"><b><hr></b></tr>\n";
            print "<tr><td colspan=\"2\"><a href=\"ordre.php?id={$id}&returside={$returside}&vis_lev_addr=0\">Vis ekstrafelter</tr>\n";
        } else {
            print "<tr><td><b>" . findtekst(243, $sprog_id) . "</b></td><td align=\"center\">{$jobkort} {$debitorkort}</td></tr>\n";
            print "<tr><td colspan=\"2\"><b><hr></b></tr>\n";
            if ($vis_saet) {
                print "<tr><td><b>{$felt_1}</b></td><td align=\"right\">" . dkdecimal($felt_2) . "</td></tr>";
                print "<tr><td><b>{$felt_3}</b></td><td align=\"right\">" . dkdecimal($felt_4) . "</td></tr>";
            } else {
                if (findtekst(244, $sprog_id)) {
                    print "<tr><td><b>" . findtekst(244, $sprog_id) . "</b></td><td>{$felt_1}</td></tr>\n";
                }
                if (findtekst(245, $sprog_id)) {
                    print "<tr><td><b>" . findtekst(245, $sprog_id) . "</b></td><td>{$felt_2}</td></tr>\n";
                }
                if (findtekst(246, $sprog_id)) {
                    print "<tr><td><b>" . findtekst(246, $sprog_id) . "</b></td><td>{$felt_3}</td></tr>\n";
                }
                if (findtekst(247, $sprog_id)) {
                    print "<tr><td><b>" . findtekst(247, $sprog_id) . "</b></td><td>{$felt_4}</td></tr>\n";
                }
                if (findtekst(248, $sprog_id)) {
                    print "<tr><td><b>" . findtekst(248, $sprog_id) . "</b></td><td>{$felt_5}</td></tr>\n";
                }
            }
            print "<tr><td colspan=\"2\"><b><hr></b></tr>\n";
            print "<tr><td colspan=\"2\"><a href=\"ordre.php?id={$id}&returside={$returside}&vis_lev_addr=1\">Vis leveringsadresse</td></tr>\n";
        }
        $lev_max = 0;
        $q = db_select("select lev_nr from batch_salg where ordre_id = {$id}", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            if ($r['lev_nr'] > $lev_max) {
                $lev_max = $r['lev_nr'];
            }
        }
        if ($lev_max > 0) {
            print "<tr><td colspan=\"2\">&nbsp;</td></tr>\n";
            for ($levnr = 1; $levnr <= $lev_max; $levnr++) {
                print "<tr><td colspan=\"2\"> <a href='udskriftsvalg.php?id={$id}&valg={$levnr}&formular=3'>F&oslash;lgeseddel {$levnr}</a></td></tr>\n";
            }
        }
        if (!$formularsprog) {
            $formularsprog = 'Dansk';
        }
        $art == 'DO' ? $form_nr = 4 : ($form_nr = 5);
        $q = db_select("select * from formularer where formular='{$form_nr}' and art='5' and lower(sprog)='" . strtolower($formularsprog) . "'", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            if ($r['xa'] == '1') {
                $std_subj = $r['beskrivelse'];
            } elseif ($r['xa'] == '2') {
                $std_txt_title = $r['beskrivelse'];
            }
            list($std_txt, $tmp) = explode("<br>", $std_txt_title);
            $mail_text ? $std_txt_title = $mail_text : ($std_txt_title = str_replace("<br>", "", $std_txt_title));
        }
        print "</tbody></table></td></tr>\n";
        # -< Tabel 2.3
        if ($udskriv_til == 'email') {
            print "<tr><td align=\"center\" colspan=\"3\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tbody>\n";
            #Tabel 2.4 ->
            print "<tr><td width=\"120px\">Mail emne</td><td><input class=\"inputbox\" type=\"text\" style=\"width:1000px;\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_subj\" placeholder=\"{$std_subj}\" value=\"{$mail_subj}\" onchange=\"javascript:docChange = true;\"></td>";
            if ($bilag) {
                if ($dokument) {
                    print "<td title=\"klik her for at &aring;bne bilaget: {$dokument}\"><a href=\"../includes/bilag.php?kilde=ordrer&filnavn={$dokument}&bilag_id={$id}&bilag={$dokument}&kilde_id={$id}\"><img style=\"border: 0px solid\" alt=\"clip_m_papir\" src=\"../ikoner/paper.png\"></a></td>";
                } else {
                    print "<td title=\"klik her for at vedh&aelig;fte et bilag\"><a href=\"../includes/bilag.php?kilde=ordrer&bilag_id={$id}&bilag={$dokument}&ny=ja&kilde_id={$id}\"><img  style=\"border: 0px solid\" alt=\"clip\" src=\"../ikoner/clip.png\"></a></td>";
                }
            }
            print "</tr><tr><td valign=\"top\">Mail tekst</td><td title=\"{$std_txt_title}\">";
            if ($mail_text) {
                print "<textarea style=\"width:1000px;\" rows=\"2\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_text\" onchange=\"javascript:docChange = true;\">{$mail_text}</textarea>\n";
            } else {
                print "<input class=\"inputbox\" type=\"text\" style=\"width:1000px;\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_text\" placeholder=\"{$std_txt}\" value=\"{$mail_text}\" onchange=\"javascript:docChange = true;\">";
            }
            print "</td><td><input type=\"submit\" value=\"OK\" name=\"opdat_mailtext\"></td></tr></tbody></table></td></tr>\n";
            # <- Tabel 2.4
        }
        print "<tr><td align=\"center\" colspan=\"3\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%\"><tbody>\n";
        #Tabel 2.5 ->
        //print "<tr><td colspan=\"7\"></td></tr>\n<tr>\n"; # udkommenteret 20140502
        print "<td align=\"center\"><b>Pos.</b></td><td align=\"center\"><b>Varenr.</b></td><td align=\"center\"><b>Antal</b></td><td align=\"center\"><b>Enhed</b></td><td align=\"center\"><b>Beskrivelse</b></td><td align=\"center\"><b>Pris</b></td><td align=\"center\"><b>Rabat</b></td>\n";
        #		print "<td align=\"center\"><b>Pos.</b></td><td align=\"center\"><b>Varenr.</b></td><td align=\"center\"><b>Antal</b></td><td align=\"center\"><b>Enhed</b></td><td align=\"center\"><b>Beskrivelse</b></td><td align=\"center\"><b>Pris</b></td><td align=\"center\"><b>Rabat</b></td>";
        if ($procentfakt) {
            print "<td align=\"center\"><b>Procent</b></td>\n";
        }
        print "<td align=\"center\"><b>I alt</b></td>\n";
        if (db_fetch_array(db_select("select * from grupper where art = 'PRJ' order by kodenr", __FILE__ . " linje " . __LINE__))) {
            $vis_projekt = 'on';
        }
        if ($vis_projekt && !$projekt[0]) {
            print "<td align=\"center\" title=\"Projektnummer. Vises for ordrelinjer tilknyttet et projekt.\"><b>Proj.</b></td>\n";
        }
        #		else //print "<td></td>\n"; # udkommenteret 20140502
        if ($genfakt) {
            print "<td align=\"center\" title=\"N&aring;r dette felt er afm&aelig;rket udelades ordrelinjen ved genfakturering.\"><b>kdo</b></td>\n";
        }
        if ($omkunde) {
            print "<td align=\"center\" title =\"Hvis feltet vises er kunden underlagt reglerne for omvendt betalingspligt. Er varen afmærkeret er der ikke opkrævet moms for den pågældende vare.\"><b>O/B</b></td>";
        }
        print "</tr>\n";
        $x = 0;
        $k_sum = 0;
        if (!$ordre_id) {
            $ordre_id = 0;
        }
        $query = db_select("select * from ordrelinjer where ordre_id = '{$ordre_id}' order by posnr", __FILE__ . " linje " . __LINE__);
        while ($row = db_fetch_array($query)) {
            if ($row['posnr'] > 0) {
                $x++;
                $linje_id[$x] = $row['id'];
                $vare_id[$x] = $row['vare_id'];
                $posnr[$x] = $x;
                $varenr[$x] = HtmlEntities($row['varenr'], ENT_COMPAT, $charset);
                $lev_varenr[$x] = HtmlEntities($row['lev_varenr'], ENT_COMPAT, $charset);
                $beskrivelse[$x] = HtmlEntities($row['beskrivelse'], ENT_COMPAT, $charset);
                $enhed[$x] = HtmlEntities($row['enhed'], ENT_COMPAT, $charset);
                $pris[$x] = $row['pris'] * 1;
                $rabat[$x] = $row['rabat'] * 1;
                $rabatart[$x] = $row['rabatart'];
                $procent[$x] = $row['procent'];
                $antal[$x] = $row['antal'];
                $momsfri[$x] = $row['momsfri'];
                $varemomssats[$x] = $row['momssats'];
                $folgevare[$x] = $row['folgevare'];
                $saet[$x] = $row['saet'];
                $samlevare[$x] = $row['samlevare'];
                $fast_db[$x] = $row['fast_db'];
                $row['omvbet'] ? $omvbet[$x] = 'checked' : ($omvbet[$x] = '');
                #omvendt betalingspligt
                if (!$varemomssats[$x] || $varemomssats[$x] > $momssats) {
                    $varemomssats[$x] = $momssats;
                }
                if ($momsfri[$x] || $omvbet[$x]) {
                    $varemomssats[$x] = 0;
                }
                $serienr[$x] = HtmlEntities($row['serienr'], ENT_COMPAT, $charset);
                $kostpris[$x] = $row['kostpris'];
                $k_sum += $kostpris[$x] * $antal[$x];
                $projekt[$x] = $row['projekt'];
                $omvbet[$x] = $row['omvbet'];
                $lev_varenr[$x] = $row['lev_varenr'];
                $row['kdo'] ? $kdo[$x] = 'checked' : ($kdo[$x] = '');
                #/*
                if (!$brugsamletpris) {
                    if ($vare_id[$x]) {
                        list($koordpr, $koordnr, $koordant, $koordid, $koordart) = explode(chr(9), find_kostpris($vare_id[$x], $linje_id[$x]));
                        $kobs_ordre_pris = explode(",", $koordpr);
                        $ko_ant[$x] = count($kobs_ordre_pris);
                        $kobs_ordre_id = explode(",", $koordid);
                        $kobs_ordre_antal = explode(",", $koordant);
                        $kobs_ordre_art = explode(",", $koordart);
                        $kostpris[$x] = 0;
                        for ($y = 0; $y < $ko_ant[$x]; $y++) {
                            $kostpris[$x] += $kobs_ordre_pris[$y];
                            if ($valutakurs && $valutakurs != 100) {
                                $kostpris[$x] *= 100 / $valutakurs;
                            }
                        }
                        $kostpris[$x] /= $ko_ant[$x];
                        #20141023
                        #cho "Kost3 $kostpris[$x]<br>";
                        $kostsum[$x] = $kostpris[$x] * $antal[$x];
                        #cho "Kost4 $kostsum[$x]<br>";
                        # db_modify("update ordrelinjer set kostpris='$kostpris[$x]' where id='$linje_id[$x]'",__FILE__ . " linje " . __LINE__);
                        $db[$x] = ($pris[$x] - $kostpris[$x]) * $antal[$x];
                        #cho "DB $db[$x]=($pris[$x]-$kostpris[$x])*$antal[$x]<br>";
                        if ($pris[$x] != 0) {
                            $dg[$x] = $db[$x] * 100 / $pris[$x];
                        } else {
                            $dg[$x] = 0;
                        }
                        $dk_db[$x] = dkdecimal($db[$x]);
                        $dk_dg[$x] = dkdecimal($dg[$x]);
                        #cho "$dk_db[$x] $dk_dg[$x]<br>";
                    }
                }
                if ($art == 'DK' && $antal[$x] < 0) {
                    $bogfor == 0;
                }
                if ($serienr[$x]) {
                    $serienumre[$x] = NULL;
                    $q2 = db_select("select serienr from serienr where salgslinje_id='{$linje_id[$x]}' order by serienr", __FILE__ . " linje " . __LINE__);
                    while ($r2 = db_fetch_array($q2)) {
                        $serienumre[$x] ? $serienumre[$x] .= ',' . $r['serienr'] : ($serienumre[$x] = $r['serienr']);
                    }
                }
                #*/
                if ($brugsamletpris && $linje_id[$x]) {
                    db_modify("update ordrelinjer set posnr='{$x}' where id = '{$linje_id[$x]}'", __FILE__ . " linje " . __LINE__);
                }
            }
        }
        $linjeantal = $x;
        print "<input type=\"hidden\" name=\"linjeantal\" value=\"{$x}\">\n";
        $totalrest = 0;
        for ($x = 1; $x <= $linjeantal; $x++) {
            if (!$vare_id[$x]) {
                $query = db_select("select id from varer where varenr = '{$varenr[$x]}'", __FILE__ . " linje " . __LINE__);
                if ($row = db_fetch_array($query)) {
                    $vare_id[$x] = $row['id'];
                }
            }
            if ($varenr[$x] && $vare_id[$x]) {
                $row = db_fetch_array(db_select("select gruppe,provisionsfri from varer where id = '{$vare_id[$x]}'", __FILE__ . " linje " . __LINE__));
                $provisionsfri[$x] = $row['provisionsfri'];
                $row = db_fetch_array(db_select("select box8,box9 from grupper where art='VG' and kodenr='{$row['gruppe']}'", __FILE__ . " linje " . __LINE__));
                $row['box8'] == 'on' ? $lagervare = 1 : ($lagervare = 0);
                $row['box9'] == 'on' ? $batchvare = 1 : ($batchvare = 0);
                if ($rabatart[$x] == 'amount') {
                    $ialt = ($pris[$x] - $rabat[$x]) * $antal[$x];
                } else {
                    $ialt = ($pris[$x] - $pris[$x] / 100 * $rabat[$x]) * $antal[$x];
                }
                if ($provisionsfri[$x]) {
                    if ($art == 'DO') {
                        $kostsum[$x] = $ialt;
                    }
                }
                #				if ($valutakurs)$kostsum[$x]*=$valutakurs/100; #20140116
                $db[$x] = $ialt - $kostsum[$x];
                $ialt = afrund($ialt, 3);
                if ($ialt != 0) {
                    $dg[$x] = $db[$x] * 100 / $ialt;
                    $dk_dg[$x] = dkdecimal($dg[$x]);
                }
                $dk_kostpris[$x] = dkdecimal($kostpris[$x]);
                if ($art == 'DO') {
                    $dk_db[$x] = dkdecimal($db[$x]);
                    $dk_kostsum[$x] = dkdecimal($kostsum[$x]);
                } else {
                    $dk_db[$x] = dkdecimal($db[$x] * -1);
                    $dk_kostsum[$x] = dkdecimal($kostsum[$x] * -1);
                }
                $dkpris = dkdecimal($pris[$x]);
                $rabat[$x] ? $dkrabat = dkdecimal($rabat[$x], 3) : ($dkrabat = NULL);
                $dkprocent = dkdecimal($procent[$x]);
                if ($momsfri[$x] != 'on' && !$omvbet[$x]) {
                    if ($incl_moms) {
                        $dkpris = dkdecimal($pris[$x] + $pris[$x] * $varemomssats[$x] / 100);
                    }
                }
                if ($antal[$x]) {
                    if ($art == 'DK') {
                        $dkantal[$x] = dkdecimal($antal[$x] * -1);
                    } else {
                        $dkantal[$x] = dkdecimal($antal[$x]);
                    }
                    if (substr($dkantal[$x], -1) == '0') {
                        $dkantal[$x] = substr($dkantal[$x], 0, -1);
                    }
                    if (substr($dkantal[$x], -1) == '0') {
                        $dkantal[$x] = substr($dkantal[$x], 0, -2);
                    }
                }
                if ($saet[$x] || $rvnr || $lev_varenr[$x]) {
                    $dkrabat = NULL;
                    if ($lev_varenr[$x]) {
                        $dkpris = NULL;
                    }
                }
            } else {
                $antal[$x] = '';
                $dkpris = '';
                $dkrabat = '';
                $dkprocent = '';
                $ialt = '';
            }
            $title = var2str($beskrivelse[$x], $id, $posnr[$x], $varenr[$x], $dkantal[$x], $enhed[$x], $dkpris, $dkprocent, $serienr[$x], $varemomssats[$x], $rabat[$x]);
            print "<tr bgcolor=\"{$linjebg}\">\n";
            print "<input type=\"hidden\" name=\"linje_id[{$x}]\" value=\"{$linje_id[$x]}\">\n";
            print "<input type=\"hidden\" name=\"posn{$x}\" value=\"{$posnr[$x]}\"><td align=\"right\">{$posnr[$x]}</td>\n";
            print "<input type=\"hidden\" name=\"vare{$x}\" value=\"{$varenr[$x]}\"><td>{$varenr[$x]}<br></td>\n";
            print "<input type=\"hidden\" name=\"dkan{$x}\" value=\"{$dkantal[$x]}\"><td align=\"right\">{$dkantal[$x]}<br></td>\n";
            print "<input type=\"hidden\" name=\"enhed[{$x}]\" value=\"{$enhed[$x]}\"><td align=\"right\">{$enhed[$x]}<br></td>\n";
            print "<input type=\"hidden\" name=\"beskrivelse{$x}\" value=\"{$beskrivelse[$x]}\"><td title=\"{$title}\">" . str_replace("\n", "<br>", $beskrivelse[$x]) . "&nbsp;</td>\n";
            print "<input type=\"hidden\" name=\"pris{$x}\" value=\"" . dkdecimal($pris[$x], 3) . "\"><td align=\"right\" title=\"Kostpris {$dk_kostpris[$x]}\">{$dkpris}<br></td>\n";
            #			print "<input type=\"hidden\" name=\"pris$x\" value=\"$dkpris\"><td align=\"right\">$dkpris<br></td>\n";
            print "<input type=\"hidden\" name=\"raba{$x}\" value=\"" . dkdecimal($rabat[$x], 3) . "\"><td align=\"right\">{$dkrabat}<br></td>\n";
            print "<input type=\"hidden\" name=\"proc{$x}\" value=\"{$dkprocent}\">";
            if ($procentfakt) {
                print "<td align=\"right\">{$dkprocent}<br></td>\n";
            }
            print "<input type=\"hidden\" name=\"serienr[{$x}]\" value=\"{$serienr[$x]}\">\n";
            print "<input type=\"hidden\" name=\"vare_id[{$x}]\" value=\"{$vare_id[$x]}\">\n";
            print "<input type=\"hidden\" name=\"lev_varenr[{$x}]\" value=\"{$lev_varenr[$x]}\">\n";
            print "<input type=\"hidden\" name=\"kdo[{$x}]\" value=\"{$kdo[$x]}\">\n";
            print "<input type=\"hidden\" name=\"rabatart[{$x}]\" value=\"{$rabatart[$x]}\">\n";
            print "<input type=\"hidden\" name=\"momsfri[{$x}]\" value=\"{$momsfri[$x]}\">\n";
            print "<input type=\"hidden\" name=\"varemomssats[{$x}]\" value=\"{$varemomssats[$x]}\">\n";
            print "<input type=\"hidden\" name=\"samlevare[{$x}]\" value=\"{$samlevare[$x]}\">\n";
            print "<input type=\"hidden\" name=\"folgevare[{$x}]\" value=\"{$folgevare[$x]}\">\n";
            print "<input type=\"hidden\" name=\"omvbet[{$x}]\" value=\"{$omvbet[$x]}\">\n";
            print "<input type=\"hidden\" name=\"saet[{$x}]\" value=\"{$saet[$x]}\">\n";
            print "<input type=\"hidden\" name=\"fast_db[{$x}]\" value=\"{$fast_db[$x]}\">\n";
            if ($brugsamletpris) {
                $dbsum = $sum - $k_sum;
                #else $dbsum=-$sum-$k_sum;
            } else {
                $dbsum = $dbsum + $db[$x];
            }
            if ($ialt) {
                if ($procentfakt) {
                    $ialt *= $procent[$x] / 100;
                }
                if ($varenr[$x]) {
                    if ($incl_moms && !$momsfri[$x] && !$omvbet[$x]) {
                        $tmp = $ialt + $ialt * $momssats / 100;
                    } else {
                        $tmp = $ialt;
                    }
                    if ($brugsamletpris) {
                        if ($saet[$x] || $varenr[$x] == $rvnr) {
                            if ($lev_varenr[$x]) {
                                list($tmp) = explode("|", $lev_varenr[$x], 2);
                            } else {
                                $tmp = '';
                            }
                        } elseif ($rvnr && $incl_moms) {
                            #20150917
                            $tmp = $antal[$x] * ($pris[$x] + $pris[$x] * $momssats / 100);
                        }
                    }
                    if ($art == 'DK') {
                        $tmp *= -1;
                    }
                    $tmp = dkdecimal($tmp);
                }
                print "<td align=\"right\" title=\"Kostpris {$dk_kostsum[$x]} * db: {$dk_db[$x]} * dg: {$dk_dg[$x]}%\">" . $tmp . "</td>\n";
            } else {
                print "<td>&nbsp;</td>\n";
            }
            print "<input type=\"hidden\" name=\"projekt[{$x}]\" value=\"{$projekt[$x]}\">\n";
            if ($vis_projekt && !$projekt[0]) {
                $r = db_fetch_array(db_select("select beskrivelse from grupper where art = 'PROJ' and kodenr='{$projekt[$x]}'", __FILE__ . " linje " . __LINE__));
                print "<td align=\"right\" title=\"'{$r['projekt']}'\">{$projekt[$x]}</td>\n";
            }
            // else print "<td></td>"; # udkommenteret 20140502
            print $kdo[$x];
            if ($genfakt) {
                print "<td align=\"center\">";
                if ($kdo[$x]) {
                    print "<b>&radic;</b>";
                }
                print "</td>";
            }
            if ($omvbet[$x]) {
                $omvbet[$x] = "&radic;";
            }
            if ($omkunde) {
                print "<td align=\"center\">{$omvbet[$x]}</td>\n";
            }
            #cho "$kobs_ordre_id[0] && $art!='DK' && $ko_ant[$x]>=1<br>";
            if ($kobs_ordre_id[0] && $art != 'DK' && $ko_ant[$x] >= 1) {
                for ($y = 0; $y < $ko_ant[$x]; $y++) {
                    $spantekst = "K&oslash;bsordre&nbsp;{$kobs_ordre_nr[$y]} \n antal:&nbsp;{$kobs_ordre_antal[$y]}&nbsp;&aacute;&nbsp;" . dkdecimal($kobs_ordre_pris[$y]);
                    if ($kobs_ordre_art[$y] == 'KO') {
                        $link = "../kreditor/ordre.php?id={$kobs_ordre_id[$y]}";
                    } else {
                        $link = "../debitor/ordre.php?id={$kobs_ordre_id[$y]}";
                    }
                    print "<td align=\"right\" onClick=\"javascript:k_ordre=window.open('{$link}','ordre' ,'left=10,top=10,width=800,height=400,scrollbars=yes,resizable=yes,menubar=no,location=no');k_ordre.focus();\"onMouseOver=\"this.style.cursor = 'pointer'\" title=\"'{$spantekst}'\"><img src=\"../ikoner/opslag.png\"></td>\n";
                }
            } else {
                //print "<td><br></td>\n"; # udkommenteret 20140502
                if ($serienr[$x]) {
                    print "<td onClick=\"serienummer({$linje_id[$x]})\" onMouseOver=\"this.style.cursor = 'pointer'\" align=\"right\" title=\"Serienumre \"><img alt=\"Serienummer\" src=\"../ikoner/serienr.png\"></td>\n";
                }
            }
        }
        # 20150412
        if ($brugsamletpris) {
            print "<tr><td></td><td></td><td></td><td></td><td><textarea class=\"autosize inputbox ordreText comment\" id=\"comment\" rows=\"1\" cols=\"58\" name=\"ekstratekst\" onfocus=\"document.forms[0].fokus.value=this.name; var val=this.value; this.value=''; this.value= val;\"></textarea></td><td colspan=\"3\"><input style=\"width:100%\" type=\"submit\" name=\"tilfoj\" value=\"Tilføj\"></td></tr>";
        }
        #		$tmp=$momssum/100*$momssats; #ellers runder den ned ved v. 0,5 re ??
        #		$moms=afrund($tmp,3);
        $kostpris[0] = $kostpris[0] * 1;
        if ($submit == 'del_ordre' || $submit == 'Fakturer') {
            db_modify("update ordrer set sum='{$sum}',kostpris='{$kostpris['0']}',moms='{$moms}' where id='{$id}'", __FILE__ . " linje " . __LINE__);
        }
        if ($art == 'DK') {
            $sum = $sum * -1;
            $momssum = $momssum * -1;
            $moms = $moms * -1;
        }
        #		$tmp=$momssum/100*$momssats; #ellers runder den ned ved v. 0,5 ??
        #		$moms=afrund($tmp,3);
        $ialt = $sum + $moms;
        print "<tr><td colspan=\"11\"><br></td></tr>\n";
        print "<tr><td colspan=\"11\"><table border=\"1\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\"><tbody>\n";
        #Tabel 2.5.1 ->
        print "<tr bgcolor=\"{$bgcolor5}\">\n";
        #		print "<td align=\"center\">".dkdecimal($procenttillag)."% tillæg ".dkdecimal($tillag)." </td>\n";
        print "<td width=\"20%\" align=\"center\">Nettosum " . dkdecimal($sum) . "</td>\n";
        print "<td width=\"20%\" align=\"center\" title=\"D&aelig;kningsbidrag:&nbsp;" . dkdecimal($dbsum) . "\">";
        if (!$vis_saet) {
            print "D&aelig;kningsbidrag:&nbsp;" . dkdecimal($dbsum);
        }
        print "</td>\n";
        if ($sum) {
            $dg_sum = $dbsum * 100 / $sum;
        } else {
            $dg_sum = dkdecimal(0);
        }
        print "<td width=\"20%\" align=\"center\" title=\"D&aelig;kningsgrad:&nbsp;" . dkdecimal($dg_sum) . "%\">";
        if (!$vis_saet) {
            print "D&aelig;kningsgrad:&nbsp;" . dkdecimal($dg_sum);
        }
        print "</td>\n";
        print "<td align=\"center\">Moms " . dkdecimal($moms) . "</td>\n";
        print "<td align=\"center\" title=\"D&aelig;kningsgrad:&nbsp;" . dkdecimal($dg_sum) . "%\">I alt " . dkdecimal($ialt) . "</td>\n";
        print "</tbody></table></td></tr>\n";
        #<- Tabel 2.5.1
        print "<tr><td align=\"center\" colspan=\"11\">\n";
        print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody><tr>\n";
        #Tabel 2.5.2 ->
        if ($art != 'DK') {
            print "<td align=\"center\"><input type=\"submit\" class=\"button gray medium\" value=\"&nbsp;Kopi&eacute;r&nbsp;\" name=\"submit\" title=\"Kopi&eacute;r til ny ordre med samme indhold.\"></td>\n";
        }
        if ($mail_fakt) {
            $tmp = "value=\"&nbsp;Send&nbsp;\" onclick=\"return confirm('Dokumentet sendes pr. mail til {$email}')\" title=\"Send via e-mail med vedh&aelig;ftet PDF-fil. Anden form for behandling v&aelig;lges fra listen Udskriv til.\"";
        } else {
            $tmp = "value=\"&nbsp;Udskriv&nbsp;\" title=\"&Aring;bn et PDF-dokument, som kan gemmes eller viderebehandles p&aring; anden vis.\"";
        }
        print "<td align=\"center\"><input type=\"submit\" class=\"button gray medium\" name=\"submit\" {$tmp}></td>\n";
        if ($art != 'DK' && !$krediteret) {
            $title = "Klik her for at oprette en kreditnota, som hel eller delvist krediterer denne faktura. Kreditnotaen oprettes som en kreditnotaordre, som kan redigeres inden bogf&oslash;ring. Eksempelvis hvis kun en enkelt faktureret vare skal krediteres.";
            print "<td align=\"center\" title=\"{$title}\"><input type=\"submit\" class=\"button gray medium\" value=\"Kredit&eacute;r\" name=\"submit\"></td>\n";
        }
        print "</tbody></table></td></tr>\n";
        #<- Tabel 2.5.2
        print "</tbody></table></td></tr>\n";
        #<- Tabel 2.5
        print "</tbody></table></td></tr>\n";
        #<- Tabel 2
        print "</form>\n";
    } else {
        ############################# ordren er ikke faktureret #################################
        if ($brugernavn && !$ref) {
            $ref = $brugernavn;
        }
        if (!$konto_id) {
            #20150302
            if ($incl_moms) {
                $momssats = 25;
            }
            $status = 0;
        }
        if ($rvnr || $brugsamletpris) {
            $x = 1;
            $linje_id = array();
            $q = db_select("select id from ordrelinjer where ordre_id = '{$id}' and saet > 0 and varenr!='{$rvnr}' order by saet,samlevare,posnr,id", __FILE__ . " linje " . __LINE__);
            while ($r = db_fetch_array($q)) {
                $linje_id[$x] = $r['id'];
                $x++;
            }
            $q = db_select("select id,saet from ordrelinjer where ordre_id = '{$id}' and rabat > 0 and varenr!='{$rvnr}' order by saet,samlevare,posnr,id", __FILE__ . " linje " . __LINE__);
            while ($r = db_fetch_array($q)) {
                if (!$r['saet']) {
                    $linje_id[$x] = $r['id'];
                    $x++;
                }
            }
            $qtxt = "select id from ordrelinjer where ordre_id = '{$id}' and vare_id > '0' and (varenr='{$svnr}' or varenr='{$rvnr}')";
            if (db_fetch_array(db_select($qtxt, __FILE__ . " linje " . __LINE__))) {
                #20150914 Skal kun afvikles hvis der er rabat eller sæt vnr på ordren.
                $qtxt = "select id from ordrelinjer where ordre_id = '{$id}' and vare_id > '0' and varenr='{$rvnr}'";
                $r = db_fetch_array(db_select($qtxt, __FILE__ . " linje " . __LINE__));
                if ($linje_id[$x] = $r['id']) {
                    $x++;
                }
                $q = db_select("select * from ordrelinjer where ordre_id = '{$id}' order by posnr", __FILE__ . " linje " . __LINE__);
                while ($r = db_fetch_array($q)) {
                    if (!$r['saet'] && $r['rabat'] * 1 == 0 && $r['varenr'] != $rvnr || !$r['varenr']) {
                        $linje_id[$x] = $r['id'];
                        $x++;
                    }
                }
                for ($x = 1; $x <= count($linje_id); $x++) {
                    if ($linje_id[$x]) {
                        db_modify("update ordrelinjer set posnr='{$x}' where id='{$linje_id[$x]}'", __FILE__ . " linje " . __LINE__);
                    }
                }
            }
        }
        $qtxt = "select max(antal) as antal from ordrelinjer where ordre_id = '{$id}' and vare_id > '0'";
        $r = db_fetch_array(db_select($qtxt, __FILE__ . " linje " . __LINE__));
        $r['antal'] < 0 ? $dan_kn = 1 : ($dan_kn = NULL);
        print "<form name=\"ordre\" action=\"ordre.php?id={$id}&amp;sag_id={$sag_id}&amp;returside={$returside}\" method=\"post\">\n";
        print "<input type=\"hidden\" name=\"ordrenr\" value=\"{$ordrenr}\">\n";
        print "<input type=\"hidden\" name=\"status\" value=\"{$status}\">\n";
        print "<input type=\"hidden\" name=\"id\" value=\"{$id}\">\n";
        print "<input type=\"hidden\" name=\"art\" value=\"{$art}\">\n";
        print "<input type=\"hidden\" name=\"kred_ord_id\" value=\"{$kred_ord_id}\">\n";
        print "<input type=\"hidden\" name=\"sag_id\" value=\"{$sag_id}\">\n";
        #20140507-1
        if ($art == 'OT') {
            // Når input fields er 'disabled' bliver de ikke opdateret, derfor tilføjes hidden fields #20140716
            print "<input type=\"hidden\" name=\"kontonr\" value=\"{$kontonr}\">\n";
            print "<input type=\"hidden\" name=\"ref\" value=\"{$ref}\">\n";
            print "<input type=\"hidden\" name=\"procenttillag\" value=\"" . dkdecimal($procenttillag) . "\">";
            print "<input type=\"hidden\" name=\"felt_1\" style=\"width:200px\" value=\"{$felt_1}\">\n";
            print "<input type=\"hidden\" name=\"felt_2\" style=\"width:200px\" value=\"{$felt_2}\">\n";
            print "<input type=\"hidden\" name=\"felt_3\" style=\"width:200px\" value=\"{$felt_3}\">\n";
            print "<input type=\"hidden\" name=\"felt_4\" style=\"width:200px\" value=\"{$felt_4}\">\n";
            print "<input type=\"hidden\" name=\"felt_5\" style=\"width:200px\" value=\"{$felt_5}\">\n";
            print "<input type=\"hidden\" name=\"lev_navn\" value=\"{$lev_navn}\">\n";
            print "<input type=\"hidden\" name=\"lev_addr1\" value=\"{$lev_addr1}\"><input type=\"hidden\" name=\"lev_addr2\" value=\"{$lev_addr2}\">\n";
            print "<input type=\"hidden\" name=\"lev_postnr\" value=\"{$lev_postnr}\"><input type=\"hidden\" name=\"lev_bynavn\" value=\"{$lev_bynavn}\">\n";
            print "<input type=\"hidden\" name=\"lev_kontakt\" value=\"{$lev_kontakt}\">\n";
        }
        #cho "status $status<br>";
        #intiering af variabler
        $antal_ialt = 0;
        #10.10.2007
        $leveres_ialt = 0;
        #10.10.2007
        $tidl_lev_ialt = 0;
        #10.10.2007
        $konto_id *= 1;
        #cho "art: $art<br>"; #cho "vis_lev_addr: $vis_lev_addr<br>"; #cho "ref: $ref";
        $r = db_fetch_array(db_select("select * from adresser where id={$konto_id}", __FILE__ . " linje " . __LINE__));
        $k_firmanavn = HtmlEntities($r['firmanavn'], ENT_COMPAT, $charset);
        $k_addr1 = HtmlEntities($r['addr1'], ENT_COMPAT, $charset);
        $k_addr2 = HtmlEntities($r['addr2'], ENT_COMPAT, $charset);
        $k_postnr = HtmlEntities($r['postnr'], ENT_COMPAT, $charset);
        $k_bynavn = HtmlEntities($r['bynavn'], ENT_COMPAT, $charset);
        $k_land = HtmlEntities($r['land'], ENT_COMPAT, $charset);
        $k_cvrnr = HtmlEntities($r['cvrnr'], ENT_COMPAT, $charset);
        $k_betalingsbet = HtmlEntities($r['betalingsbet'], ENT_COMPAT, $charset);
        $k_betalingsdage = HtmlEntities($r['betalingsdage'], ENT_COMPAT, $charset);
        $k_email = HtmlEntities($r['email'], ENT_COMPAT, $charset);
        $k_ean = HtmlEntities($r['ean'], ENT_COMPAT, $charset);
        $k_institution = HtmlEntities($r['institution'], ENT_COMPAT, $charset);
        // Query til kunde kontakt
        $x = 0;
        #20140826
        $q = db_select("select * from ansatte where konto_id='{$konto_id}' order by posnr", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $a_kontakt[$x] = htmlspecialchars($r['navn']);
            $a_mobil[$x] = $r['mobil'];
            $a_email[$x] = HtmlEntities($r['email']);
            $x++;
        }
        //echo "kontakt: $kontakt<br>";
        //echo "konto id: $konto_id<br>";
        //echo "kontakt_tlf: $kontakt_tlf<br>";
        ##### pile ########	tilfoejet 20080210
        $alerttekst = findtekst(154, $sprog_id);
        $spantekst = findtekst(198, $sprog_id);
        print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"100%\" valign = \"top\"><tbody>\n";
        #Tabel 3 ->
        if ($prev_id) {
            print "<tr><td width=\"50%\" title=\"{$spantekst}\"><a href=\"javascript:confirmClose('ordre.php?id={$prev_id}&returside={$returside}','{$alerttekst}')\"><img src=\"../ikoner/left.png\" style=\"border: 0px solid; width: 15px; height: 15px;\"></a></span></td>\n";
        } else {
            print "<tr><td width=\"50%\"></td>\n";
        }
        $spantekst = findtekst(199, $sprog_id);
        if ($next_id) {
            print "<td width=\"50%\" align=\"right\" title=\"{$spantekst}\"><a href=\"javascript:confirmClose('ordre.php?id={$next_id}&returside={$returside}','{$alerttekst}')\"><img src=\"../ikoner/right.png\" style=\"border: 0px solid; width: 15px; height: 15px;\"></a></span></td></tr>\n";
        } else {
            print "<tr><td width=\"50%\"></td>\n";
        }
        print "</tbody></table>\n";
        # <- Tabel 3
        ##### pile ########
        print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\"\tvalign = \"top\"><tbody>\n";
        #Tabel 4 ->
        $ordre_id = $id;
        $ret = 0;
        $art == 'OT' ? $disabled = "disabled='disabled'" : ($disabled = NULL);
        #20140716
        print "<tr><td width=\"31%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
        #Tabel 4.1 ->
        print "<tr><td witdh=\"100\">Kontonr.</td><td colspan=\"2\">\n";
        if (trim($kontonr)) {
            if ($status < 1) {
                print "<input class=\"inputbox\" type=\"text\" style=\"width:200px;background-color:#ddd;\" name=\"kontonr\" readonly=\"readonly\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontonr}\" {$disabled}></td></tr>\n";
            } else {
                print "<input class=\"inputbox\" type=\"text\" readonly=\"readonly\" style=\"width:200px;background-color:#ddd;\" name=\"kontonr\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontonr}\"></td></tr>\n";
            }
        } else {
            print "<input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"kontonr\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontonr}\" onchange=\"javascript:docChange = true;\"></td></tr>\n";
        }
        if ($firmanavn == $k_firmanavn) {
            $tekstcolor = "#444444";
        } else {
            $tekstcolor = "#ff0000";
            $ret = 1;
        }
        print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_firmanavn}\">Firmanavn</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"firmanavn\" onfocus=\"document.forms[0].fokus.value=this.name;\"  value=\"{$firmanavn}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        if ($addr1 == $k_addr1 && $addr2 == $k_addr2) {
            $tekstcolor = "#444444";
        } else {
            $tekstcolor = "#ff0000";
            $ret = 1;
        }
        print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_addr1},{$k_addr2}\">Adresse</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"addr1\" onfocus=\"document.forms[0].fokus.value=this.name;\"  value=\"{$addr1}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        print "<tr><td></td><td colspan=\"2\" style=\"color:{$tekstcolor};\" ><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"addr2\" onfocus=\"document.forms[0].fokus.value=this.name;\"  value=\"{$addr2}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        if ($postnr == $k_postnr) {
            $tekstcolor = "#444444";
        } else {
            $tekstcolor = "#ff0000";
            $ret = 1;
        }
        print "<tr><td><span style=\"color:{$tekstcolor};\" title=\"{$k_postnr}\">Postnr.</span> &amp; ";
        if ($bynavn == $k_bynavn) {
            $tekstcolor = "#444444";
        } else {
            $tekstcolor = "#ff0000";
            $ret = 1;
        }
        print "<span style=\"color:{$tekstcolor};\" title=\"{$k_bynavn}\">by</span></td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:45px;\" name=\"postnr\" onfocus=\"document.forms[0].fokus.value=this.name;\"  value=\"{$postnr}\" onchange=\"javascript:docChange = true;\" {$disabled}><input class=\"inputbox\" type=\"text\" style=\"width:150px;margin-left:3px;\" name=\"bynavn\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$bynavn}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        if ($land == $k_land) {
            $tekstcolor = "#444444";
        } else {
            $tekstcolor = "#ff0000";
            $ret = 1;
        }
        print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_land}\">Land</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"land\" onfocus=\"document.forms[0].fokus.value=this.name;\"  value=\"{$land}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        if (!$sag_id) {
            #20140826
            print "<tr><td>Att.</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"kontakt\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontakt}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        } else {
            print "<tr><td>Att.</td><td colspan=\"2\"><div class=\"ddbox\"><input class=\"inputbox ddtext\" type=\"text\" name=\"kontakt\" id=\"Textbox\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontakt}\" onchange=\"javascript:docChange = true;\" {$disabled}>\n";
            // DropDownIndexClear('DropDownExTextbox');
            print "<select name=\"DropDownExTextbox\" id=\"DropDownExTextbox\" tabindex=\"1000\" class=\"inputbox ddselect\" {$disabled}>\n";
            // onchange=\"DropDownTextToBox(this,'Textbox');\"
            for ($y = 0; $y <= count($a_kontakt); $y++) {
                print "<option value=\"{$a_kontakt[$y]}\" data-kontakt_tlf=\"{$a_mobil[$y]}\">{$a_kontakt[$y]}</option>\n";
            }
            print "</select></div></td></tr>\n";
            print "<tr><td>Att. tlf</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"kontakt_tlf\" id=\"kontakt_tlf\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kontakt_tlf}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            #20160129
            print "<script language=\"javascript\" type=\"text/javascript\">\n\t\t\t\n\t\t\t\t\t\t\tDropDownIndexClear(\"DropDownExTextbox\");\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\$('#DropDownExTextbox').on('change', function () {\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tvar select = \$(this).find('option:selected').val()\n\t\t\t\t\t\t\t\t\tvar selectTlf = \$(this).find('option:selected').attr('data-kontakt_tlf')\n\t\t\t\t\t\t\t\t\t\$('#Textbox').val(select)\n\t\t\t\t\t\t\t\t\t\$('#kontakt_tlf').val(selectTlf)\n\t\t\t\t\t\t\tDropDownIndexClear(\"DropDownExTextbox\");\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t</script>\n";
        }
        print "<tr><td title=\"Kundens ordrenummer som refererence\">Kundeordre</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" name=\"kundeordnr\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$kundeordnr}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        #cho "$cvrnr!=$k_cvrnr<br>";
        if ($cvrnr != $k_cvrnr || $ean != $k_ean || $email != $k_email || $institution != $k_institution) {
            $ret = 1;
        }
        if ($ret) {
            print "<tr><td></td><td align=\"center\"><a href=\"sync_stamkort.php?konto_id={$konto_id}&ordre_id={$id}&retning=op\"><img src=\"../ikoner/up.png\" title=\"Klik her for at synkronisere stamkort med informationer fra ordre\" style=\"border: 0px solid; width: 25px; height: 25px;\"></a></td>";
            print "<td align=\"center\"><a href=\"sync_stamkort.php?konto_id={$konto_id}&ordre_id={$id}&retning=ned\"><img src=\"../ikoner/down.png\" title=\"Klik her for at synkronisere ordre med informationer fra stamkort\" style=\"border: 0px solid; width: 25px; height: 25px;\"></a></td></tr>\n";
        }
        print "</tbody></table></td>\n\n";
        # <- Tabel 4.1
        print "<td width=\"38%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"250\">\n";
        #Tabel 4.2 ->
        $cvrnr == $k_cvrnr ? $tekstcolor = "#444444" : ($tekstcolor = "#ff0000");
        print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_cvrnr}\">CVR-nr.</td><td><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"cvrnr\" value=\"{$cvrnr}\" onchange=\"javascript:docChange = true;\" {$disabled}></td>\n";
        $ean == $k_ean ? $tekstcolor = "#444444" : ($tekstcolor = "#ff0000");
        print "<td>&nbsp;</td><td style=\"color:{$tekstcolor};\">EAN-nr.</td><td><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"ean\" value=\"{$ean}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        $email == $k_email ? $tekstcolor = "#444444" : ($tekstcolor = "#ff0000");
        if (!$sag_id) {
            #20160303
            print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_email}\">E-mail</td><td><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"email\" value=\"{$email}\" onchange=\"javascript:docChange = true;\"></td>\n";
        } else {
            print "<tr><td style=\"color:{$tekstcolor};\" title=\"{$k_email}\">E-mail</td><td><div class=\"ddbox2\"><input class=\"inputbox ddtext2\" type=\"text\" name=\"email\" id=\"Textbox2\" value=\"{$email}\" onchange=\"javascript:docChange = true;\">\n";
            print "<select name=\"DropDownExTextbox2\" id=\"DropDownExTextbox2\" tabindex=\"1000\" class=\"inputbox ddselect2\">\n";
            if ($k_email) {
                print "<option value=\"{$k_email}\">Kunde:&nbsp;&nbsp;{$k_email}</option>\n";
                print "<option style=\"font-size: 1px; background-color: #cccccc;\" disabled></option>";
            }
            for ($y = 0; $y < count($a_email); $y++) {
                print "<option value=\"{$a_email[$y]}\">{$a_kontakt[$y]}:&nbsp;&nbsp;{$a_email[$y]}</option>\n";
            }
            print "<option>&nbsp;</option>\n";
            print "</select></div></td>\n";
            print "<script language=\"javascript\" type=\"text/javascript\">\n\t\t\t\n\t\t\t\t\t\t\tDropDownIndexClear(\"DropDownExTextbox2\");\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\$('#DropDownExTextbox2').on('change', function () {\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tvar select = \$(this).find('option:selected').val()\n\t\t\t\t\t\t\t\t\t\$('#Textbox2').val(select)\n\t\t\t\t\t\t\t\t\tDropDownIndexClear(\"DropDownExTextbox2\");\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t</script>\n";
        }
        $institution == $k_institution ? $tekstcolor = "#444444" : ($tekstcolor = "#ff0000");
        print "<td></td><td style=\"color:{$tekstcolor};\" title=\"{$k_institution}\">Institution</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"institution\" value=\"{$institution}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        print "<tr><td>Udskriv&nbsp;til</td>\n";
        if (!$udskriv_til) {
            if ($mail_fakt) {
                $udskriv_til = "email";
            }
            #			if ($oio_fakt) $udskriv_til="oioxml";
            if ($lev_pbs_nr) {
                if ($pbs) {
                    $udskriv_til = "PBS";
                }
            }
        }
        if (!$udskriv_til) {
            $udskriv_til = "PDF";
        }
        print "<td><select class=\"inputbox\" style=\"width:130px\" name=\"udskriv_til\">\n";
        if ($udskriv_til == "PBS" && $lev_pbs != 'B') {
            print "<option value=\"PBS\">PBS</option>\n";
        } else {
            print "<option>{$udskriv_til}</option>\n";
        }
        if ($udskriv_til != "PDF") {
            print "<option>PDF</option>\n";
        }
        if ($udskriv_til != "PDF-tekst") {
            print "<option title=\"Udskrives som PDF uden baggrund\">PDF-tekst</option>\n";
        }
        if ($udskriv_til != "email") {
            print "<option title=\"Sendes som PDF via e-mail\">email</option>\n";
        }
        #		if ($udskriv_til!="oioxml") print "<option title=\"Kun ved fakturering/kreditering.\">oioxml</option>\n"; #PHR 20090803
        if ($udskriv_til != "oioubl") {
            print "<option title=\"Kun ved fakturering/kreditering.\">oioubl</option>\n";
        }
        #PHR 20090803
        #		if ($udskriv_til!="edifakt") print "<option title=\"Kun ved fakturering/kreditering.\">edifakt</option>\n"; #PHR 20140201
        if ($udskriv_til != "historik" && db_fetch_array(db_select("select * from grupper where ART = 'bilag' and (box6='on' or (box1 !='' and box2 !='' and box3 !=''))", __FILE__ . " linje " . __LINE__))) {
            print "<option title=\"Gem en kopi og vedhæft kundens historik\">historik</option>\n";
        }
        $tmp = $pbs_nr * 1;
        # 20120822
        if ($lev_pbs_nr) {
            if ($lev_pbs == 'L') {
                if ($tmp) {
                    print "<option value=\"PBS\">PBS</option>\n";
                }
            } else {
                if ($udskriv_til != "PBS" && $lev_pbs != 'B') {
                    print "<option value=\"PBS_FI\">PBS</option>\n";
                } elseif ($tmp && $udskriv_til != "PBS" && $lev_pbs == 'B') {
                    print "<option title=\"Opkr&aelig;ves via PBS betalingsservice\">PBS</option>\n";
                }
            }
        }
        print "</SELECT></td>\n";
        print "<td>&nbsp;</td><td>Momssats</td><td><input class=\"inputbox\" style=\"text-align:right;width:40px\" type=\"text\" name=\"momssats\" value=\"" . dkdecimal($momssats) . "\" onchange=\"javascript:docChange = true;\" {$disabled}>%</td></tr>\n";
        /*
        		print "<tr><td colspan=2>Send pr. mail&nbsp;</td><td><input class=\"inputbox\" type=\"checkbox\" name=\"mail_fakt\" onchange=\"javascript:docChange = true;\" $mail_fakt></td>\n";
        		if ($lev_pbs_nr) {
        			if ($pbs == "FI") $pbs_fi='checked';
        			elseif ($pbs == "BS") $pbs_bs='checked';
        			$title="PBS udsender FI indbetalingskort";
        			if (!$pbs_bs) { #naeste linje ingen apostrof omkring $pbs_fi
        				print "<td colspan=\"2\" title=\"$title\">Faktura via PBS (FI)</td><td title=\"$title\"><input class=\"inputbox\" type=\"checkbox\" name=\"pbs_fi\" $pbs_fi onchange=\"javascript:docChange = true;\"></td></tr>\n";
        				if ($pbs_nr && !$pbs_fi) print "<tr><td colspan=\"2\"><td>\n";
        			}
        			$title="Opkr&aelig;ves via PBS betalingsservice";
        			if ($pbs_nr && !$pbs_fi) print "<td colspan=\"2\" title=\"$title\">Opkr&aelig;v via PBS (BS)</td><td title=\"$title\"><input class=\"inputbox\" type=\"checkbox\" name=\"pbs_bs\" \"$pbs_bs\" onchange=\"javascript:docChange = true;\"></td></tr>\n";
        		} else print "</tr>\n";
        */
        $mail_bilag == 'on' ? $checked = "checked='checked'" : ($checked = NULL);
        if ($udskriv_til == "email" && (strpos($_SERVER['SERVER_NAME'], 'ackup') || strpos($_SERVER['SERVER_NAME'], 'sl3'))) {
            print "<tr><td>Mail bilag</td><td><input type=\"checkbox\" name=\"mail_bilag\" {$checked}></td>";
        } else {
            print "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"mail_bilag\" value=\"{$mail_bilag}\"></td>";
        }
        if ($procentvare) {
            print "<td>&nbsp;</td><td>Procenttillæg</td><td><input class=\"inputbox\" style=\"text-align:right;width:40px\" type=\"text\" name=\"procenttillag\" value=\"" . dkdecimal($procenttillag) . "\" onchange=\"javascript:docChange = true;\" {$disabled}>%</td></tr>\n";
        } else {
            print "</tr>\n";
        }
        if (db_fetch_array(db_select("select distinct sprog from formularer where sprog != 'Dansk'", __FILE__ . " linje " . __LINE__))) {
            print "<tr><td title=\"Sprog som skal anvendes p&aring; dokumenter som tilbud, ordrer, fakturaer med videre.\">Sprog</span></td>\n";
            print "<td><select class=\"inputbox\" style=\"width:130px\" name=\"sprog\">\n";
            print "<option>{$formularsprog}</option>\n";
            $q = db_select("select distinct sprog from formularer order by sprog", __FILE__ . " linje " . __LINE__);
            while ($r = db_fetch_array($q)) {
                print "<option>{$r['sprog']}</option>\n";
            }
            print "</SELECT></td>";
        } else {
            print "<tr><td colspan=\"2\"></td>";
        }
        print "<tr><td colspan=\"5\"><hr></td></tr>\n";
        print "<tr><td width=\"20%\">Ordredato</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"ordredato\" value=\"{$ordredato}\" onchange=\"javascript:docChange = true;\" {$disabled}></td>\n";
        if ($hurtigfakt == 'on') {
            print "<td></td></tr>\n";
        } else {
            if ($art == 'DK') {
                print "<td title=\"Dato for returnering\">Modt.&nbsp;dato</td>";
            } else {
                print "<td title=\"Leveringsdato\">Lev.&nbsp;dato</td>";
            }
            print "<td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"levdato\" value=\"{$levdato}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
        }
        if ($fakturadato || $status > 0) {
            $dd = date("d-m-Y");
            print "<tr><td ";
            if ($art != 'DK') {
                print "title=\"Fakturadato\">Fakt.&nbsp;dato";
            } else {
                print "title=\"Dato for kreditnota\">KN.&nbsp;dato";
            }
            print "</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:130px\" placeholder=\"{$dd}\" name=\"fakturadato\" value=\"{$fakturadato}\" onchange=\"javascript:docChange = true;\"></td>\n";
            $tmp = "Genfaktureringsdato. Dette felt skal kun udfyldes, hvis der er tale om et abonnement eller \nlignende, som skal faktureres igen p&aring; et senere tidspunkt. \nSkriv datoen for n&aelig;ste fakturering";
            if ($art == 'DO') {
                print "<td width=\"20%\" title=\"{$tmp}\">Genfakt.</span></td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:130px\" name=\"genfakt\" value=\"{$genfakt}\" onchange=\"javascript:docChange = true;\"></td>\n";
            }
        }
        print "<tr><td>Betaling</td>\n";
        if (!$betalingsbet) {
            $betalingsbet = "Netto";
        }
        if ($art == 'DK') {
            print "<td colspan=\"2\"><select class=\"inputbox\" style=\"width:130px\" name=\"betalingsbet\">\n";
            if ($betalingsbet == 'Kontant') {
                print "<option>Kontant</option>\n";
            }
            if ($betalingsbet == 'Netto') {
                print "<option value='Netto'>Konto</option>\n";
            }
            if ($betalingsbet != 'Kontant') {
                print "<option>Kontant</option>\n";
            }
            if ($betalingsbet != 'Netto') {
                print "<option>Netto</option>\n";
            }
            if ($betalingsbet == 'Kontant' || $betalingsbet == 'Efterkrav' || $betalingsbet == 'Forud' || $betalingsbet == 'Kreditkort') {
                $betalingsdage = '';
            } else {
                $betalingsdage = 0;
            }
            print "</SELECT></td>\n";
        } else {
            if (!$betalingsbet) {
                $betalingsbet = "Netto";
            }
            print "<td colspan=\"2\"><select class=\"inputbox\" style=\"width:96px\" name=\"betalingsbet\" {$disabled}>\n";
            print "<option style=\"color: red !important;\">{$betalingsbet}</option>\n";
            if ($betalingsbet != 'Forud') {
                print "<option>Forud</option>\n";
            }
            if ($betalingsbet != 'Kontant') {
                print "<option>Kontant</option>\n";
            }
            if ($betalingsbet != 'Kreditkort') {
                print "<option>Kreditkort</option>\n";
            }
            if ($betalingsbet != 'Efterkrav') {
                print "<option>Efterkrav</option>\n";
            }
            if ($betalingsbet != 'Netto') {
                print "<option>Netto</option>\n";
            }
            if ($betalingsbet != 'Lb. md.') {
                print "<option>Lb. md.</option>\n";
            }
            if ($betalingsbet == 'Kontant' || $betalingsbet == 'Efterkrav' || $betalingsbet == 'Forud' || $betalingsbet == 'Kreditkort') {
                $betalingsdage = '';
            } elseif (!$betalingsdage) {
                $betalingsdage = 'Nul';
            }
            if ($betalingsdage) {
                if ($betalingsdage == 'Nul') {
                    $betalingsdage = 0;
                }
                print "</SELECT>+<input class=\"inputbox\" type=\"text\" style=\"text-align:right;width:25px\" name=\"betalingsdage\" value=\"{$betalingsdage}\" onchange=\"javascript:docChange = true;\" {$disabled}></td>\n";
            }
        }
        $list = array();
        $beskriv = array();
        $list[0] = 'DKK';
        $x = 0;
        $q = db_select("select * from grupper where art = 'VK'order by box1 ", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $x++;
            $list[$x] = $r['box1'];
            $beskriv[$x] = $r['beskrivelse'];
        }
        $tmp = $x;
        if ($x > 0) {
            $list[0] = 'DKK';
            $beskriv[0] = 'Danske kroner';
            print "<td>Valuta</td>\n";
            print "<td><select class=\"inputbox\" NAME=\"ny_valuta\">\n";
            for ($x = 0; $x <= $tmp; $x++) {
                if ($valuta != $list[$x]) {
                    print "<option title=\"{$beskriv[$x]}\">{$list[$x]}</option>\n";
                } else {
                    print "<option title=\"{$beskriv[$x]}\" selected=\"selected\">{$list[$x]}</option>\n";
                }
            }
            print "</SELECT></td><td></td>\n";
        } else {
            //print "<tr><td colspan=\"2\" width=\"200\">\n"; # udkommenteret 15052014
            print "</tr>\n";
        }
        $r = db_fetch_array(db_select("select id from adresser where art = 'S'", __FILE__ . " linje " . __LINE__));
        $adr_id = $r['id'] * 1;
        $x = 0;
        $ansat = array();
        $a_afd = array();
        $q = db_select("select navn,afd from ansatte where konto_id = '{$adr_id}' and lukket != 'on' order by navn", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $ansat[$x] = $r['navn'];
            $a_afd[$x] = $r['afd'];
            $x++;
        }
        if (!in_array($ref, $ansat)) {
            $r = db_fetch_array(db_select("select navn from ansatte,brugere where brugernavn='{$ref}' and ansatte.id=" . nr_cast('brugere.ansat_id') . "", __FILE__ . " linje " . __LINE__));
            if ($r['navn']) {
                $ref = $r['navn'];
            }
        }
        for ($x = 0; $x < count($ansat); $x++) {
            if (!$x) {
                print "<tr><td>Vor ref.</td>\n";
                print "<td><select class=\"inputbox\" name=\"ref\" {$disabled}>\n";
                print "<option>{$ref}</option>\n";
            }
            if ($ref != $ansat[$x]) {
                print "<option> {$ansat[$x]}</option>\n";
            }
        }
        print "</select>\n";
        $x = 0;
        $afd_navn = array();
        $afd_nr[$x] = array();
        $q = db_select("select * from grupper where art = 'AFD'", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $afd_nr[$x] = $r['kodenr'];
            $afd_navn[$x] = $r['beskrivelse'];
            $x++;
        }
        if (count($afd_nr) > 1) {
            print "</td><td></td>\n";
            print "<td>Afd</td><td><select name=\"afd\">";
            for ($x = 0; $x < count($afd_nr); $x++) {
                if ($afd_nr[$x] == $afd) {
                    print "<option value=\"{$afd_nr[$x]}\">{$afd_nr[$x]} {$afd_navn[$x]}</option>";
                }
            }
            for ($x = 0; $x < count($afd_nr); $x++) {
                if ($afd_nr[$x] != $afd) {
                    print "<option value=\"{$afd_nr[$x]}\">{$afd_nr[$x]} {$afd_navn[$x]}</option>";
                }
            }
            print "</select>";
        }
        print "</td></tr>\n";
        $list = array();
        $beskriv = array();
        $x = 0;
        $q = db_select("select * from grupper where art = 'PRJ' and kodenr != '0' order by kodenr", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $x++;
            $list[$x] = $r['kodenr'];
            $beskriv[$x] = $r['beskrivelse'];
        }
        $projektantal = $x;
        if ($x > 0) {
            $vis_projekt = 'on';
            print "<td title=\"Hvis hele ordren skal registreres p&aring; et projekt, v&aelig;lges projektet her. Ellers anvendes projektfeltet p&aring; ordrelinjen.\">Projekt</td>\n";
            print "<td><select class=\"inputbox\" name=\"projekt[0]\">\n";
            for ($x = 0; $x <= $projektantal; $x++) {
                if ($projekt[0] != $list[$x]) {
                    print "<option title=\"{$beskriv[$x]}\">{$list[$x]}</option>\n";
                } else {
                    print "<option title=\"{$beskriv[$x]}\" selected=\"selected\">{$list[$x]}</option>\n";
                }
            }
            print "</select></td></tr>\n";
        } else {
            print "<tr><td colspan=\"2\" width=\"200\"></tr>\n";
        }
        if ($status == 0 && $hurtigfakt != "on") {
            print "<tr><td>Godkend</td><td><input class=\"inputbox\" type=\"checkbox\" name=\"godkend\" {$disabled}></td></tr>\n";
        } elseif ($status < 3 && $hurtigfakt != "on") {
            if ($restordre) {
                $restordre = "checked";
            } else {
                $restordre = "";
            }
            print "<tr><td>Restordre</td><td><input class=\"inputbox\" type=\"checkbox\" name=\"restordre\" {$restordre}></td>\n";
        }
        print "</tbody></table></td>\n";
        # <- Tabel 4.2
        print "<td width=\"31%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" valign=\"top\">\n";
        # Tabel 4.3 ->
        if ($vis_lev_addr || !$kontonr) {
            print "<tr><td align=\"center\">{$jobkort} {$debitorkort}</td><td align=\"right\">Vis leveringsadresse <input type=\"checkbox\" name=\"vis_lev_addr\" checked=\"checked\"><td></tr>\n";
            print "<tr><td colspan=\"2\"><hr><td></tr>\n";
            print "<tr><td colspan=\"2\" align=\"center\"><b>Leveringsadresse</b></td></tr>\n";
            print "<tr><td colspan=\"2\"><hr></b></tr>\n";
            print "<tr><td>Firmanavn</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" onfocus=\"document.forms[0].fokus.value=this.name;\" name=\"lev_navn\" value=\"{$lev_navn}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            print "<tr><td>Adresse</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" onfocus=\"document.forms[0].fokus.value=this.name;\" name=\"lev_addr1\" value=\"{$lev_addr1}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            print "<tr><td></td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"lev_addr2\" value=\"{$lev_addr2}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            print "<tr><td>Postnr. &amp; by</td><td><input class=\"inputbox\" type=\"text\" style=\"width:45px\" onfocus=\"document.forms[0].fokus.value=this.name;\" name=\"lev_postnr\" value=\"{$lev_postnr}\" {$disabled}><input class=\"inputbox\" type=\"text\" style=\"width:150px;margin-left:3px;\" name=\"lev_bynavn\" value=\"{$lev_bynavn}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            print "<tr><td>Att.</td><td colspan=\"2\"><input class=\"inputbox\" type=\"text\" style=\"width:200px\" onfocus=\"document.forms[0].fokus.value=this.name;\" name=\"lev_kontakt\" value=\"{$lev_kontakt}\" onchange=\"javascript:docChange = true;\" {$disabled}></td></tr>\n";
            print "<input type=\"hidden\" name=\"felt_1\" style=\"width:200px\" value=\"{$felt_1}\">\n";
            print "<input type=\"hidden\" name=\"felt_2\" style=\"width:200px\" value=\"{$felt_2}\">\n";
            print "<input type=\"hidden\" name=\"felt_3\" style=\"width:200px\" value=\"{$felt_3}\">\n";
            print "<input type=\"hidden\" name=\"felt_4\" style=\"width:200px\" value=\"{$felt_4}\">\n";
            print "<input type=\"hidden\" name=\"felt_5\" style=\"width:200px\" value=\"{$felt_5}\">\n";
        } else {
            print "<tr><td align=\"center\">{$jobkort} {$debitorkort}</td><td align=\"right\">Vis leveringsadresse <input type=\"checkbox\" name=\"vis_lev_addr\"><td></tr>\n";
            print "<tr><td colspan=\"2\"><hr><td></tr>\n";
            print "<tr><td colspan=\"2\" align=\"center\"><b>" . findtekst(243, $sprog_id) . "</b></tr>\n";
            print "<tr><td colspan=\"2\"><hr></b></tr>\n";
            if ($vis_saet) {
                $felt_2 *= 1;
                $felt_4 *= 1;
                if ($fakturadate) {
                    if (!$felt_2) {
                        $felt_2 = $sum + $moms;
                    }
                    $felt_2 < $sum + $moms ? $felt_4 = $sum + $moms - $felt_2 : ($felt_4 = 0);
                }
                $dkfelt_2 = dkdecimal($felt_2, 2);
                $dkfelt_4 = dkdecimal($felt_4, 2);
                $r = db_fetch_array(db_select("select * from grupper where art = 'POS' and kodenr = '1'", __FILE__ . " linje " . __LINE__));
                $kortantal = $r['box4'] * 1;
                $korttyper = explode(chr(9), $r['box5']);
                print "<tr><td><select name=\"felt_1\">";
                if (!$felt_1) {
                    $felt_1 = $korttyper[0];
                }
                if ($felt_1) {
                    print "<option value=\"{$felt_1}\">{$felt_1}</value>";
                }
                if ($felt_1 != 'Kontant') {
                    print "<option value=\"Kontant\">Kontant</value>";
                }
                for ($x = 0; $x < $kortantal; $x++) {
                    if ($felt_1 != $korttyper[$x]) {
                        print "<option value=\"{$korttyper[$x]}\">{$korttyper[$x]}</value>";
                    }
                }
                print "</select></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_2\" style=\"text-align:right;width:200px\" value=\"{$dkfelt_2}\" {$disabled}></td></tr>";
                print "<tr><td><select name=\"felt_3\">";
                if ($felt_3) {
                    print "<option value=\"{$felt_3}\">{$felt_3}</value>";
                }
                if ($felt_3 != 'Kontant') {
                    print "<option value=\"Kontant\">Kontant</value>";
                }
                for ($x = 0; $x < $kortantal; $x++) {
                    if ($felt_3 != $korttyper[$x]) {
                        print "<option value=\"{$korttyper[$x]}\">{$korttyper[$x]}</value>";
                    }
                }
                print "</select></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_4\" style=\"text-align:right;width:200px\" value=\"{$dkfelt_4}\" {$disabled}></td></tr>";
            } else {
                if (substr(findtekst(244, $sprog_id), 0, 1) != "#") {
                    print "<tr><td><span onmouseover=\"return overlib('" . findtekst(249, $sprog_id) . "',WIDTH=600);\" onmouseout=\"return nd();\">" . findtekst(244, $sprog_id) . "</span></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_1\" style=\"width:200px\" value=\"{$felt_1}\" {$disabled}></td></tr>\n";
                }
                if (substr(findtekst(245, $sprog_id), 0, 1) != "#") {
                    print "<tr><td><span onmouseover=\"return overlib('" . findtekst(250, $sprog_id) . "',WIDTH=600);\" onmouseout=\"return nd();\">" . findtekst(245, $sprog_id) . "</span></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_2\" style=\"width:200px\" value=\"{$felt_2}\" {$disabled}></td></tr>\n";
                }
                if (substr(findtekst(246, $sprog_id), 0, 1) != "#") {
                    print "<tr><td><span onmouseover=\"return overlib('" . findtekst(251, $sprog_id) . "',WIDTH=600);\" onmouseout=\"return nd();\">" . findtekst(246, $sprog_id) . "</span></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_3\" style=\"width:200px\" value=\"{$felt_3}\" {$disabled}></td></tr>\n";
                }
                if (substr(findtekst(247, $sprog_id), 0, 1) != "#") {
                    print "<tr><td><span onmouseover=\"return overlib('" . findtekst(252, $sprog_id) . "',WIDTH=600);\" onmouseout=\"return nd();\">" . findtekst(247, $sprog_id) . "</span></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_4\" style=\"width:200px\" value=\"{$felt_4}\" {$disabled}></td></tr>\n";
                }
                if (substr(findtekst(248, $sprog_id), 0, 1) != "#") {
                    print "<tr><td><span onmouseover=\"return overlib('" . findtekst(253, $sprog_id) . "',WIDTH=600);\" onmouseout=\"return nd();\">" . findtekst(248, $sprog_id) . "</span></td><td><input class=\"inputbox\" type=\"text\" name=\"felt_5\" style=\"width:200px\" value=\"{$felt_5}\" {$disabled}></td></tr>\n";
                }
            }
            print "<input type=\"hidden\" name=\"lev_navn\" value=\"{$lev_navn}\">\n";
            print "<input type=\"hidden\" name=\"lev_addr1\" value=\"{$lev_addr1}\"><input type=\"hidden\" name=\"lev_addr2\" value=\"{$lev_addr2}\">\n";
            print "<input type=\"hidden\" name=\"lev_postnr\" value=\"{$lev_postnr}\"><input type=\"hidden\" name=\"lev_bynavn\" value=\"{$lev_bynavn}\">\n";
            print "<input type=\"hidden\" name=\"lev_kontakt\" value=\"{$lev_kontakt}\">\n";
        }
        print "</td></tr></tbody></table></td></tr>\n";
        #<- Tabel 4.3
        $row2 = db_fetch_array(db_select("select notes from adresser where kontonr = '{$kontonr}' and art = 'D'", __FILE__ . " linje " . __LINE__));
        #20142403-1
        $notes = str_replace("\n", "<br>", $row2['notes']);
        if ($notes) {
            print "<tr><td colspan=\"3\" witdh=\"100%\" style=\"color: rgb(255,0,0)\">{$notes}</td></tr>\n";
        }
        /*
        $query = db_select("select notes from adresser where kontonr = '$kontonr' and art = 'D'",__FILE__ . " linje " . __LINE__);
        if ($row2 = db_fetch_array($query) ) {
        	$notes=str_replace("\n","<br>",$row2['notes']);
        	print "<tr><td colspan=\"3\" witdh=\"100%\" style=\"color: rgb(255,0,0)\">$notes</td></tr>\n";
        }
        */
        if ($udskriv_til == 'email') {
            if (!$formularsprog) {
                $formularsprog = 'Dansk';
            }
            $status < 1 ? $form_nr = 1 : ($form_nr = 2);
            if ($art == 'DK') {
                $form_nr = 5;
            }
            $q = db_select("select * from formularer where formular='{$form_nr}' and art='5' and lower(sprog)='" . strtolower($formularsprog) . "'", __FILE__ . " linje " . __LINE__);
            while ($r = db_fetch_array($q)) {
                if ($r['xa'] == '1') {
                    $std_subj = $r['beskrivelse'];
                } elseif ($r['xa'] == '2') {
                    $std_txt_title = $r['beskrivelse'];
                }
            }
            if ($art != 'DK') {
                $q = db_select("select * from formularer where formular='4' and art='5' and lower(sprog)='" . strtolower($formularsprog) . "'", __FILE__ . " linje " . __LINE__);
            }
            while ($r = db_fetch_array($q)) {
                if ($r['xa'] == '1') {
                    $fak_subj = $r['beskrivelse'];
                } elseif ($r['xa'] == '2') {
                    $fak_text = str_replace("<br>", "", $r['beskrivelse']);
                }
            }
            $subj_title = '';
            if (!$mail_subj && $art != 'DK') {
                $subj_title = HtmlEntities("Ved fakturering ændres emneteksten til:\n\n{$fak_subj}", ENT_COMPAT, $charset);
            }
            $text_title = '';
            if (!$mail_text && $art != 'DK') {
                $text_title = HtmlEntities("Ved fakturering ændres mailteksten til:\n\n{$fak_text}", ENT_COMPAT, $charset);
            }
            list($std_txt, $tmp) = explode("<br>", $std_txt_title);
            $mail_text ? $std_txt_title = $mail_text : ($std_txt_title = str_replace("<br>", "", $std_txt_title));
            print "<tr><td align=\"center\" colspan=\"3\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tbody>\n";
            #Tabel 4.4 ->
            if (!$mail_subj && !$mail_text && $art != 'DK') {
                print "<tr><td></td><td colspan=\"1\" align=\"left\"><small>Nedenstående tekster ændres ved fakturering, hold musen over beskrivelsen til venstre for at se ændringen</small></td>";
            }
            print "<tr><td width=\"120px\" title=\"{$subj_title}\">Mail emne</td><td title=\"{$std_subj}\"><input class=\"inputbox\" type=\"text\" style=\"width:1000px;\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_subj\" placeholder=\"{$std_subj}\" value=\"{$mail_subj}\" onchange=\"javascript:docChange = true;\"></td>";
            if ($bilag) {
                if ($dokument) {
                    print "<td title=\"klik her for at &aring;bne bilaget: {$dokument}\"><a href=\"../includes/bilag.php?kilde=ordrer&filnavn={$dokument}&bilag_id={$id}&bilag={$dokument}&kilde_id={$id}\"><img style=\"border: 0px solid\" alt=\"clip_m_papir\" src=\"../ikoner/paper.png\"></a></td>";
                } else {
                    print "<td title=\"klik her for at vedh&aelig;fte et bilag\"><a href=\"../includes/bilag.php?kilde=ordrer&bilag_id={$id}&bilag={$dokument}&ny=ja&kilde_id={$id}\"><img  style=\"border: 0px solid\" alt=\"clip\" src=\"../ikoner/clip.png\"></a></td>";
                }
            }
            print "</tr><tr><td valign=\"top\"  title=\"{$text_title}\">Mail tekst</td><td title=\"{$std_txt_title}\">";
            if ($mail_text) {
                print "<textarea style=\"width:1000px;\" rows=\"2\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_text\" onchange=\"javascript:docChange = true;\">{$mail_text}</textarea>\n";
            } else {
                print "<input class=\"inputbox\" type=\"text\" style=\"width:1000px;\" onfocus=\"document.forms[0].fokus.value=this.name;\"name=\"mail_text\" placeholder=\"{$std_txt}\" value=\"{$mail_text}\" onchange=\"javascript:docChange = true;\">";
            }
            print "</td></tr></tbody></table></td></tr>\n";
            # <- Tabel 4.4
        }
        print "<tr><td align=\"center\" colspan=\"3\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tbody>\n";
        # Tabel 4.5 ->
        if ($kontonr) {
            print "<tr><td align=\"center\" title=\"Positionsnummer. R&aelig;kkef&oslash;lgen &aelig;ndres ved at overskrive positionsnumrene (1,5 hvis mellem 1 og 2). En enkelt linje slettes ved at skrive minustegn som positionsnummer.\">Pos.</td><td align=\"center\" title=\"Varenummer. Skriv hele varenumret eller klik p&aring; Opslag for at v&aelig;lge. Hvis du vil v&aelig;lge mellem varenumre startende med t, s&aring; skriv t* i feltet og klik p&aring; Opslag.\">Varenr.</td><td align=\"center\" title=\"Antal enheder. Timer og minutter kan angives med : som skilletegn. Eksempelvis 5:45 som bliver til 5,75.\">Antal</td><td align=\"center\">Enhed</td><td align=\"center\" title=\"Brug [Shift]+[Enter] for et indsætte et linjeskift i en beskrivelseslinje\">Beskrivelse</td><td align=\"center\">Pris</td><td align=\"center\">Rabat</td>";
            if ($procentfakt) {
                print "<td align=\"center\">Procent</td>";
            }
            print "<td align=\"center\">I alt</td>";
            if ($vis_projekt && !$projekt[0]) {
                print "<td align=\"center\">Proj.</td>";
            }
            if ($genfakt) {
                print "<td align=\"center\" title=\"'Kun denne ordre'. Afm&aelig;rk dette felt hvis ordrelinjen ikke skal med ved genfakturering eller kopiering af ordren.\">kdo</td>\n";
            }
            if ($status >= 1 && $hurtigfakt != 'on') {
                if ($art != 'DK') {
                    $tmp = "Lev&eacute;r";
                    $tmp2 = "Indtastningsfeltet herunder er det antal, som leveres ved klik p&aring; Lev&eacute;r. Antallet i parantes er det, som allerede er leveret.";
                } else {
                    $tmp = "Modtag";
                    $tmp2 = "Indtastningsfeltet herunder er det antal, som modtages ved klik p&aring; Modtag. Antallet i parantes er det, som allerede er modtaget.";
                }
                print "<td colspan=\"2\" align=\"center\" title=\"{$tmp2}\">{$tmp}</td>";
            }
        }
        if ($omkunde) {
            print "<td title =\"Hvis feltet vises er kunden underlagt reglerne for omvendt betalingspligt. Er varen ligeledes omfattet vil feltet herunder være afmærket pr default og momsen vil være undertrykt for den pågældende vare.\">O/B</td>";
        }
        print "</tr>\n";
        if (!$status) {
            $status = 0;
        }
        print "<input type=\"hidden\" name=\"status\" value=\"{$status}\">";
        print "<input type=\"hidden\" name=\"id\" value=\"{$id}\">\n";
        $x = 0;
        if (!$ordre_id) {
            $ordre_id = 0;
        }
        $kostpris[0] = 0;
        $kostsum = 0;
        $blandet_moms = 0;
        #tilfojet 20100923 grundet afrundingsfejl på ordre med rabat
        $lagervarer = 0;
        #		db_modify("update ordrelinjer set posnr=posnr+10  where varenr = '$svnr'");
        #		global $db;
        $query = db_select("select * from ordrelinjer where ordre_id = '{$ordre_id}' order by posnr", __FILE__ . " linje " . __LINE__);
        #		$query = db_select("select * from ordrelinjer where ordre_id = '$ordre_id' order by saet desc,samlevare,posnr,id",__FILE__ . " linje " . __LINE__);
        while ($row = db_fetch_array($query)) {
            if ($row['posnr'] > 0 && !is_numeric($row['samlevare']) && $row['samlevare'] < 1) {
                #Hvis "samlevare" er numerisk,indgaar varen i den ordrelinje,der refereres til - hvis "on" er varen en samlevare.
                $x++;
                $linje_id[$x] = $row['id'];
                $kred_linje_id[$x] = $row['kred_linje_id'];
                $posnr[$x] = $row['posnr'];
                $varenr[$x] = HtmlEntities(trim($row['varenr']), ENT_COMPAT, $charset);
                $beskrivelse[$x] = HtmlEntities(trim($row['beskrivelse']), ENT_COMPAT, $charset);
                if ($beskrivelse[$x] == ".") {
                    $beskrivelse[$x] = "";
                }
                $enhed[$x] = HtmlEntities(trim($row['enhed']), ENT_COMPAT, $charset);
                $pris[$x] = $row['pris'];
                $rabat[$x] = $row['rabat'] * 1;
                $rabatart[$x] = $row['rabatart'];
                $procent[$x] = $row['procent'] * 1;
                $antal[$x] = $row['antal'] * 1;
                $leveres[$x] = $row['leveres'];
                $vare_id[$x] = $row['vare_id'];
                $momsfri[$x] = $row['momsfri'];
                $rabatgruppe[$x] = $row['rabatgruppe'];
                $m_rabat[$x] = $row['m_rabat'] * -1;
                $folgevare[$x] = $row['folgevare'] * 1;
                $varemomssats[$x] = $row['momssats'] * 1;
                $fast_db[$x] = $row['fast_db'] * 1;
                $saet[$x] = $row['saet'];
                $lev_varenr[$x] = $row['lev_varenr'];
                $kostpris[$x] = $row['kostpris'];
                $row['omvbet'] ? $omvbet[$x] = 'checked' : ($omvbet[$x] = NULL);
                if (!$momsfri[$x] && !$varemomssats[$x]) {
                    $varemomssats[$x] = $momssats;
                } elseif ($varemomssats[$x] > $momssats) {
                    $varemomssats[$x] = $momssats;
                } elseif ($momsfri[$x] || $omvbet[$x]) {
                    $varemomssats[$x] = 0;
                }
                $serienr[$x] = HtmlEntities(trim($row['serienr']), ENT_COMPAT, $charset);
                $samlevare[$x] = $row['samlevare'];
                $projekt[$x] = $row['projekt'];
                $row['kdo'] ? $kdo[$x] = 'checked' : ($kdo[$x] = NULL);
                if ($vare_id[$x]) {
                    if ($fast_db[$x]) {
                        $kostpris[$x] = $pris[$x] * $fast_db[$x];
                        /*
                        					} else {
                        						list($koordpr,$koordnr,$koordant,$koordid,$koordart)=explode(chr(9),find_kostpris($vare_id[$x],$linje_id[$x]));
                        						$kobs_ordre_pris=explode(",",$koordpr);
                        						$kobs_ordre_antal=explode(",",$koordant);
                        						$ko_ant[$x]=count($kobs_ordre_pris);
                        						$kostpris[$x]=0;
                        				#rettet 20120418 grundet fejl i kostpris v leverring af flere omgange på samme ordrelinje på købsordre
                        				#rettet yderligere 20121213 grundet ny fejl hvis køb er fordelt over flere købsordrer
                        						for($y=0;$y<$ko_ant[$x];$y++) $kostsum[$x]+=$kobs_ordre_pris[$y]*$kobs_ordre_antal[$y];
                        						($antal[$x])?$kostpris[$x]=$kostsum[$x]/$antal[$x]:$kostpris[$x]=0;
                        						if ($valutakurs) $kostpris[$x]*=100/$valutakurs; #20140116
                        */
                    }
                    $kostsum += $kostpris[$x] * $antal[$x];
                    /*					
                    #cho "update ordrelinjer set kostpris='$kostpris[$x]' where id='$linje_id[$x]'<br>";
                    				db_modify("update ordrelinjer set kostpris='$kostpris[$x]' where id='$linje_id[$x]'",__FILE__ . " linje " . __LINE__);
                    */
                    if ($rabatart[$x] == 'amount') {
                        $db[$x] = $pris[$x] - $rabat[$x];
                    } else {
                        $db[$x] = $pris[$x] - $pris[$x] * $rabat[$x] / 100;
                    }
                    #20140424 -=
                    $db[$x] -= $kostpris[$x];
                    #20140424 -=
                    #cho "$db[$x]=$pris[$x]-$kostpris[$x]<br>";
                    if ($pris[$x] != 0) {
                        $dg[$x] = $db[$x] * 100 / $pris[$x];
                    } else {
                        $dg[$x] = 0;
                    }
                    $dk_db[$x] = dkdecimal($db[$x]);
                    $dk_dg[$x] = dkdecimal($dg[$x]);
                }
                if ($art == 'DK' && $antal[$x] < 0) {
                    $bogfor == 0;
                }
                if ($serienr[$x]) {
                    $serienumre[$x] = NULL;
                    $q2 = db_select("select serienr from serienr where salgslinje_id='{$linje_id[$x]}' order by serienr", __FILE__ . " linje " . __LINE__);
                    while ($r2 = db_fetch_array($q2)) {
                        $serienumre[$x] ? $serienumre[$x] .= ',' . $r2['serienr'] : ($serienumre[$x] = $r2['serienr']);
                    }
                }
                if (!$lagervarer && $vare_id[$x]) {
                    $r2 = db_fetch_array(db_select("select grupper.box8 from varer,grupper where varer.id = '{$vare_id[$x]}' and grupper.art='VG' and grupper.kodenr=varer.gruppe", __FILE__ . " linje " . __LINE__));
                    if ($r2['box8']) {
                        $lagervarer = 1;
                    }
                }
            }
        }
        $linjeantal = $x;
        #cho "Lagervarer $lagervarer<br>";
        $moms = 0;
        $sum = 0;
        $ny_pos = 0;
        $saetnr = 0;
        $saetpris = 0;
        for ($x = 1; $x <= $linjeantal; $x++) {
            if ($saet[$x]) {
                if ($saetnr && $saetnr != $saet[$x]) {
                    # tilføjer linjen for sætpris
                    $qtxt = "select beskrivelse from ordrelinjer where saet = '{$saetnr}' and ordre_id='{$id}' and samlevare='on'";
                    $r = db_fetch_array(db_select($qtxt, __FILE__ . " linje " . __LINE__));
                    list($sum, $dbsum, $blandet_moms, $moms) = explode(chr(9), ordrelinjer($x, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, '0', '0', '0', '0', $linje_id[$x], '0', '', '', $r['beskrivelse'], '', $saetpris, $rabat[$x], 'percent', '100', '1', '0', $vare_id[$x], '', '0', '0', $momssats, '', 'on', '', '', '', '', '', '', '', '', '', '', '0', '', '0', $saetnr));
                    $saetpris = 0;
                }
                if (!$saetpris) {
                    print "<tr><td><br></td></tr>";
                }
                $linjesum = $pris[$x] * $antal[$x];
                $linjesum -= $linjesum * $rabat[$x] / 100;
                $linjesum += $linjesum * $varemomssats[$x] / 100;
                $saetpris += afrund($linjesum, 3);
                $saetnr = $saet[$x];
            } elseif ($saetnr) {
                $r = db_fetch_array(db_select("select beskrivelse from ordrelinjer where saet = '{$saetnr}' and ordre_id='{$id}' and samlevare='on'", __FILE__ . " linje " . __LINE__));
                list($sum, $dbsum, $blandet_moms, $moms) = explode(chr(9), ordrelinjer($x, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, '0', '0', '0', '0', '0', '0', '', '', $r['beskrivelse'], '', $saetpris, '0', 'percent', '100', '1', '0', '0', '', '0', '0', '0', '', '', '', '', '', '', '', '', '', '', '', '', '0', '', '0', $saetnr));
                $saetpris = 0;
                $saetnr = 0;
                print "<tr><td><br></td></tr>";
            }
            if (!$folgevare[$x] || $folgevare[$x] >= 0) {
                list($sum, $dbsum, $blandet_moms, $moms, $antal_ialt, $leveres_ialt, $tidl_lev_ialt, $tidl_lev[$x], $levdiff) = explode(chr(9), ordrelinjer($x, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, $leveres_ialt, $tidl_lev_ialt, $levdiff, $projekt[0], $linje_id[$x], $kred_linje_id[$x], $posnr[$x], $varenr[$x], $beskrivelse[$x], $enhed[$x], $pris[$x], $rabat[$x], $rabatart[$x], $procent[$x], $antal[$x], $leveres[$x], $vare_id[$x], $momsfri[$x], $rabatgruppe[$x], $m_rabat[$x], $varemomssats[$x], $serienr[$x], $samlevare[$x], $folgevare[$x], $projekt[$x], $kdo[$x], $kobs_ordre_pris, $ko_ant[$x], $kostpris[$x], $db[$x], $dg[$x], $dk_db[$x], $dk_dg[$x], '0', $omvbet[$x], $saet[$x], $saetnr));
            }
            if ($samlevare[$x] == 'on') {
                $q = db_select("select * from ordrelinjer where ordre_id = '{$ordre_id}' and samlevare = '{$linje_id[$x]}' order by id", __FILE__ . " linje " . __LINE__);
                while ($r = db_fetch_array($q)) {
                    $antal_ialt += $r['antal'];
                    if ($r['antal'] > 0) {
                        $tmp = 0;
                        $q2 = db_select("select antal from batch_salg where linje_id = '{$r['id']}' and ordre_id='{$id}' and vare_id = '{$r['vare_id']}'", __FILE__ . " linje " . __LINE__);
                        while ($r2 = db_fetch_array($q2)) {
                            $tmp = $tmp + $r2['antal'];
                        }
                        if ($art == 'DK') {
                            $dkantal = dkdecimal($r['antal'] * -1);
                        } else {
                            $dkantal = dkdecimal($r['antal']);
                        }
                        if (substr($dkantal, -1) == '0') {
                            $dkantal = substr($dkantal, 0, -1);
                        }
                        if (substr($dkantal, -1) == '0') {
                            $dkantal = substr($dkantal, 0, -2);
                        }
                    }
                    $tidl_lev_ialt += $tmp;
                    print "<tr><td></td><td>{$r['varenr']}</td><td align=\"right\">{$dkantal}</td><td>{$r['enhed']}</td><td>{$r['beskrivelse']}</td></tr>";
                }
            }
            print "<input type=\"hidden\" name=\"samlevare[{$x}]\" value=\"{$samlevare[$x]}\">\n";
            if ($folgevare[$x] > 0) {
                $x_nr = 0;
                $fv_linje_id = 0;
                for ($i = 1; $i <= $linjeantal; $i++) {
                    $tmp = $linje_id[$x] * -1;
                    if ($tmp == $folgevare[$i]) {
                        $x_nr = $i;
                        $fv_linje_id = $linje_id[$i] * 1;
                        $fv_varenr = $varenr[$i];
                        $fv_salgspris = $pris[$i];
                        $fv_kostpris = $kostpris[$i];
                        $fv_enhed = $enhed[$i];
                        $fv_beskrivelse = $beskrivelse[$i];
                        $fv_varemomssats = $varemomssats[$i];
                        $fv_db = $fv_salgspris - $fv_kostpris;
                        $fv_salgspris != 0 ? $fv_dg = $fv_db * 100 / $fv_salgspris : ($fv_dg = 0);
                    }
                }
                if (!$fv_linje_id) {
                    global $regnaar;
                    $r = db_fetch_array(db_select("select varer.varenr,varer.beskrivelse,varer.enhed,varer.salgspris,varer.kostpris,grupper.box4,grupper.box7 from varer,grupper where varer.id = '{$folgevare[$x]}' and grupper.art='VG' and grupper.kodenr=varer.gruppe", __FILE__ . " linje " . __LINE__));
                    $fv_linje_id = 0;
                    $fv_varenr = $r['varenr'];
                    $fv_salgspris = $r['salgspris'];
                    $fv_kostpris = $r['kostpris'];
                    $fv_enhed = $r['enhed'];
                    $fv_beskrivelse = $r['beskrivelse'];
                    $fv_db = $fv_salgspris - $fv_kostpris;
                    $fv_salgspris != 0 ? $fv_dg = $fv_db * 100 / $fv_salgspris : ($fv_dg = 0);
                    $r2 = db_fetch_array(db_select("select moms from kontoplan where kontonr = '{$r['box4']}' and regnskabsaar = '{$regnaar}'", __FILE__ . " linje " . __LINE__));
                    if ($tmp = trim($r2['moms'])) {
                        # f.eks S3
                        $tmp = substr($tmp, 1);
                        #f.eks 3
                        $r2 = db_fetch_array(db_select("select box2 from grupper where art = 'SM' and kodenr = '{$tmp}'", __FILE__ . " linje " . __LINE__));
                        if ($r2['box2']) {
                            $fv_varemomssats = $r2['box2'] * 1;
                        }
                    } else {
                        $fv_varemomssats = $momssats;
                    }
                }
                $fv_dk_db = dkdecimal($fv_db);
                $fv_dk_dg = dkdecimal($fv_dg);
                list($sum, $dbsum, $blandet_moms, $moms) = explode(chr(9), ordrelinjer($x_nr, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, $leveres_ialt, $tidl_lev_ialt, $levdiff, $projekt[0], $fv_linje_id, 0, $x, $fv_varenr, $fv_beskrivelse, $fv_enhed, $fv_salgspris, 0, 'percent', $procent[$x], $antal[$x], $leveres[$x], $folgevare[$x], $fv_momsfri, 0, 0, $fv_varemomssats, 0, 0, 0, $projekt[$x], $kdo[$x], 0, 0, $fv_kostpris, $fv_db, $fv_dg, $fv_dk_db, $fv_dk_dg, '1', $saet[$x], $saetnr));
            }
            print "<input type=\"hidden\" name=\"folgevare[{$x}]\" value=\"{$folgevare[$x]}\">\n";
            if ($saet[$x] && $x == $linjeantal && $saetpris) {
                #			$r=db_fetch_array(db_select("select beskrivelse from varer where id = '$svid'",__FILE__ . " linje " . __LINE__));
                $r = db_fetch_array(db_select("select beskrivelse from ordrelinjer where saet = '{$saetnr}' and ordre_id='{$id}' and samlevare='on'", __FILE__ . " linje " . __LINE__));
                #cho __LINE__."<br>";
                list($sum, $dbsum, $blandet_moms, $moms) = explode(chr(9), ordrelinjer($x, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, '0', '0', '0', '0', '0', '0', '', '', $r['beskrivelse'], '', $saetpris, '0', 'percent', '100', '1', '0', '0', '', '0', '0', '0', '', '', '', '', '', '', '', '', '', '', '', '', '0', '', '0', $saetnr));
                $saetnr = 0;
            }
        }
        if ($brugsamletpris && $samlet_rabat && $samlet_pris && $samlet_pris != $ordresum) {
            $x++;
            $diff = afrund($samlet_pris - ($sum + $moms), 3);
            $tmp = $sum + $moms;
            if ($samlet_rabat) {
                $ms = afrund($moms * 100 / ($sum + $moms), 2);
                #20150318
                $r = db_fetch_array(db_select("select id,beskrivelse from varer where varenr = '{$rvnr}'", __FILE__ . " linje " . __LINE__));
                opret_ordrelinje($id, $r['id'], $rvnr, 1, $r['beskrivelse'], $diff, $ms, 100, 'DO', '', '', '0', '', '', '', '99', '0');
                $r = db_fetch_array(db_select("select * from ordrelinjer where ordre_id = '{$id}' and varenr = '{$rvnr}'", __FILE__ . " linje " . __LINE__));
                $vist_rabat = $samlet_pris - $bruttosaetsum . "|" . $samlet_pris;
                db_modify("update ordrelinjer set lev_varenr='{$vist_rabat}' where id='{$r['id']}'", __FILE__ . " linje " . __LINE__);
                list($sum, $dbsum, $blandet_moms, $moms) = explode(chr(9), ordrelinjer($x, $sum, $dbsum, $blandet_moms, $moms, $antal_ialt, '0', '0', '0', '0', $r['id'], '0', '99', $rvnr, $r['beskrivelse'], '', $r['pris'], $r['rabat'], 'percent', '100', '1', '0', $r['vare_id'], '', '0', '0', $momssats, '', '', '', '', '', '', '', '', '', '', '', '', '0', '', '0', '0'));
            }
        }
        $sum = afrund($sum, 2);
        $moms = afrund($moms, 2);
        print "<input type=\"hidden\" name=\"linjeantal\" value=\"{$linjeantal}\">\n";
        print "<input type=\"hidden\" name=\"lagervarer\" value=\"{$lagervarer}\">\n";
        if ($status >= 1 && $bogfor != 0 && !$leveres_ialt && $tidl_lev_ialt && $antal_ialt != $tidl_lev_ialt) {
            $del_ordre = 'on';
        } else {
            $del_ordre = '';
        }
        if ($kontonr) {
            $x++;
            $antal[0] = 1;
            $posnr[0] = $linjeantal + 1;
            if ($varenr[0] && isset($_GET['vare_id'])) {
                #20150407
                $fokus = "dkan0";
                #20150306 + value i dkan0
                $r = db_fetch_array(db_select("select * from varer where varenr='{$varenr['0']}'", __FILE__ . " linje " . __LINE__));
                $beskrivelse[0] = $r['beskrivelse'];
                $pris[0] = $r['salgspris'];
                print "<input type=\"hidden\" name=\"indsat\" value=\"" . $_GET['vare_id'] . "\">";
                if ($incl_moms) {
                    if ($r = db_fetch_array(db_select("select box7 from grupper where art='VG' and kodenr='{$gruppe}' and box7!='on'", __FILE__ . " linje " . __LINE__))) {
                        $momsfri[0] = $r2['box7'];
                    } else {
                        $pris[0] += $pris[0] * $momssats / 100;
                    }
                }
            } else {
                $varenr[0] = NULL;
                $antal[0] = NULL;
            }
            if ($art != 'OT') {
                // ordrelinje til indtastning behøves ikke at vises ved 'Original tilbud' #20140716
                print "<tr>\n";
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"text-align:right\" size=\"3\" name=\"posn0\" value=\"{$posnr['0']}\"></td>\n";
                if ($art == 'DK') {
                    print "<td valign=\"top\"><input class=\"inputbox\" readonly=\"readonly\" size=\"12\" name=\"vare0\" onfocus=\"document.forms[0].fokus.value=this.name;\"></td>\n";
                } else {
                    print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" size=\"12\" name=\"vare0\" onfocus=\"document.forms[0].fokus.value=this.name;\" value=\"{$varenr['0']}\"></td>\n";
                }
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"text-align:right\" size=\"4\" name=\"dkan0\" placeholder=\"{$antal['0']}\"></td>\n";
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"background: none repeat scroll 0 0 #e4e4ee\" readonly=\"readonly\" size=\"3\"></td>\n";
                //print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" size=\"58\" name=\"beskrivelse0\" onfocus=\"document.forms[0].fokus.value=this.name;\"></td>\n";
                print "<td valign=\"top\"><textarea class=\"autosize inputbox ordreText comment\" id=\"comment\" rows=\"1\" cols=\"58\" name=\"beskrivelse0\" placeholder=\"{$beskrivelse['0']}\" onfocus=\"document.forms[0].fokus.value=this.name; var val=this.value; this.value=''; this.value= val;\"></textarea></td>\n";
                #2013.11.27 Ændret til textarea, så hele texten vises #2013.11.29 indsat ny onfocus da chrome ikke satte curser efter tekst
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"text-align:right\" size=\"10\" name=\"pris0\" placeholder=\"" . dkdecimal($pris[0]) . "\"></td>\n";
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"text-align:right\" size=\"4\" name=\"raba0\">\n";
                if ($procentfakt) {
                    print "</td><td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"text-align:right\" size=\"4\" name=\"proc0\" value=\"100,00\"></td>\n";
                } else {
                    print "<input type=\"hidden\" name=\"proc0\" value=\"100,00\"></td>\n";
                }
                print "<td valign=\"top\"><input class=\"inputbox\" type=\"text\" style=\"background: none repeat scroll 0 0 #e4e4ee\" readonly=\"readonly\" size=\"10\"></td>\n";
                if ($vis_projekt && !$masterprojekt) {
                    print "<td></td>";
                }
                if ($genfakt) {
                    print "<td title=\"Afm&aelig;rk dette felt hvis ordrelinjen ikke skal med ved genfakturering / kopiering.\"><input class=\"inputbox\" name=\"kdo[0]\" type=\"checkbox\"></td>\n";
                }
                print "<td valign=\"top\" colspan=\"2\"><input type=\"button\" name=\"insert\" class=\"button white small bold\" value=\"B\" onClick=\"this.form.beskrivelse0.value=this.form.beskrivelse0.value.concat('<b></b>'); this.form.beskrivelse0.focus();\" title=\"Indsættes ved fed tekst. Sæt cursoren imellem <b> og </b>\n(F.eks. <b>Lorem ipsum</b>).\">\n";
                #2013.11.29 Sætter fokus på felt ved clik
                print "<input type=\"button\" name=\"insert\" class=\"button white small italic\" value=\"I\" onClick=\"this.form.beskrivelse0.value=this.form.beskrivelse0.value.concat('<i></i>'); this.form.beskrivelse0.focus();\" title=\"Indsættes ved kursiv tekst. Sæt cursoren imellem <i> og </i>\n(F.eks. <i>Lorem ipsum</i>).\nKan også bruges til tom linje. Her insættes <i></i> uden tekst. \"></td>\n";
                print "</tr>\n";
            }
            if ($procenttillag) {
                $r = db_fetch_array(db_select("select beskrivelse from varer where varenr = '{$procentvare}'", __FILE__ . " linje " . __LINE__));
                $tillag = $sum * $procenttillag / 100;
                $beskr = var2str($r['beskrivelse'], $id, $posnr[$x], $varenr[$x], $dkantal[$x], $enhed[$x], $dkpris, $dkprocent, $serienr[$x], $varemomssats[$x], $dkrabat[$x]);
                $beskr = str_replace('$procenttillæg;', dkdecimal($procenttillag), $beskr);
                print "<tr>\n";
                print "<td></td>\n";
                print "<td>{$procentvare}</td>\n";
                print "<td></td>\n";
                print "<td></td>\n";
                print "<td>{$beskr}</td>\n";
                print "<td></td>\n";
                print "<td></td>\n";
                print "<td></td>\n";
                print "<td align=right>" . dkdecimal($tillag) . "</td>\n";
                if ($art != 'OT') {
                    print "<td></td>\n";
                }
                #20140716
                print "</tr>\n";
                $sum += $tillag;
                $dbsum += $tillag;
                $moms += $tillag / 100 * $momssats;
            }
            print "<input type=\"hidden\" name=\"sum\" value=\"{$sum}\">\n";
            if (!$blandet_moms && !$incl_moms) {
                $moms = $sum * $momssats / 100;
            }
            #tilfojet 20100923 grundet afrundingsfejl på ordre med rabat
            $moms = afrund($moms * 1, 3);
            $kostpris[0] = $kostpris[0] * 1;
            db_modify("update ordrer set sum={$sum},kostpris={$kostsum},moms={$moms} where id={$id}", __FILE__ . " linje " . __LINE__);
            if ($art == 'DK') {
                $sum = $sum * -1;
                $moms = $moms * -1;
            }
            $ialt = $sum + $moms;
            print "<tr><td colspan=\"12\"><table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tbody>\n";
            # Tabel 4.5.1 ->
            print "<tr>\n";
            #			print "<td align=\"center\">".dkdecimal($procenttillag)."% tillæg:&nbsp;".dkdecimal($tillag)."</td>\n";
            print "<td align=\"center\">Nettosum:&nbsp;" . dkdecimal($sum) . "</td>\n";
            if ($vis_saet) {
                $db = $sum - $kostsum;
            } else {
                $db = $dbsum;
            }
            print "<td width=\"20%\" align=\"center\"  title=\"DB: DKK " . dkdecimal($db * $valutakurs / 100) . "\">";
            if (!$vis_saet) {
                print "D&aelig;kningsbidrag:&nbsp;" . dkdecimal($db);
            }
            print "</td>\n";
            if ($sum) {
                $dg_sum = $db * 100 / $sum;
            } else {
                $dg_sum = dkdecimal(0);
            }
            print "<td width=\"20%\" align=\"center\"  title=\"DG;" . dkdecimal($dg_sum) . "%\">";
            if (!$vis_saet) {
                print "D&aelig;kningsgrad:&nbsp;" . dkdecimal($dg_sum) . "%";
            }
            print "</td>\n";
            print "<td width=\"20%\" align=\"center\" align=\"center\">Moms:&nbsp;" . dkdecimal($moms) . "</td>\n";
            print "<td width=\"20%\" align=\"center\" align=\"center\" title=\"DG;" . dkdecimal($dg_sum) . "%\">I alt:";
            if ($brugsamletpris && $art == 'DO') {
                print "<input type=\"hidden\" name=\"ordresum\" value=\"" . afrund($ialt, 2) . "\">";
                print "<input style=\"width:100px;text-align:right\" type=\"text\" name=\"samlet_pris\" value=\"" . dkdecimal($ialt) . "\">";
            } else {
                print dkdecimal($ialt);
            }
            print "</td>\n";
        }
        print "</tbody></table></td></tr>\n";
        # <- Tabel 4.5.1
        if ($fokus != 'dkan' . count($vare_id)) {
            print "<input type=\"hidden\" name=\"fokus\">\n";
        }
        #20151019
        print "<tr><td align=\"center\" colspan=\"12\">\n";
        print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tbody><tr>\n";
        # Tabel 4.5.2 ->
        if ($status < 3) {
            if ($levdiff) {
                $status = 1;
            } elseif ($status == 1) {
                $status++;
            }
            //if ($status<1) $width="33%";
            //elseif ($sum!=0) $width="25%";
            if ($hurtigfakt == 'on' && $fakturadato) {
                print "<input type=\"hidden\" name=\"levdato\" value=\"{$fakturadato}\">\n";
            }
            print "<input type=\"hidden\" name=\"valutakurs\" value=\"{$valutakurs}\">\n";
            print "<input type=\"hidden\" name=\"status\" value=\"{$status}\">\n";
            print "<td align=\"center\" width={$width}><input type=\"submit\" class=\"button gray medium\" id=\"submit\" style=\"width:75px;\" accesskey=\"g\" value=\"Gem\" name=\"submit\" onclick=\"javascript:docChange = false;\"></td>\n";
            if ($art != 'OT') {
                # Fjerner knappen opslag hvis art er = OT (original tilbud) #20140716
                print "<td align=\"center\" width={$width}><input type=\"submit\" class=\"button blue medium\" style=\"width:75px;\" accesskey=\"o\" value=\"Opslag\" name=\"submit\" ";
                if ($art == "DK") {
                    print "disabled=\"disabled\" ";
                }
                print "onclick=\"javascript:docChange = false;\"></td>\n";
            }
            if ($status == 1 && $bogfor != 0 && $hurtigfakt != 'on' && $leveres_ialt) {
                if ($art == 'DO') {
                    print "<td align=\"center\" width={$width}><input type=\"submit\" class=\"button gray medium\" style=\"width:75px;\" accesskey=\"l\" value=\"Lev&eacute;r\" name=\"submit\" onclick=\"javascript:docChange = false;\"></td>\n";
                } else {
                    print "<td align=\"center\" width={$width} title=\"Klik her for at tage varer retur\"><input type=\"submit\"  class=\"button gray medium\" style=\"width:75px;\" accesskey=\"l\" value=\"Modtag\" name=\"submit\" onclick=\"javascript:docChange = false;\"></td>\n";
                }
            }
            if ($status == 2 && $bogfor != 0 || $status > 0 && $hurtigfakt == 'on') {
                $disabled = NULL;
                $titletext = '';
                $tmp = "";
                $dd = date("d-m-Y");
                if ($art != 'DK' && !$dan_kn) {
                    if ($udskriv_til == 'email') {
                        $tmp = "onclick=\"return confirm('Faktura sendes pr. mail til {$email}')\"";
                    } elseif ($udskriv_til == 'PBS') {
                        $tmp = "onclick=\"return confirm('Faktura tilføjes PBS/Nets liste!')\"";
                    } elseif ($udskriv_til == 'oioubl') {
                        $tmp = "onclick=\"return confirm('Faktura genereres som OIOUBL fil!')\"";
                    } elseif (!$fakturadato) {
                        $tmp = "onclick=\"return confirm('Fakturadato sættes til {$dd}!')\"";
                    } else {
                        $tmp = "";
                    }
                    if ($vis_saet) {
                        if (($betalingsbet == 'Netto' || $betalingsbet == 'Lb.md') && is_numeric($felt_2) && $felt_2 != 0) {
                            #20150313
                            $tmp = "onclick=\"return confirm('Betalingsbetingelser er sat til {$betalingsbet} {$betalingsdage} dage og betaling til {$felt_1}!\\\n Vil du det?')\"";
                        } else {
                            if ($fakturadate && $fakturadate != date('Y-m-d')) {
                                $tmp = "onclick=\"return confirm('Fakturadato er ikke idag!\\\n Vil du det?')\"";
                            }
                            if ($felt_2 + $felt_4 < $sum + $moms) {
                                $disabled = 'disabled';
                                $titletext = 'Vælg betalingsmåde';
                            }
                        }
                    }
                    #echo "$art=='DO' && $dan_kn<br>";
                    print "<td align=\"center\" width=\"{$width}\" title=\"{$titletext}\"><input {$disabled} type=\"submit\" class=\"button gray medium\" style=\"width:75px;\" accesskey=\"f\" value=\"Faktur&eacute;r\" name=\"submit\" {$tmp}></td>\n";
                } else {
                    if ($vis_saet) {
                        $disabled = NULL;
                        $titletext = '';
                        $diff = afrund($felt_2 + $felt_4 + ($sum + $moms), 2);
                        if ($diff) {
                            $disabled = 'disabled';
                            $titletext = 'Vælg betalingsmåde';
                        }
                    }
                    if ($art == 'DO' && $dan_kn) {
                        $tmp = "onclick=\"return confirm('Ordre omdannes til kreditnota ved fakturering!')\"";
                    }
                    if ($mail_fakt) {
                        $tmp = "onclick=\"return confirm('Kreditnota sendes pr. mail til {$email}')\"";
                    }
                    print "<td align=\"center\" width=\"{$width}\" title=\"{$titletext}\"><input {$disabled} type=\"submit\" class=\"button gray medium\" style=\"width:75px;\" accesskey=\"f\" value=\"Kredit&eacute;r\" name=\"submit\" {$tmp}></td>\n";
                }
            } elseif ($del_ordre == 'on') {
                $txt = "Klik her for at opdele ordren i 2.<br>Den ene vil indeholde ikke leverede varer<br>Den anden vil indeholde leverede varer";
                print "<td align=\"center\" width=\"{$width}\" >\n\t\t\t\t\t<span onmouseover=\"return overlib('{$txt}',WIDTH=800);\" onmouseout=\"return nd();\">\n\t\t\t\t\t<input type=\"submit\" class=\"button gray medium\" accesskey=\"f\" value=\"Del ordre\" name=\"submit\" style=\"width:75px;\" onclick=\"javascript:docChange = false;\"></span></td>\n";
            }
            if ($linjeantal > 0 && $konto_id && ($art == 'DO' || $art == 'OT')) {
                # skal også med ved 'original tilbud' (OT) #20140716
                if ($mail_fakt && $status < 1) {
                    $tmp = "onclick=\"return confirm('Tilbud sendes pr mail til {$email}')\"";
                } elseif ($mail_fakt && $hurtigfakt && $status < 3) {
                    $tmp = "onclick=\"return confirm('Ordrebekr&aelig;ftelse sendes pr mail til {$email}')\"";
                } elseif ($mail_fakt && $status < 2) {
                    $tmp = "onclick=\"return confirm('Ordrebekr&aelig;ftelse sendes pr. mail til {$email}')\"";
                } else {
                    $tmp = "";
                }
                $udskriv_til == 'email' ? $value = 'Send' : ($value = 'Udskriv');
                print "<td align=\"center\" width={$width}><input type=\"submit\" class=\"button gray medium\" style=\"width:75px;\" value=\"{$value}\" name=\"submit\" {$tmp} title=\"{$tekst2}\" onclick=\"javascript:docChange = false;\"></td>\n";
            }
            if ($status < 3 && $brugsamletpris && $svnr && $konto_id) {
                print "<td align=\"center\" width={$width}><input type=\"button\" class=\"button gray medium\" style=\"width:75px;\" value=\"Sæt\" name=\"ret_saet\" title=\"Klik her for at oprette eller rette i varesæt\" onclick=\"jacascript:window.location.href='saetpris.php?id={$id}'\"></td>\n";
            }
            $tekst = findtekst(155, $sprog_id);
            $tekst2 = findtekst(156, $sprog_id);
            if (count($leveret) == 0 && $art != 'OT' && $id) {
                print "<td align=\"center\"><input type=\"submit\" class=\"button rosy medium\" style=\"width:75px;\" value=\"Slet\" name=\"submit\" onclick=\"return confirm('{$tekst}')\" title=\"{$tekst2}\"></td>\n";
            }
            if ($art == 'OT' && $sag_id) {
                print "<td align=\"center\"><a class=\"button gray medium mozMedium\" style=\"\" title=\"klik her for at kopiér tilbud til ny sag\" href=\"../sager/sager.php?funktion=kopi_ordre&amp;sag_id={$sag_id}&amp;konto_id={$konto_id}&amp;ordre_id={$id}&amp;returside=ordre\">Kopiér</a></td>\n";
            }
            print "</tbody></table></td></tr>\n";
            # <- Tabel 4.5.2
            print "</form>\n";
            print "</tbody></table></td></tr>\n";
            # <- Tabel 4.5
            //print "<tr><td></td></tr>\n";
        }
        # end if ($status < 3)
        if ($konto_id) {
            $r = db_fetch_array(db_select("select kreditmax from adresser where id = '{$konto_id}'", __FILE__ . " linje " . __LINE__));
        }
        if ($kreditmax = $r['kreditmax'] * 1) {
            if ($valutakurs) {
                $kreditmax = $kreditmax * 100 / $valutakurs;
            }
            $q = db_select("select * from openpost where konto_id = '{$konto_id}' and udlignet='0'", __FILE__ . " linje " . __LINE__);
            $tilgode = 0;
            while ($r = db_fetch_array($q)) {
                if (!$r['valuta']) {
                    $r['valuta'] = 'DKK';
                }
                if (!$r['valutakurs']) {
                    $r['valutakurs'] = 100;
                }
                if ($valuta == 'DKK' && $r['valuta'] != 'DKK') {
                    $opp_amount = $r['amount'] * $r['valutakurs'] / 100;
                } elseif ($valuta != 'DKK' && $r['valuta'] == 'DKK') {
                    if ($r3 = db_fetch_array(db_select("select kurs from grupper,valuta where grupper.art='VK' and grupper.box1='{$valuta}' and valuta.gruppe = " . nr_cast('grupper.kodenr') . " and valuta.valdate <= '{$r['transdate']}' order by valuta.valdate desc"))) {
                        $opp_amount = $r['amount'] * 100 / $r3['kurs'];
                    } elseif ($valuta) {
                        print "<BODY onLoad=\"javascript:alert('Ingen valutakurs for faktura {$r['faktnr']}')\">\n";
                    }
                } elseif ($valuta != 'DKK' && $r['valuta'] != 'DKK' && $r['valuta'] != $valuta) {
                    $tmp == $r['amount'] * $r['valuta'] / 100;
                    $opp_amount = $tmp * 100 / $r['valutakurs'];
                } else {
                    $opp_amount = $r['amount'];
                }
                $tilgode = $tilgode + $opp_amount;
            }
            if ($kreditmax < $ialt + $tilgode) {
                $tmp = dkdecimal($ialt + $tilgode - $kreditmax, 2);
                print "<BODY onLoad=\"javascript:alert('Kreditloft overskrides med {$valuta} {$tmp}')\">\n";
            }
        }
        # end  if ($kreditmax....
        print "</tbody></table></td></tr>\n";
        # <- Tabel 4
        print "</form>\n";
        #
    }
    # end else for (if ($status>=3))
    # ADD LINK TO GLS!!
    if ($db_id == '390') {
        # || $db_id=='2'
        print "<tr><td align=\"center\"><br>";
        print "<form name=\"glslabel_form\" action=\"../includes/gls.php\" target=\"_blank\" method=\"POST\">" . "\n<input type=\"hidden\" name=\"txtAction\" value=\"70120\">" . "\n<input type=\"hidden\" name=\"txtConsigneeNo\" value=\"" . $kontonr . "\">" . "\n<input type=\"hidden\" name=\"txtWeight\" value=\"1\">" . "\n<input type=\"hidden\" name=\"txtCountryNum\" value=\"208\">" . "\n<input type=\"hidden\" name=\"txtReferenceNo\" value=\"" . $ordrenr . " \">" . "\n<input type=\"hidden\" name=\"txtConsigneeEmail\" value=\"" . $email . " \">";
        if (!empty($lev_navn)) {
            print "\n<input type=\"hidden\" name=\"txtName1\" value=\"" . $lev_navn . "\">";
            print "\n<input type=\"hidden\" name=\"txtZipCodeDisplay\" value=\"" . $lev_postnr . "\">";
            print "\n<input type=\"hidden\" name=\"txtCity\" value=\"" . $lev_bynavn . "\">";
            print "\n<input type=\"hidden\" name=\"txtStreet\" value=\"" . $lev_addr1 . "\">";
            print "\n<input type=\"hidden\" name=\"txtName2\" value=\"" . $lev_addr2 . "\">";
            print "\n<input type=\"hidden\" name=\"txtContact\" value=\"" . $lev_kontakt . "\">";
        } else {
            print "\n<input type=\"hidden\" name=\"txtName1\" value=\"" . $firmanavn . "\">";
            print "\n<input type=\"hidden\" name=\"txtZipCodeDisplay\" value=\"" . $postnr . "\">";
            print "\n<input type=\"hidden\" name=\"txtCity\" value=\"" . $bynavn . "\">";
            print "\n<input type=\"hidden\" name=\"txtStreet\" value=\"" . $addr1 . "\">";
            print "\n<input type=\"hidden\" name=\"txtName2\" value=\"" . $addr2 . "\">";
            print "\n<input type=\"hidden\" name=\"txtContact\" value=\"" . $kontakt . "\">";
        }
        print "\n<input type=\"submit\" value=\"Send til GLS\"></form>";
        if ($cvrnr && !is_numeric(substr($cvrnr, 0, 2))) {
            $landekode = substr($cvrnr, 0, 2);
        } elseif (strtolower($land) == 'sverige' || strtolower($land) == 'sweden') {
            $landekode = 'se';
        } elseif (strtolower($land) == 'norge' || strtolower($land) == 'norway') {
            $landekode = 'no';
        } else {
            $landekode = 'se';
        }
        print "<form name=\"fedexlabel_form\" action=\"https://www.fedex.com/shipping/shipEntryAction.do\" target=\"_blank\" method=\"POST\">" . "\n<input type=\"hidden\" name=\"txtAction\" value=\"70120\">" . "\n<input type=\"hidden\" name=\"txtConsigneeNo\" value=\"" . $kontonr . "\">" . "\n<input type=\"hidden\" name=\"txtWeight\" value=\"1\">" . "\n<input type=\"hidden\" name=\"txtCountryNum\" value=\"208\">" . "\n<input type=\"hidden\" name=\"billingData.referenceData.yourReference\" value=\"" . $ordrenr . "\">" . "\n<input type=\"hidden\" name=\"notificationData.recipientNotifications.email\" value=\"" . $email . "\">" . "\n<input type=\"hidden\" name=\"notificationData.recipientNotifications..pickupNotificationFlag\" value=\"true\">" . "\n<input type=\"hidden\" name=\".companyName\" value=\"" . $firmanavn . "\">" . "\n<input type=\"hidden\" name=\"toData.addressLine1\" value=\"" . $addr1 . "\">" . "\n<input type=\"hidden\" name=\"toData.addressLine2\" value=\"" . $addr2 . "\">" . "\n<input type=\"hidden\" name=\"toData.city\" value=\"" . $bynavn . "\">" . "\n<input type=\"hidden\" name=\"toData.zipPostalCode\" value=\"" . $postnr . "\">" . "\n<input type=\"hidden\" name=\"toData.contactName\" value=\"" . $kontakt . "\">" . "\n<input type=\"hidden\" name=\"toData.countryCode\" value=\"{$landekode}\">" . "\n<input type=\"hidden\" name=\"toData.taxID\" value=\"" . $cvrnr . "\">" . "\n<input type=\"hidden\" name=\"toData.phoneNumber\" value=\"" . $tlf . "\">" . "\n<input type=\"hidden\" name=\"psdData.numberOfPackages\" value=\"1\">" . "\n<input type=\"hidden\" name=\"psdData.mpsRowDataList[0].weight\" value=\"1\">" . "\n<input type=\"hidden\" name=\"psdData.serviceType\" value=\"International Economy\">" . "\n<input type=\"hidden\" name=\"psdData.packageType\" value=\"Your Packaging\">" . "\n<input type=\"hidden\" name=\"psdData.serviceType\" value=\"International Economy\">" . "\n<input type=\"hidden\" name=\"billingData.selectedBillDutiesAndTaxIndex\" value=\"R\">" . "\n<input type=\"hidden\" name=\"billingData.referenceData.invoiceNumber\" value=\"{$fakturanr}\">";
        //fedex fragttype
        "\n<input type=\"hidden\" name=\"commodityData.totalCustomsValue\" value=\"{$sum}\">" . "\n<input type=\"hidden\" name=\"commodityData.documentShipping\" value=\"false\">";
        //
        if (!empty($lev_navn)) {
            print "\n<input type=\"hidden\" name=\"toData.addressData.countryCode\" value=\"{$landekode}\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.companyName\" value=\"" . $lev_navn . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.zipPostalCode\" value=\"" . $lev_postnr . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.city\" value=\"" . $lev_bynavn . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.addressLine1\" value=\"" . $lev_addr1 . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.addressLine2\" value=\"" . $lev_addr2 . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.contactName\" value=\"" . $lev_kontakt . "\">";
        } else {
            print "\n<input type=\"hidden\" name=\"toData.addressData.countryCode\" value=\"{$landekode}\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.companyName\" value=\"" . $firmanavn . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.zipPostalCode\" value=\"" . $postnr . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.city\" value=\"" . $bynavn . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.addressLine1\" value=\"" . $addr1 . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.addressLine2\" value=\"" . $addr2 . "\">";
            print "\n<input type=\"hidden\" name=\"toData.addressData.contactName\" value=\"" . $kontakt . "\">";
        }
        print "\n<input type=\"submit\" value=\"Send til Fedex\"></form>";
        print "</td></tr>";
    }
    print "<!--Function ordreside s**t-->";
}
Exemple #4
0
function vareopslag($sort, $fokus, $id, $vis, $ref, $find)
{
    global $konto_id;
    global $kontonr;
    global $bgcolor;
    global $bgcolor5;
    global $charset;
    if ($find) {
        $find = str_replace("*", "%", $find);
    }
    if (!$konto_id) {
        if (!$kontonr && $id) {
            $query = db_select("select kontonr from ordrer where id = {$id}", __FILE__ . " linje " . __LINE__);
            if ($row = db_fetch_array($query)) {
                $kontonr = trim($row[kontonr]);
            }
        }
        if ($kontonr) {
            $query = db_select("select id from adresser where kontonr = '{$kontonr}' and art = 'K'", __FILE__ . " linje " . __LINE__);
            if ($row = db_fetch_array($query)) {
                $konto_id = $row[id];
            }
        }
    }
    sidehoved($id, "../kreditor/ordre.php", "../lager/varekort.php", "{$fokus}&leverandor={$konto_id}", "Leverand&oslash;rordre {$id}");
    #	print"<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody>";
    #	print"<tr><td valign=\"top\">";
    $listeantal = 0;
    if ($id) {
        $q = db_select("select id,beskrivelse from grupper where art='PL' and box4='on' and box1='{$konto_id}' order by beskrivelse", __FILE__ . " linje " . __LINE__);
        while ($r = db_fetch_array($q)) {
            $listeantal++;
            $prisliste[$listeantal] = $r['id'];
            $listenavn[$listeantal] = $r['beskrivelse'];
        }
        print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\t\" width=\"100%\" valign = \"top\"><tbody><tr>";
        if ($listeantal) {
            print "<form name=\"prisliste\" action=\"../includes/prislister.php?start=0&ordre_id={$id}&fokus={$fokus}\" method=\"post\">";
            print "<td><select name=prisliste>";
            for ($x = 1; $x <= $listeantal; $x++) {
                print "<option value=\"{$prisliste[$x]}\">{$listenavn[$x]}</option>";
            }
            print "</select><input type=\"submit\" name=\"prislist\" value=\"Vis\"></td>";
        }
    }
    print "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"100%\" valign = \"top\">";
    print "<tbody><tr>";
    print "<td><b><a href=ordre.php?sort=varenr&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Varenr</a></b></td>";
    print "<td><b> Enhed</b></td>";
    print "<td><b><a href=ordre.php?sort=beskrivelse&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Beskrivelse</a></b></td>";
    print "<td align=right><b><a href=ordre.php?sort=salgspris&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis={$vis}>Salgspris</a></b></td>";
    print "<td align=right><b> Kostpris</b></td>";
    print "<td align=right><b> Beholdning&nbsp;</b></td>";
    #	print"<td width=2%></td>";
    print "<td align><b> Leverand&oslash;r</b></td>";
    if ($kontonr) {
        if ($vis) {
            print "<td align=right><a href=ordre.php?sort={$sort}&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}><span title='Klik her for at vise alle varer fra alle leverand&oslash;rer'>Alle&nbsp;lev.</span></a></td>";
        } else {
            print "<td align=right><a href=ordre.php?sort={$sort}&funktion=vareOpslag&x={$x}&fokus={$fokus}&id={$id}&vis=1><span title='Klik her for kun at vise alle varer fra denne leverand&oslash;exit\n\t\t\tr'>Denne&nbsp;lev.</span></a></td>";
        }
    }
    print " </tr>\n";
    $sort = $_GET['sort'];
    if (!$sort) {
        $sort = varenr;
    }
    $vare_id = array();
    if ($vis && $konto_id) {
        $temp = " and lev_id = " . $konto_id;
    }
    $y = 0;
    $skjul_vare_id = array();
    $vis_vare_id = array();
    $query = db_select("select * from vare_lev", __FILE__ . " linje " . __LINE__);
    while ($row = db_fetch_array($query)) {
        $y++;
        if (!$konto_id || !$vis || $row['lev_id'] == $konto_id || $row['lev_id'] == '0') {
            $vis_vare_id[$y] = $row['vare_id'];
        } else {
            $skjul_vare_id[$y] = $row['vare_id'];
        }
    }
    if ($ref) {
        if ($row = db_fetch_array(db_select("select afd from ansatte where navn = '{$ref}'", __FILE__ . " linje " . __LINE__))) {
            if ($row = db_fetch_array(db_select("select kodenr from grupper where box1='{$row['afd']}' and art='LG'", __FILE__ . " linje " . __LINE__))) {
                $lager = $row['kodenr'];
            }
        }
    }
    $lager = $lager * 1;
    if (!$sort) {
        $sort = varenr;
    }
    if (!$kontonr) {
        $x++;
    } elseif ($x > 1) {
        print "<td colspan=9><hr></td>";
    }
    if ($find) {
        $query = db_select("select * from varer where lukket != '1' and {$fokus} like '{$find}' order by {$sort}", __FILE__ . " linje " . __LINE__);
    } else {
        $query = db_select("select * from varer where lukket != '1' order by {$sort}", __FILE__ . " linje " . __LINE__);
    }
    while ($row = db_fetch_array($query)) {
        $vare_id = $row['id'];
        if ($konto_id && !in_array($vare_id, $skjul_vare_id) || in_array($vare_id, $vis_vare_id)) {
            $varenr = db_escape_string(trim($row['varenr']));
            $vist = 0;
            $x = 0;
            $query2 = db_select("select * from vare_lev where vare_id = {$row['id']} {$temp}", __FILE__ . " linje " . __LINE__);
            while ($row2 = db_fetch_array($query2)) {
                $x++;
                $y++;
                if ($linjebg != $bgcolor) {
                    $linjebg = $bgcolor;
                    $color = '#000000';
                } else {
                    $linjebg = $bgcolor5;
                    $color = '#000000';
                }
                print "<tr bgcolor=\"{$linjebg}\">";
                print "<td><a href=\"ordre.php?vare_id={$vare_id}&fokus={$fokus}&konto_id={$row2['lev_id']}&id={$id}\">" . htmlentities(stripslashes($varenr), ENT_COMPAT, $charset) . "</a></td>";
                print "<td>{$row['enhed']}<br></td>";
                print "<td> {$row['beskrivelse']}<br></td>";
                $salgspris = dkdecimal($row[salgspris]);
                print "<td align=right> {$salgspris}<br></td>";
                $kostpris = dkdecimal($row2[kostpris]);
                print "<td align=right> {$kostpris}<br></td>";
                if ($lager >= 1) {
                    $q2 = db_select("select * from batch_kob where vare_id={$vare_id} and rest>0 and lager={$lager}", __FILE__ . " linje " . __LINE__);
                    while ($r2 = db_fetch_array($q2)) {
                        $q3 = db_select("select * from reservation where batch_kob_id={$r2['id']}", __FILE__ . " linje " . __LINE__);
                        while ($r3 = db_fetch_array($q3)) {
                            $reserveret = $reserveret + $r3[antal];
                        }
                    }
                    $linjetext = "<span title= 'Reserveret: {$reserveret}'>";
                    if ($r2 = db_fetch_array(db_select("select beholdning from lagerstatus where vare_id={$row['id']} and lager={$lager}", __FILE__ . " linje " . __LINE__))) {
                        print "<td align=right>{$linjetext} {$r2['beholdning']} &nbsp;</span></td>";
                    } else {
                        print "<td align=right>{$linjetext} 0 &nbsp;</span></td>";
                    }
                } else {
                    print "<td align=right> {$row['beholdning']} &nbsp;</td>";
                }
                #			print "<td></td>";
                $levquery = db_select("select kontonr, firmanavn from adresser where id={$row2['lev_id']}", __FILE__ . " linje " . __LINE__);
                if ($levrow = db_fetch_array($levquery)) {
                    print "<td> " . htmlentities(stripslashes($levrow[firmanavn]), ENT_COMPAT, $charset) . "</td>";
                } else {
                    print "<td></td>";
                }
                print "<td align=right><a href=\"../lager/varekort.php?returside=../kreditor/ordre.php&ordre_id={$id}&fokus={$fokus}&id={$row['id']}\">Ret</a></td>";
                print "</tr>\n";
                $vist = 1;
            }
            #			if ($konto_id && $y==1) print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?vare_id=$vare_id&fokus=$fokus&konto_id=$row2[lev_id]&id=$id\">";
        }
        if ($kontonr && !$vist && $row['samlevare'] != 'on' && !in_array($vare_id, $skjul_vare_id)) {
            #		if ((!in_array($row[id], $vare_id))&&($vist==0)&&($row['samlevare']!='on')&&($konto_id)) {
            if ($linjebg != $bgcolor) {
                $linjebg = $bgcolor;
                $color = '#000000';
            } else {
                $linjebg = $bgcolor5;
                $color = '#000000';
            }
            print "<tr bgcolor=\"{$linjebg}\">";
            print "<td><a href=\"ordre.php?vare_id={$vare_id}&fokus={$fokus}&id={$id}\">{$row['varenr']}</a></td>";
            print "<td>{$row['enhed']}<br></td>";
            print "<td> " . htmlentities(stripslashes($row[beskrivelse]), ENT_COMPAT, $charset) . "<br></td>";
            $salgspris = dkdecimal($row[salgspris]);
            print "<td align=right> {$salgspris}<br></td>";
            $kostpris = dkdecimal($row[kostpris]);
            print "<td align=right> {$kostpris}<br></td>";
            print "<td></td><td></td>";
            print "<td align=right><a href=\"../lager/varekort.php?returside=../kreditor/ordre.php&ordre_id={$id}&fokus={$fokus}&id={$row['id']}\">Ret</a></td>";
            print "</tr>\n";
        }
    }
    print "</tbody></table></td></tr></tbody></table>";
    exit;
}