Beispiel #1
0
function levering($id, $hurtigfakt, $genfakt, $webservice)
{
    global $regnaar;
    global $levdate;
    global $lev_nr;
    global $db;
    $fp = fopen("../temp/ordrelev.log", "a");
    transaktion("begin");
    $q = db_select("select lev_nr from batch_salg where ordre_id = {$id} order by lev_nr", __FILE__ . " linje " . __LINE__);
    while ($r = db_fetch_array($q)) {
        if ($lev_nr <= $r['lev_nr']) {
            $lev_nr = $r['lev_nr'] + 1;
        }
    }
    if (!$lev_nr) {
        $lev_nr = 1;
    }
    $query = db_select("select * from ordrer where id = {$id}", __FILE__ . " linje " . __LINE__);
    $row = db_fetch_array($query);
    $ref = $row['ref'];
    $levdate = $row['levdate'];
    $fakturadate = $row['fakturadate'];
    $art = $row['art'];
    $query = db_select("select box1, box2, box3, box4 from grupper where art='RA' and kodenr='{$regnaar}'", __FILE__ . " linje " . __LINE__);
    if ($row = db_fetch_array($query)) {
        #	$year=substr(str_replace(" ","",$row['box2']),-2); #aendret 060308 - grundet mulighed for fakt i aar 2208
        $year = trim($row['box2']);
        $aarstart = str_replace(" ", "", $year . $row['box1']);
        #	$year=substr(str_replace(" ","",$row['box4']),-2);
        $year = trim($row['box4']);
        $aarslut = str_replace(" ", "", $year . $row['box3']);
    }
    if ($hurtigfakt && $fakturadate && $fakturadate != $levdate) {
        db_modify("update ordrer set levdate = fakturadate where id = {$id}", __FILE__ . " linje " . __LINE__);
    }
    $r = db_fetch_array(db_select("select * from ordrer where id = '{$id}'", __FILE__ . " linje " . __LINE__));
    if (!$r['levdate']) {
        print "<BODY onLoad=\"javascript:alert('Leveringsdato SKAL udfyldes')\">";
        #	print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id=$id\">";
        exit;
    } else {
        if ($r['levdate'] < $r['ordredate']) {
            print "<BODY onLoad=\"javascript:alert('Leveringsdato er f&oslash;r ordredato')\">";
            print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
            exit;
        }
        list($year, $month, $day) = split('-', $r['levdate']);
        $year = trim($year);
        $ym = $year . $month;
        if (!$webservice && ($ym < $aarstart || $ym > $aarslut)) {
            print "<BODY onLoad=\"javascript:alert('Leveringsdato uden for regnskabs&aring;r')\">";
            print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
            exit;
        }
        if ($hurtigfakt == 'on' && !$fakturadate) {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=fakturadato.php?id={$id}&returside=levering.php&hurtigfakt=on\">";
            #		include("fakturadato.php");
            #		fakturadato($id);
            exit;
        }
        if ($fejl == 0) {
            $fakturanr = 1;
            $x = 0;
            $query = db_select("select * from ordrelinjer where ordre_id = '{$id}' and samlevare = 'on'", __FILE__ . " linje " . __LINE__);
            while ($row = db_fetch_array($query)) {
                if ($row[leveres] != 0) {
                    samlevare($row[id], $row['vare_id'], $row['leveres']);
                }
            }
            $query = db_select("select * from ordrelinjer where ordre_id = '{$id}'", __FILE__ . " linje " . __LINE__);
            while ($row = db_fetch_array($query)) {
                if ($row[posnr] > 0 && strlen(trim($row[varenr])) > 0) {
                    $x++;
                    $linje_id[$x] = $row[id];
                    $kred_linje_id[$x] = $row[kred_linje_id];
                    $vare_id[$x] = $row['vare_id'];
                    $varenr[$x] = $row['varenr'];
                    $antal[$x] = $row[antal];
                    $leveres[$x] = $row[leveres];
                    $pris[$x] = $row[pris];
                    $rabat[$x] = $row[rabat];
                    $nettopris[$x] = $row[pris] - $row[pris] * $row[rabat] / 100;
                    $serienr[$x] = trim($row['serienr']);
                    $posnr[$x] = $row[posnr];
                    if ($hurtigfakt == 'on') {
                        $leveres[$x] = $antal[$x];
                    }
                }
            }
            $linjeantal = $x;
            for ($x = 1; $x <= $linjeantal; $x++) {
                $tidl_lev = 0;
                $query = db_select("select antal from batch_salg where linje_id = {$linje_id[$x]}", __FILE__ . " linje " . __LINE__);
                while ($row = db_fetch_array($query)) {
                    $tidl_lev = $tidl_lev + $row[antal];
                }
                if ($hurtigfakt == 'on') {
                    $leveres[$x] = $antal[$x] - $tidl_lev;
                }
                if ($antal[$x] > 0 && $antal[$x] < $leveres[$x] + $tidl_lev) {
                    print "<BODY onLoad=\"javascript:alert('Der er sat for meget til levering (pos nr. {$posnr[$x]})')\">";
                    print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
                    exit;
                }
                if ($leveres[$x] > 0 && $serienr[$x]) {
                    $sn_antal[$x] = 0;
                    $query = db_select("select * from serienr where salgslinje_id = '{$linje_id[$x]}' and batch_salg_id=0", __FILE__ . " linje " . __LINE__);
                    while ($row = db_fetch_array($query)) {
                        $sn_antal[$x] = $sn_antal[$x] + 1;
                    }
                    if ($leveres[$x] != $sn_antal[$x]) {
                        print "<BODY onLoad=\"javascript:alert('Der er sat {$leveres[$x]} til levering men valgt {$sn_antal[$x]} serienumre (pos nr: {$posnr[$x]})')\">";
                        print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
                        exit;
                    }
                }
                if ($leveres[$x] < 0 && $serienr[$x]) {
                    $sn_antal[$x] = 0;
                    $query = db_select("select * from serienr where salgslinje_id = {$kred_linje_id[$x]}*-1", __FILE__ . " linje " . __LINE__);
                    while ($row = db_fetch_array($query)) {
                        $sn_antal[$x] = $sn_antal[$x] + 1;
                    }
                    if ($leveres[$x] + $sn_antal[$x] != 0) {
                        $tmp = $leveres[$x] * -1;
                        print "<BODY onLoad=\"javascript:alert('Der er sat {$tmp} til returnering men valgt {$sn_antal[$x]} serienumre (pos nr: {$posnr[$x]})')\">";
                        print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
                        exit;
                    }
                }
                if ($leveres[$x] < 0 && $art == 'DK') {
                    $tidl_lev = 0;
                    $query = db_select("select * from batch_kob where linje_id = '{$linje_id[$x]}' and ordre_id={$id}", __FILE__ . " linje " . __LINE__);
                    while ($row = db_fetch_array($query)) {
                        $tidl_lev = $tidl_lev - $row[antal];
                    }
                    if ($leveres[$x] > $tidl_lev + $antal[$x]) {
                        $leveres[$x] = $antal[$x] - $tidl_lev;
                    }
                }
            }
            for ($x = 1; $x <= $linjeantal; $x++) {
                $sn_start = 0;
                $query = db_select("select * from varer where id='{$vare_id[$x]}'", __FILE__ . " linje " . __LINE__);
                $row = db_fetch_array($query);
                $kostpris[$x] = $row[kostpris];
                $gruppe[$x] = $row[gruppe];
                if ($row[beholdning]) {
                    $beholdning[$x] = $row[beholdning];
                } else {
                    $beholdning[$x] = 0;
                }
                $beholdning[$x] = $beholdning[$x] - $leveres[$x];
                #			if (trim($row['samlevare'])=='on') {
                #				for ($a=1; $a<=$leveres[$x]; $a++) samlevare($vare_id[$x], $linje_id[$x]);
                #			}
                if (!$gruppe[$x]) {
                    print "<BODY onLoad=\"javascript:alert('Vare tilhrer ikke nogen varegruppe - kontroller vare og indstillinger! (pos nr: {$posnr[$x]})')\">";
                    print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id={$id}\">";
                    exit;
                }
                if ($vare_id[$x] && $leveres[$x] != 0) {
                    linjeopdat($id, $gruppe[$x], $linje_id[$x], $beholdning[$x], $vare_id[$x], $leveres[$x], $pris[$x], $nettopris[$x], $rabat[$x], $row['samlevare'], $x, $posnr[$x], $serienr[$x], $kred_linje_id[$x]);
                }
            }
        }
    }
    transaktion("commit");
    return "Levering OK";
}
Beispiel #2
0
    exit;
}
if ($_POST['bilag'] || $_POST['bilag'] == '0') {
    $id = if_isset($_POST['id']);
    $ny_beholdning = if_isset($_POST['ny_beholdning']);
    $bilag = if_isset($_POST['bilag']);
    if (!is_numeric($bilag) || strlen($bilag) > 9) {
        print "<BODY onLoad=\"javascript:alert('Bilagsnummer skal v&aelig;re et positivt tal og m&aring; maks indeholder 9 cifre')\">";
        $fejl = 1;
    }
}
if (!$fejl && $antal >= 1) {
    if ($bilag || $bilag == '0') {
        $bilag = $bilag * 1;
        if ($samlevare && $antal) {
            list($antal, $id, $ny_beholdning) = samlevare($id[0], $ny_beholdning[0]);
            $kontonr = array();
        }
        $r = db_fetch_array(db_select("select * from grupper where kodenr='{$regnaar}' and art='RA'", __FILE__ . " linje " . __LINE__));
        $startaar = $row['box2'] * 1;
        $startaar >= '2015' ? $aut_lager = 'on' : ($aut_lager = NULL);
        transaktion('begin');
        $l = 0;
        $afgangsum = 0;
        for ($x = 0; $x < $antal; $x++) {
            $id[$x] *= 1;
            $ny_beholdning[$x] *= 1;
            if ($r = db_fetch_array(db_select("select varenr,kostpris,beholdning,gruppe from varer where id = '{$id[$x]}'", __FILE__ . " linje " . __LINE__))) {
                $varenr[$x] = db_escape_string($r['varenr']);
                $beholdning[$x] = $r['beholdning'];
                $regulering[$x] = $ny_beholdning[$x] - $beholdning[$x];
Beispiel #3
0
                 $varemomssats[0] = $momssats;
             }
         } elseif (!$momsfri[0]) {
             $varemomssats[0] = $momssats;
         } else {
             $varemomssats[0] = $momssats;
         }
         if ($variant_type[0]) {
             $varianter = explode(chr(9), $variant_type[0]);
             for ($y = 0; $y < count($varianter); $y++) {
                 $r1 = db_fetch_array(db_select("select variant_typer.beskrivelse as vt_besk,varianter.beskrivelse as var_besk from variant_typer,varianter where variant_typer.id = '{$varianter[$y]}' and variant_typer.variant_id=varianter.id", __FILE__ . " linje " . __LINE__));
                 $beskrivelse[0] .= ", " . $r1['var_besk'] . ":" . $r1['vt_besk'];
             }
         }
         if ($samlevare[0]) {
             samlevare($id, $art, $vare_id[0], $antal[0]);
         } else {
             $omlev && $omvare[0] ? $omvbet[0] = 'on' : ($omvbet[0] = '');
             #20150415
             echo "insert into ordrelinjer (ordre_id,posnr,varenr,vare_id,beskrivelse,enhed,antal,pris,rabat,serienr,lev_varenr,momsfri,variant_id,samlevare,omvbet,momssats) values ('{$id}','{$posnr_ny['0']}','{$varenr['0']}','{$vare_id['0']}','{$beskrivelse['0']}','{$enhed['0']}','{$antal['0']}','{$pris['0']}','{$rabat['0']}','{$serienr['0']}','{$lev_varenr['0']}','{$momsfri['0']}','{$variant_id['0']}','{$samlevare['0']}','{$omvbet['0']}',{$varemomssats['0']})<br>";
             db_modify("insert into ordrelinjer (ordre_id,posnr,varenr,vare_id,beskrivelse,enhed,antal,pris,rabat,serienr,lev_varenr,momsfri,variant_id,samlevare,omvbet,momssats) values ('{$id}','{$posnr_ny['0']}','{$varenr['0']}','{$vare_id['0']}','{$beskrivelse['0']}','{$enhed['0']}','{$antal['0']}','{$pris['0']}','{$rabat['0']}','{$serienr['0']}','{$lev_varenr['0']}','{$momsfri['0']}','{$variant_id['0']}','{$samlevare['0']}','{$omvbet['0']}',{$varemomssats['0']})", __FILE__ . " linje " . __LINE__);
         }
     } else {
         $submit = 'Opslag';
         #						$varenr[0]=$varenr[0]."*";
     }
     if ($status == 2) {
         $status = 1;
     }
 } elseif ($beskrivelse[0]) {
     db_modify("insert into ordrelinjer (ordre_id, posnr, beskrivelse) values ('{$id}', '{$posnr_ny['0']}', '{$beskrivelse['0']}')", __FILE__ . " linje " . __LINE__);