$udskriv_til[$x] == 'PBS_BS' || $udskriv_til[$x] == 'PBS_FI' ? $pbs = 'on' : ($pbs = ''); if ($udskriv_til[$x] == 'oioubl') { if ($art == "DO") { $oioubl = 'faktura'; } else { $oioubl = 'kreditnota'; } } else { $oioubl = NULL; } db_modify("update ordrer set firmanavn='{$firmanavn[$x]}',fakturadate='{$fakturadate}',nextfakt='{$nextfakt}',email='{$email[$x]}',udskriv_til='{$udskriv_til[$x]}',mail_fakt='{$mail_fakt}',projekt='{$projekt[$x]}',betalingsbet='{$betalingsbet[$x]}',betalingsdage='{$betalingsdage[$x]}',procenttillag='{$procenttillag[$x]}' where id='{$ordreliste[$x]}'", __FILE__ . " linje " . __LINE__); if ($nextfakt <= $fakturadate) { $fejltekst = "Genfaktureringsdato skal være efter fakturadato ({$firmanavn[$x]})"; } if (!$fejltekst && strstr($udskriv_til[$x], 'PBS')) { $betalingsdate = forfaldsdag($fakturadate, $betalingsbet[$x], $betalingsdage[$x]); list($b_y, $b_m, $b_d) = explode("-", $betalingsdate); $b_m *= 1; $n_m = date("m") + 1; if ($n_m > 12) { $n_m = 1; } # 20121212 if ($b_m != $n_m) { $fejltekst = "Betalingsdato skal være i {$n_m}. måned til PBS ({$firmanavn[$x]})"; } } if (!$fejltekst) { list($year, $month, $day) = explode('-', $fakturadate); $year = trim($year); $ym = $year . $month;
$erh = $r['erh']; } elseif ($r['modt_fi']) { $erh = "ERH351"; } else { $erh = "ERH356"; } if ($erh == "ERH351" || $erh == "ERH357" || $erh == "ERH358" || $erh == "SDCK020") { $modt_konto = $r['modt_fi']; $kort_ref = $r['betal_id']; } elseif ($r['faktnr']) { $kort_ref = "Fakt: " . $r['faktnr']; } if ($r['forfaldsdate']) { $forfaldsdag = str_replace("-", "", dkdato($r['forfaldsdate'])); } else { $forfaldsdag = str_replace("-", "", forfaldsdag($r['transdate'], $r['betalingsbet'], $r['betalingsdage'])); } $belob = dkdecimal($r['amount'] * -1); $valuta = $r['valuta']; if (!$valuta) { $valuta = 'DKK'; } if ($r['betal_id']) { if (substr($r['betal_id'], 0, 1) == "+") { $betal_id = substr($r['betal_id'], 1); list($tmp, $tmp2) = explode("<", $betal_id); if ($tmp == '04' || $tmp == '15') { $erh = 'ERH352'; } elseif ($tmp == '71') { $erh = 'ERH351'; } elseif ($tmp == '73') {
function vis_aabne_poster($dato_fra, $dato_til, $konto_fra, $konto_til, $art) { global $bgcolor; global $bgcolor5; print "<tr><td><table width=100% cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tbody>\n"; print "<tr><td>Kontonr</td><td>Firmanavn</td><td align=right>>90</td><td align=right>60-90</td><td align=right>30-60</td><td align=right>8-30</td><td align=right>0-8</td><td align=right>I alt</td><tr>"; $currentdate = date("Y-m-d"); $fromdate = usdate($dato_fra); $todate = usdate($dato_til); # echo "SS $fromdate $todate KF $konto_fra<br>"; /* # Finder start og s**t paa regnskabsaar for ($x=1; $x<=12; $x++) { if ($maaned_fra==$md[$x]){$maaned_fra=$x;} if ($maaned_til==$md[$x]){$maaned_til=$x;} } $query = db_select("select * from grupper where kodenr='$regnaar' and art='RA'",__FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); # $regnaar=$row[kodenr]; $startmaaned=$row['box1']*1; $startaar=$row['box2']*1; $slutmaaned=$row['box3']*1; $slutaar=$row['box4']*1; $slutdato=31; ## if ($maaned_fra) $startmaaned=$maaned_fra; if ($maaned_til) $slutmaaned=$maaned_til; if (!is_numeric($startmaaned)) { if (strstr($startmaaned," ")) list($tmp,$startmaaned)=explode(" ",$startmaaned); if (!is_numeric($startmaaned)) list ($tmp,$startmaaned)=explode(" ",find_maaned_nr($startmaaned)); } if (!is_numeric($slutmaaned)) { if (strstr($slutmaaned," ")) list($tmp,$slutmaaned)=explode(" ",$slutmaaned); if (!is_numeric($slutmaaned)) list ($tmp,$slutmaaned)=explode(" ",find_maaned_nr($slutmaaned)); } while (!checkdate($slutmaaned,$slutdato,$slutaar)) { $slutdato=$slutdato-1; if ($slutdato<28) break; } # if ($slutmaaned<10){$slutmaaned="0".$slutmaaned;} $regnstart = $startaar. "-" . $startmaaned . "-" . '01'; $regnslut = $slutaar . "-" . $slutmaaned . "-" . $slutdato; */ #$regnslut = "2005-05-04"; print "<form name=aabenpost action=rapport.php method=post>"; print "<tr><td colspan=10><hr></td></tr>\n"; $x = 0; # echo "KF $konto_fra<br>"; if (is_numeric($konto_fra) && is_numeric($konto_til)) { $tekst = "select * from adresser where " . nr_cast('kontonr') . ">='{$konto_fra}' and " . nr_cast('kontonr') . "<='{$konto_til}' and art = 'D' order by " . nr_cast('kontonr') . ""; } elseif ($konto_fra && $konto_fra != '*') { $konto_fra = str_replace("*", "%", $konto_fra); $tmp1 = strtolower($konto_fra); $tmp2 = strtoupper($konto_fra); $tekst = "select * from adresser where (firmanavn like '{$konto_fra}' or lower(firmanavn) like '{$tmp1}' or upper(firmanavn) like '{$tmp2}') and art = 'D' order by firmanavn"; } else { $tekst = "select * from adresser where art = '{$art}' order by firmanavn"; } # echo "tekst $tekst<br>"; $kontonr = array(); $x = 0; $q = db_select("{$tekst}", __FILE__ . " linje " . __LINE__); # if ($konto_fra && $konto_til) $tmp=nr_cast('kontonr').">='$konto_fra' and ".nr_cast('kontonr')."<='$konto_til' and "; # elseif ($konto_fra) $tmp=nr_cast('kontonr').">='$konto_fra' and "; # elseif ($konto_til) $tmp=nr_cast('kontonr')."<='$konto_til'and "; # else $tmp=""; # $q = db_select("select * from adresser where $tmp art = '$art' order by firmanavn",__FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $x++; $konto_id[$x] = $r['id']; print "<input type=hidden name=konto_id[{$x}] value={$konto_id[$x]}>"; $kontonr[$x] = trim($r['kontonr']); $firmanavn[$x] = stripslashes($r['firmanavn']); $addr1[$x] = stripslashes($r['addr1']); $addr2[$x] = stripslashes($r['addr2']); $postnr[$x] = trim($r['postnr']); $bynavn[$x] = stripslashes($r['bynavn']); $email[$x] = trim($r['email']); $betalingsbet[$x] = trim($r['betalingsbet']); $betalingsdage[$x] = trim($r['betalingsdage']); } $kontoantal = $x; $sum = 0; for ($x = 1; $x <= $kontoantal; $x++) { $amount = 0; $udlignet = 1; $rykkerbelob = 0; $forfalden = 0; $forfalden_plus8 = 0; $forfalden_plus30 = 0; $forfalden_plus60 = 0; $forfalden_plus90 = 0; $y = 0; $faktnr = array(); $f = 0; if ($art == 'D') { $tmp = ""; } else { $tmp = "desc"; } # if ($fromdate && $todate) $q=db_select("select * from openpost where transdate>='$fromdate' and transdate<='$todate' and konto_id='$konto_id[$x]'",__FILE__ . " linje " . __LINE__); # elseif ($todate) $q=db_select("select * from openpost where transdate<='$todate' and konto_id='$konto_id[$x]'",__FILE__ . " linje " . __LINE__); # else $q=db_select("select * from openpost where konto_id='$konto_id[$x]'",__FILE__ . " linje " . __LINE__); # if ($fromdate && $todate) $tekst="select * from openpost where transdate>='$fromdate' and transdate<='$todate' and konto_id='$konto_id[$x]' order by faktnr,amount $tmp"; if ($todate) { $tekst = "select * from openpost where transdate<='{$todate}' and konto_id='{$konto_id[$x]}' order by faktnr,amount {$tmp}"; } else { $tekst = "select * from openpost where konto_id='{$konto_id[$x]}' order by faktnr,amount {$tmp}"; } $q = db_select("{$tekst}", __FILE__ . " linje " . __LINE__); # if ($regnaar) $q=db_select("select * from openpost where konto_id=$id[$x] and transdate <= '$regnslut' order by faktnr,amount $tmp",__FILE__ . " linje " . __LINE__); # else $q=db_select("select * from openpost where konto_id=$id[$x] and udlignet!='1' order by faktnr,amount $tmp",__FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { if ($r['udlignet'] != 1 || $r['transdate'] <= $todate && $r['udlign_date'] && $r['udlign_date'] > $todate) { if ($r['faktnr'] && !in_array($r['faktnr'], $faktnr)) { $f++; $faktnr[$f] = $r['faktnr']; $forfaldsdag = $r['forfaldsdate']; } elseif (!$r['faktnr']) { $forfaldsdag = $r['transdate']; } $oid = $r['id']; $transdate = $r['transdate']; if ($r['valuta']) { $valuta = $r['valuta']; } else { $valuta = 'DKK'; } if ($r['valutakurs']) { $valutakurs = $r['valutakurs']; } else { $valutakurs = 100; } $udlignet = "0"; $amount = $r['amount']; if ($amount > 0) { $amount += 0.0001; } else { $amount -= 0.0001; } if (!$forfaldsdag && $art == 'D' && $amount < 0) { $forfaldsdag = $r['transdate']; } elseif (!$forfaldsdag && $art == 'K' && $amount > 0) { $forfaldsdag = $r['transdate']; } elseif (!$forfaldsdag) { $forfaldsdag = $r['forfaldsdate']; } if ($r['faktnr'] && !$r['kladde_id'] && ($amount > 0 || $amount < 0 && strstr($r['beskrivelse'], "Lev. fakt")) && $r['refnr'] > 1) { #rettet 20090715 if ($r2 = db_fetch_array(db_select("select betalingsbet, betalingsdage from ordrer where id='{$r['refnr']}' and fakturanr = '{$r['faktnr']}'", __FILE__ . " linje " . __LINE__))) { $betalingsbet[$x] = trim($r2['betalingsbet']); $betalingsdage[$x] = trim($r2['betalingsdage']); $tmp = usdate(forfaldsdag($transdate, $betalingsbet[$x], $betalingsdage[$x])); if ($tmp != $forfaldsdag) { $forfaldsdag = $tmp; db_modify("update openpost set forfaldsdate = '{$forfaldsdag}' where id='{$oid}'", __FILE__ . " linje " . __LINE__); } } } #elseif () $amount = $amount * $valutakurs / 100; if ($amount > 0) { $amount = round($amount + 0.0001, 2); } else { $amount = round($amount - 0.0001, 2); } ### nedenstående er indført grundet en fejl i 2.0.3 som skrev forkert forfaldsdato i openpost og fjernet i 2.0.8. # $tmp=usdate(forfaldsdag($transdate, $betalingsbet[$x], $betalingsdage[$x])); # if ($tmp && !$forfaldsdag) db_modify("update openpost set forfaldsdate='$tmp' where id='$oid'",__FILE__ . " linje " . __LINE__); # $forfaldsdag=$tmp; ################ $fakt_utid = strtotime($transdate); $forf_utid = strtotime($forfaldsdag); $dage = round(($forf_utid - $fakt_utid) / 86400, 0); $forfaldsdag_plus8 = usdate(forfaldsdag($transdate, 'netto', $dage + 8)); $forfaldsdag_plus30 = usdate(forfaldsdag($transdate, 'netto', $dage + 30)); $forfaldsdag_plus60 = usdate(forfaldsdag($transdate, 'netto', $dage + 60)); $forfaldsdag_plus90 = usdate(forfaldsdag($transdate, 'netto', $dage + 90)); if ($forfaldsdag < $currentdate) { $rykkerbelob = $rykkerbelob + $amount; } if ($forfaldsdag < $currentdate && $forfaldsdag_plus8 > $currentdate) { $forfalden = $forfalden + $amount; } if ($forfaldsdag_plus8 <= $currentdate && $forfaldsdag_plus30 > $currentdate) { $forfalden_plus8 = $forfalden_plus8 + $amount; } if ($forfaldsdag_plus30 <= $currentdate && $forfaldsdag_plus60 > $currentdate) { $forfalden_plus30 = $forfalden_plus30 + $amount; } if ($forfaldsdag_plus60 <= $currentdate && $forfaldsdag_plus90 > $currentdate) { $forfalden_plus60 = $forfalden_plus60 + $amount; } if ($forfaldsdag_plus90 <= $currentdate) { $forfalden_plus90 = $forfalden_plus90 + $amount; } $y = $y + $amount; } } $y > 0 ? $y = round($y + 0.0001, 2) : ($y = round($y - 0.0001, 2)); if ($y > 0.01 || $udlignet == "0") { if ($linjebg != $bgcolor) { $linjebg = $bgcolor; $color = '#000000'; } elseif ($linjebg != $bgcolor5) { $linjebg = $bgcolor5; $color = '#000000'; } $forfaldsum = $forfaldsum + $forfalden; $forfaldsum_plus8 = $forfaldsum_plus8 + $forfalden_plus8; $forfaldsum_plus30 = $forfaldsum_plus30 + $forfalden_plus30; $forfaldsum_plus60 = $forfaldsum_plus60 + $forfalden_plus60; $forfaldsum_plus90 = $forfaldsum_plus90 + $forfalden_plus90; $sum = $sum + $y; print "<tr bgcolor=\"{$linjebg}\">"; if ($popup) { print "<td onClick=\"window.open('rapport.php?rapportart=kontokort&dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$kontonr[$x]}&konto_til={$kontonr[$x]}&submit=ok','kreditorrapport','{$jsvars}')\" onMouseOver=\"this.style.cursor = 'pointer'\"><a>"; } else { print "<td><a href=rapport.php?rapportart=kontokort&kilde=openpost&kto_fra={$konto_fra}&kilde_kto_til={$konto_til}&dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$kontonr[$x]}&konto_til={$kontonr[$x]}&submit=ok>"; } print "<span title='Klik for detaljer' style=\"text-decoration: underline;\">{$kontonr[$x]}</span></a></td>"; print "<td>{$firmanavn[$x]}</td>"; /* if ($forfalden_plus90 != 0) $color="rgb(255, 0, 0)"; else $color="rgb(0, 0, 0)"; $tmp=dkdecimal($forfalden_plus90); print "<td align=right><span style='color: $color;'>$tmp</span></td>"; if ($forfalden_plus60 != 0) $color="rgb(255, 0, 0)"; else $color="rgb(0, 0, 0)"; $tmp=dkdecimal($forfalden_plus60); print "<td align=right><span style='color: $color;'>$tmp</span></td>"; if ($forfalden_plus60 != 0) $color="rgb(255, 0, 0)"; else $color="rgb(0, 0, 0)"; $tmp=dkdecimal($forfalden_plus30); print "<td align=right><span style='color: $color;'>$tmp</span></td>"; if ($forfalden_plus30 != 0) $color="rgb(255, 0, 0)"; else $color="rgb(0, 0, 0)"; $tmp=dkdecimal($forfalden_plus8); print "<td align=right><span style='color: $color;'>$tmp</span></td>"; if ($forfalden != 0) $color="rgb(255, 0, 0)"; else $color="rgb(0, 0, 0)"; $tmp=dkdecimal($forfalden); */ if ($art == 'D' && $forfalden_plus90 > 0 || $art == 'K' && $forfalden_plus90 < 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfalden_plus90); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($art == 'D' && $forfalden_plus60 > 0 || $art == 'K' && $forfalden_plus60 < 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfalden_plus60); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($art == 'D' && $forfalden_plus30 > 0 || $art == 'K' && $forfalden_plus30 < 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfalden_plus30); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($art == 'D' && $forfalden_plus8 > 0 || $art == 'K' && $forfalden_plus8 < 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfalden_plus8); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($art == 'D' && $forfalden > 0 || $art == 'K' && $forfalden < 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfalden); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; $tmp = dkdecimal($y); if (abs($y) < 0.01) { print "<td align=right title=\"Klik her for at udligne åbne poster\"><a href=\"rapport.php?submit=ok&rapportart=openpost&dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&udlign={$konto_id[$x]}\">{$tmp}</a></td>"; } else { print "<td align=right>{$tmp}</td>"; } if ($kontoudtog[$x] == 'on' && $art == "D") { print "<td align=center><input type=checkbox name=kontoudtog[{$x}] checked>"; } elseif ($art == "D") { print "<td align=center><input type=checkbox name=kontoudtog[{$x}]>"; } print "</tr>\n"; } print "<input type=hidden name=rykkerbelob[{$x}] value={$rykkerbelob}>"; } print "<tr><td colspan=10><hr></td></tr>\n"; print "<tr><td><br></td><td>I alt</td>"; if ($forfaldsum_plus90 != 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfaldsum_plus90); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($forfaldsum_plus60 != 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfaldsum_plus60); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($forfaldsum_plus60 != 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfaldsum_plus30); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($forfaldsum_plus30 != 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfaldsum_plus8); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; if ($forfaldsum != 0) { $color = "rgb(255, 0, 0)"; } else { $color = "rgb(0, 0, 0)"; } $tmp = dkdecimal($forfaldsum); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; $color = "rgb(0, 0, 0)"; $tmp = dkdecimal($sum); print "<td align=right><span style='color: {$color};'>{$tmp}</span></td>"; print "<input type=hidden name=rapportart value=\"openpost\">"; print "<input type=hidden name=regnaar value={$regnaar}>"; print "<input type=hidden name=dato_fra value={$dato_fra}>"; print "<input type=hidden name=dato_til value={$dato_til}>"; print "<input type=hidden name=konto_fra value={$konto_fra}>"; print "<input type=hidden name=konto_til value={$konto_til}>"; print "<input type=hidden name=kontoantal value={$kontoantal}>"; if ($art == 'D') { print "<tr><td colspan=10 align=center><span title=\"Klik her for at maile kontoudtog til de modtagere som er afmærket herover\"><input type=submit value=\"Mail kontoudtog\" name=\"submit\"></span> \n\t\t<span title='Klik her for at oprette rykker til de som er afmærkede herover'><input type=submit value=\"Opret rykker\" name=\"submit\"></span> \n\t\t<span onmouseover=\"return overlib('" . findtekst(242, $sprog_id) . "', WIDTH=800);\" onmouseout=\"return nd();\"><input type=submit value=\"Ryk alle\" name=\"submit\"></span></td></tr>\n"; } print "</form>\n"; print "<tr><td colspan=10><hr></td></tr>\n"; print "</tbody></table>"; }
function inset_ordrer($antal_ordrer, $leverance_id, $dkdd, $ordre_id, $cvrnr, $bank_reg, $bank_konto, $pbs_nr, $ny_pbs_aftale, $kontonr) { global $id; global $lnr; global $afslut; global $linje; global $linjeoid; global $delsystem; global $charset; global $lev_pbs; global $debitorgruppe; include "../includes/forfaldsdag.php"; $r042sum = 0; $r022lin = 0; $r052lin = 0; $lnr++; $linje[$lnr] = "BS002" . $cvrnr[0] . $delsystem . "0601" . $leverance_id . filler(19, " ") . $dkdd . "\n"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $lnr++; $linje[$lnr] = "BS012" . $pbs_nr[0] . "0112" . filler(5, " ") . $debitorgruppe . filler(15, "0") . filler(4, " ") . "00000000" . $bank_reg[0] . $bank_konto[0] . "\n"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } for ($x = 1; $x <= $antal_ordrer; $x++) { $r = db_fetch_array(db_select("select * from ordrer where id='{$ordre_id[$x]}'", __FILE__ . " linje " . __LINE__)); $fakturanr = $r['fakturanr']; $kontonr = $r['kontonr']; $firmanavn = $r['firmanavn']; $adresse = $r['addr1']; if ($r['addr2']) { $adresse = $adresse . ", " . $r['addr2']; } $postnr = $r['postnr']; $ean = $r['ean']; $institution = $r['institution']; $sum = $r['sum']; $moms = $r['moms']; $belob = round(($r['sum'] + $r['moms']) * 100, 0); $r042sum = $r042sum + $belob; $fakturadate = $r['fakturadate']; $betalingsbet = $r['betalingsbet']; $betalingsdage = $r['betalingsdage']; $udskriv_til = $r['udskriv_til']; # tilfoejet 20.03.2011 while (strlen($kontonr) < 15) { $kontonr = "0" . $kontonr; } # 20140122 Denne + næste 3 linjer flyttet over nedenstående else while (strlen($pbs_nr[$x]) < 9) { $pbs_nr[$x] = "0" . $pbs_nr[$x]; } list($dd, $mm, $yy) = explode("-", forfaldsdag($fakturadate, $betalingsbet, $betalingsdage)); $forfaldsdag = $dd . $mm . $yy; if ($lev_pbs == 'B') { $firmanavn = ''; $adresse = ''; $postnr = ''; $ean = ''; $institution = ''; } else { #else indsat 20140121 if ($charset == "UTF-8") { $firmanavn = utf8_decode($firmanavn); $adresse = utf8_decode($adresse); $institution = utf8_decode($institution); } if ($udskriv_til == 'PBS_FI') { $pbs_nr[$x] = '000000000'; } # tilfoejet 20.03.2011 # rettet til '000000000' 20140207 $r022lin++; $lnr++; $linje[$lnr] = "BS022" . $pbs_nr[0] . "0240" . "00001" . $debitorgruppe . $kontonr . $pbs_nr[$x] . addslashes($firmanavn) . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } if ($ean) { $lnr++; $r022lin++; $linje[$lnr] = "BS022" . $pbs_nr[0] . "0240" . "00002" . $debitorgruppe . $kontonr . $pbs_nr[$x] . $ean . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $linjenr = "00003"; } else { $linjenr = "00002"; } $lnr++; $r022lin++; $linje[$lnr] = "BS022" . $pbs_nr[0] . "0240" . $linjenr . $debitorgruppe . $kontonr . $pbs_nr[$x] . $adresse . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $r022lin++; while (strlen($postnr) < 4) { $postnr = "0" . $postnr; } $lnr++; $linje[$lnr] = "BS022" . $pbs_nr[0] . "0240" . "00009" . $debitorgruppe . $kontonr . $pbs_nr[$x] . filler(15, " ") . $postnr . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } } if ($belob > 0) { $felt10 = "1"; } elseif ($belob < 0) { $felt10 = "2"; $belob = $belob * -1; } else { $felt10 = "0"; } while (strlen($belob) < 13) { $belob = "0" . $belob; } $lnr++; $linje[$lnr] = "BS042" . $pbs_nr[0] . "0280" . "00000" . $debitorgruppe . $kontonr . $pbs_nr[$x] . $forfaldsdag . $felt10 . $belob . filler(30, " ") . "00" . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $r052lin++; $recordnr = "00001"; $beskrivelse = "Fakturadato " . dkdato($fakturadate) . " Fakturanr: {$fakturanr} "; if ($charset == "UTF-8") { $belob = utf8_decode($belob); $beskrivelse = utf8_decode($beskrivelse); } while (strlen($beskrivelse) < 65) { $beskrivelse = $beskrivelse . " "; } $lnr++; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes($beskrivelse) . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $r052lin++; $recordnr = "00001"; $beskrivelse = "Beskrivelse"; $antal = "Antal"; $pris = "Pris"; $belob = "Beløb"; if ($charset == "UTF-8") { $belob = utf8_decode($belob); $beskrivelse = utf8_decode($beskrivelse); } while (strlen($recordnr) < 5) { $recordnr = "0" . $recordnr; } while (strlen($beskrivelse) < 35) { $beskrivelse = $beskrivelse . " "; } while (strlen($antal) < 5) { $antal = " " . $antal; } while (strlen($pris) < 10) { $pris = " " . $pris; } while (strlen($belob) < 10) { $belob = " " . $belob; } $lnr++; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes($beskrivelse) . $antal . $pris . $belob . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $y = 0; $q = db_select("select * from ordrelinjer where ordre_id='{$ordre_id[$x]}' order by posnr", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $y++; $r052lin++; $beskrivelse = var2str($r['beskrivelse'], $ordre_id[$x]); $antal = $r['antal'] * 1; $pris = dkdecimal($r['pris']); $belob = dkdecimal($r['pris'] * $r['antal']); $recordnr++; if ($charset == "UTF-8") { $beskrivelse = utf8_decode($beskrivelse); } while (strlen($recordnr) < 5) { $recordnr = "0" . $recordnr; } if (strlen($beskrivelse) > 35) { $beskrivelse = substr($beskrivelse, 0, 35); } while (strlen($beskrivelse) < 35) { $beskrivelse = $beskrivelse . " "; } while (strlen($antal) < 5) { $antal = " " . $antal; } while (strlen($pris) < 10) { $pris = " " . $pris; } while (strlen($belob) < 10) { $belob = " " . $belob; } $lnr++; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes(addslashes($beskrivelse)) . $antal . $pris . $belob . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } } if ($sum) { $r052lin++; $recordnr++; $beskrivelse = "Netto Beløb"; $dksum = dkdecimal($sum); if ($charset == "UTF-8") { $beskrivelse = utf8_decode($beskrivelse); } while (strlen($recordnr) < 5) { $recordnr = "0" . $recordnr; } while (strlen($beskrivelse) < 50) { $beskrivelse = $beskrivelse . " "; } while (strlen($dksum) < 10) { $dksum = " " . $dksum; } $lnr++; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes($beskrivelse) . $dksum . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } } if ($moms) { $r052lin++; $recordnr++; $beskrivelse = "Moms"; $dkmoms = dkdecimal($moms); if ($charset == "UTF-8") { $beskrivelse = utf8_decode($beskrivelse); } while (strlen($recordnr) < 5) { $recordnr = "0" . $recordnr; } while (strlen($beskrivelse) < 50) { $beskrivelse = $beskrivelse . " "; } while (strlen($dkmoms) < 10) { $dkmoms = " " . $dkmoms; } $lnr++; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes($beskrivelse) . $dkmoms . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } } if ($sum || $moms) { $r052lin++; $recordnr++; $beskrivelse = "Total Beløb"; $ialt = dkdecimal($sum + $moms); if ($charset == "UTF-8") { $beskrivelse = utf8_decode($beskrivelse); } while (strlen($recordnr) < 5) { $recordnr = "0" . $recordnr; } while (strlen($beskrivelse) < 50) { $beskrivelse = $beskrivelse . " "; } while (strlen($ialt) < 10) { $ialt = " " . $ialt; } $lnr++; $linjeoid[$lnr] = "{$ordre_id[$x]}"; $linje[$lnr] = "BS052" . $pbs_nr[0] . "0241" . $recordnr . $debitorgruppe . $kontonr . $pbs_nr[$x] . " " . addslashes($beskrivelse) . $ialt . "\n"; if ($afslut) { if ($charset == "UTF-8") { $linje[$lnr] = utf8_encode($linje[$lnr]); } db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } } } while (strlen($antal_ordrer) < 11) { $antal_ordrer = "0" . $antal_ordrer; } while (strlen($r042sum) < 15) { $r042sum = "0" . $r042sum; } while (strlen($r022lin) < 11) { $r022lin = "0" . $r022lin; } while (strlen($r052lin) < 11) { $r052lin = "0" . $r052lin; } $lnr++; $linje[$lnr] = "BS092" . $pbs_nr[0] . "0112" . filler(5, "0") . $debitorgruppe . filler(4, " ") . $antal_ordrer . $r042sum . $r052lin . filler(15, " ") . $r022lin . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } $lnr++; # $linje[$lnr]="BS992".$cvrnr[0]."BS10601"."00000000001".$antal_ordrer.$r042sum.$r052lin.filler(15,"0").$r022lin.filler(34,"0")."\n"; $linje[$lnr] = "BS992" . $cvrnr[0] . $delsystem . "0601" . "00000000001" . $antal_ordrer . $r042sum . $r052lin . filler(15, "0") . $r022lin . filler(34, "0") . "\n"; $linjeoid[$lnr] = "{$ordre_id[$x]}"; if ($afslut) { db_modify("insert into pbs_linjer (liste_id,linje) values ('{$id}','{$linje[$lnr]}')", __FILE__ . " linje " . __LINE__); } }
function oioubldoc_faktura($l_ordreid = "", $l_doktype = "faktura", $l_testdoc = "") { global $db_encode; include "../includes/forfaldsdag.php"; if ($l_testdoc) { $l_testdoc = "TEST"; } if (!$l_ordreid) { return ""; } if (strtolower($l_doktype) == "faktura") { # Faktura $l_doctype = "Invoice"; $l2_doctype = "Invoiced"; $l_ptype = "PIE"; } else { # Kreditnota $l_doctype = "CreditNote"; $l2_doctype = "Credited"; $l_ptype = "PCM"; } # $l_doctype = "Invoice"; # Ogsaa selvom det er en kreditnota # $l_retur=oioubl_top($l_doctype, $l_ptype, $l_testdoc, $l_ordreid); $query = db_select("select * from ordrer where id = {$l_ordreid}", __FILE__ . " linje " . __LINE__); $r_faktura = db_fetch_array($query); if ($db_encode != "UTF8") { $firmanavn = utf8_encode($r_faktura['firmanavn']); $addr_1 = utf8_encode($r_faktura['addr1']); $addr_2 = utf8_encode($r_faktura['addr2']); $postnr = utf8_encode($r_faktura['postnr']); $bynavn = utf8_encode($r_faktura['bynavn']); $land = utf8_encode($r_faktura['land']); $kontakt = utf8_encode($r_faktura['kontakt']); $bank_navn = utf8_encode($r_faktura['bank_navn']); $kundeordnr = utf8_encode($r_faktura['kundeordnr']); $cvrnr = utf8_encode($r_faktura['cvrnr']); $tlf = utf8_encode($r_faktura['tlf']); $email = utf8_encode($r_faktura['email']); $kontonr = utf8_encode($r_faktura['kontonr']); } else { $firmanavn = $r_faktura['firmanavn']; $addr_1 = $r_faktura['addr1']; $addr_2 = $r_faktura['addr2']; $postnr = $r_faktura['postnr']; $bynavn = $r_faktura['bynavn']; $land = $r_faktura['land']; $kontakt = $r_faktura['kontakt']; $bank_navn = $r_faktura['bank_navn']; $kundeordnr = $r_faktura['kundeordnr']; $cvrnr = $r_faktura['cvrnr']; $tlf = $r_faktura['tlf']; $email = $r_faktura['email']; $kontonr = $r_faktura['kontonr']; } $firmanavn = htmlspecialchars($firmanavn, ENT_QUOTES); $addr_1 = htmlspecialchars($addr_1, ENT_QUOTES); $addr_2 = htmlspecialchars($addr_2, ENT_QUOTES); $postnr = htmlspecialchars($postnr, ENT_QUOTES); $bynavn = htmlspecialchars($bynavn, ENT_QUOTES); $land = htmlspecialchars($land, ENT_QUOTES); $kontakt = htmlspecialchars($kontakt, ENT_QUOTES); $bank_navn = htmlspecialchars($bank_navn, ENT_QUOTES); $kundeordnr = htmlspecialchars($kundeordnr, ENT_QUOTES); $cvrnr = htmlspecialchars(str_replace(" ", "", $cvrnr), ENT_QUOTES); $tlf = htmlspecialchars($tlf, ENT_QUOTES); $email = htmlspecialchars($email, ENT_QUOTES); if (!$kundeordnr) { $kundeordnr = '0'; } # phr 20090803 while (strlen($cvrnr) < 8) { $cvrnr = "0" . $cvrnr; } $l_momsbeloeb = afrund(abs($r_faktura['moms']), 2); $l_momssats = $r_faktura['momssats'] * 1; $l_sumbeloeb = afrund(abs($r_faktura['sum']), 2); $l_momspligtigt = 100 * $l_momsbeloeb / $l_momssats; $l_momsfrit = $l_sumbeloeb - $l_momspligtigt; if ($l_momsfrit < 0.02) { #20150618 $l_momsfrit = 0; $l_momspligtigt = $l_sumbeloeb; } $l_forfaldsdate = usdate(forfaldsdag($r_faktura['fakturadate'], $r_faktura['betalingsbet'], $r_faktura['betalingsdage'])); # $l_retur.="\t<com:ID>".$r_faktura['fakturanr']."</com:ID>\n"; # $l_retur.="\t<com:IssueDate>".$r_faktura['fakturadate']."</com:IssueDate>\n"; # $l_retur.="\t<com:TypeCode>".$l_ptype."</com:TypeCode>\n"; if ($r_faktura['valuta']) { $l_valutakode = $r_faktura['valuta']; $l_valutakurs = $r_faktura['valutakurs']; } else { $l_valutakode = "DKK"; } if ($r_faktura['valutakurs']) { $l_valutakurs = $r_faktura['valutakurs']; } else { $l_valutakurs = 100; } $query = db_select("select * from adresser where art='S'", __FILE__ . " linje " . __LINE__); $r_egen = db_fetch_array($query); if ($db_encode != "UTF8") { $egen_firmanavn = utf8_encode($r_egen['firmanavn']); $egen_addr_1 = utf8_encode($r_egen['addr1']); $egen_addr_2 = utf8_encode($r_egen['addr2']); $egen_postnr = utf8_encode($r_egen['postnr']); $egen_bynavn = utf8_encode($r_egen['bynavn']); $egen_land = utf8_encode($r_egen['land']); $egen_kontakt = utf8_encode($r_egen['kontakt']); $egen_bank_navn = utf8_encode($r_egen['bank_navn']); $egen_tlf = utf8_encode($r_egen['tlf']); } else { $egen_firmanavn = $r_egen['firmanavn']; $egen_addr_1 = $r_egen['addr1']; $egen_addr_2 = $r_egen['addr2']; $egen_postnr = $r_egen['postnr']; $egen_bynavn = $r_egen['bynavn']; $egen_land = $r_egen['land']; $egen_kontakt = $r_egen['kontakt']; $egen_bank_navn = $r_egen['bank_navn']; $egen_tlf = $r_egen['tlf']; } $egen_firmanavn = htmlspecialchars($egen_firmanavn, ENT_QUOTES); $egen_addr_1 = htmlspecialchars($egen_addr_1, ENT_QUOTES); $egen_addr_2 = htmlspecialchars($egen_addr_2, ENT_QUOTES); $egen_postnr = htmlspecialchars($egen_postnr, ENT_QUOTES); $egen_bynavn = htmlspecialchars($egen_bynavn, ENT_QUOTES); $egen_land = htmlspecialchars($egen_land, ENT_QUOTES); $egen_kontakt = htmlspecialchars($egen_kontakt, ENT_QUOTES); $egen_bank_navn = htmlspecialchars($egen_bank_navn, ENT_QUOTES); $egen_tlf = htmlspecialchars($egen_tlf, ENT_QUOTES); $egen_cvrnr = str_replace(" ", "", $r_egen['cvrnr']); $l_retur .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $l_retur .= "<" . $l_doctype . " xsi:schemaLocation=\"urn:oasis:names:specification:ubl:schema:xsd:" . $l_doctype . "-2 UBL-" . $l_doctype . "-2.0.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:oasis:names:specification:ubl:schema:xsd:" . $l_doctype . "-2\" xmlns:cac=\"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2\" xmlns:cbc=\"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2\" xmlns:ccts=\"urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2\" xmlns:sdt=\"urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2\" xmlns:udt=\"urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2\">\n"; $l_retur .= "<cbc:UBLVersionID>2.0</cbc:UBLVersionID>\n"; $l_retur .= "<cbc:CustomizationID>OIOUBL-2.01</cbc:CustomizationID>\n"; # $l_retur.="<cbc:ProfileID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:profileid-1.1\">Procurement-BilSim-1.0</cbc:ProfileID>\n"; 20210725 $l_retur .= "<cbc:ProfileID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:profileid-1.2\">urn:www.nesubl.eu:profiles:profile5:ver2.0</cbc:ProfileID>\n"; $l_retur .= "<cbc:ID>" . $r_faktura['fakturanr'] . "</cbc:ID>\n"; $l_retur .= "<cbc:CopyIndicator>false</cbc:CopyIndicator>\n"; $l_retur .= "<cbc:IssueDate>" . $r_faktura['fakturadate'] . "</cbc:IssueDate>\n"; #20160208 if ($l_doctype == "Invoice") { $l_retur .= "<cbc:" . $l_doctype . "TypeCode listAgencyID=\"320\" listID=\"urn:oioubl:codelist:invoicetypecode-1.1\">380</cbc:" . $l_doctype . "TypeCode>\n"; } # $l_retur.="<cbc:Note>".$l_doctype." note</cbc:Note>\n"; $l_retur .= "<cbc:DocumentCurrencyCode>{$l_valutakode}</cbc:DocumentCurrencyCode>\n"; $l_retur .= "<cbc:AccountingCost>{$kontonr}</cbc:AccountingCost>\n"; $l_retur .= "<cac:OrderReference>\n"; $l_retur .= "<cbc:ID>{$kundeordnr}</cbc:ID>\n"; $l_retur .= "<cbc:SalesOrderID>{$l_ordreid}</cbc:SalesOrderID>\n"; $l_retur .= "<cbc:IssueDate>" . $r_faktura['ordredate'] . "</cbc:IssueDate>\n"; $l_retur .= "</cac:OrderReference>\n"; $l_retur .= "<cac:AccountingSupplierParty>\n"; $l_retur .= "<cac:Party>\n"; $l_retur .= "<cbc:EndpointID schemeID=\"DK:CVR\">DK" . $egen_cvrnr . "</cbc:EndpointID>\n"; $l_retur .= "<cac:PartyIdentification>\n"; $l_retur .= "<cbc:ID schemeID=\"DK:CVR\">DK" . $egen_cvrnr . "</cbc:ID>\n"; $l_retur .= "</cac:PartyIdentification>\n"; $l_retur .= "<cac:PartyName>\n"; $l_retur .= "<cbc:Name>" . $egen_firmanavn . "</cbc:Name>\n"; $l_retur .= "</cac:PartyName>\n"; $l_retur .= "<cac:PostalAddress>\n"; $l_retur .= "<cbc:AddressFormatCode listAgencyID=\"320\" listID=\"urn:oioubl:codelist:addressformatcode-1.1\">StructuredDK</cbc:AddressFormatCode>\n"; $l_retur .= "<cbc:StreetName>" . oioubl_vej($egen_addr_1, "vejnavn") . "</cbc:StreetName>\n"; $l_retur .= "<cbc:BuildingNumber>" . oioubl_vej($egen_addr_1, "husnummer") . "</cbc:BuildingNumber>\n"; $l_retur .= "<cbc:CityName>" . $egen_bynavn . "</cbc:CityName>\n"; $l_retur .= "<cbc:PostalZone>" . $egen_postnr . "</cbc:PostalZone>\n"; $l_retur .= "<cac:Country>\n"; $l_retur .= "<cbc:IdentificationCode>" . oioubl_landekode($egen_land) . "</cbc:IdentificationCode>\n"; $l_retur .= "</cac:Country>\n"; $l_retur .= "</cac:PostalAddress>\n"; $l_retur .= "<cac:PartyTaxScheme>\n"; $l_retur .= "<cbc:CompanyID schemeID=\"DK:SE\">DK" . $egen_cvrnr . "</cbc:CompanyID>\n"; $l_retur .= "<cac:TaxScheme>\n"; $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxschemeid-1.1\">63</cbc:ID>\n"; $l_retur .= "<cbc:Name>Moms</cbc:Name>\n"; $l_retur .= "</cac:TaxScheme>\n"; $l_retur .= "</cac:PartyTaxScheme>\n"; $l_retur .= "<cac:PartyLegalEntity>\n"; $l_retur .= "<cbc:RegistrationName>" . $egen_firmanavn . "</cbc:RegistrationName>\n"; $l_retur .= "<cbc:CompanyID schemeID=\"DK:CVR\">DK" . $egen_cvrnr . "</cbc:CompanyID>\n"; $l_retur .= "</cac:PartyLegalEntity>\n"; $l_retur .= "</cac:Party>\n"; $l_retur .= "</cac:AccountingSupplierParty>\n"; $l_retur .= "<cac:AccountingCustomerParty>\n"; $l_retur .= "<cac:Party>\n"; $l_retur .= "<cbc:EndpointID schemeAgencyID=\"9\" schemeID=\"GLN\">" . $r_faktura['ean'] . "</cbc:EndpointID>\n"; $l_retur .= "<cac:PartyIdentification>\n"; $l_retur .= "<cbc:ID schemeID=\"DK:CVR\">DK" . $cvrnr . "</cbc:ID>\n"; $l_retur .= "</cac:PartyIdentification>\n"; $l_retur .= "<cac:PartyName>\n"; $l_retur .= "<cbc:Name>" . $firmanavn . "</cbc:Name>\n"; $l_retur .= "</cac:PartyName>\n"; $l_retur .= "<cac:PostalAddress>\n"; $l_retur .= "<cbc:AddressFormatCode listAgencyID=\"320\" listID=\"urn:oioubl:codelist:addressformatcode-1.1\">StructuredDK</cbc:AddressFormatCode>\n"; if (oioubl_vej($addr_1, "vejnavn")) { $l_retur .= "<cbc:StreetName>" . oioubl_vej($addr_1, "vejnavn") . "</cbc:StreetName>\n"; } elseif (oioubl_vej($addr_2, "vejnavn")) { $l_retur .= "<cbc:StreetName>" . oioubl_vej($addr_2, "vejnavn") . "</cbc:StreetName>\n"; } else { $l_retur .= "<cbc:StreetName>?</cbc:StreetName>\n"; } if (oioubl_vej($addr_1, "husnummer")) { $l_retur .= "<cbc:BuildingNumber>" . oioubl_vej($addr_1, "husnummer") . "</cbc:BuildingNumber>\n"; } elseif (!oioubl_vej($addr_1, "husnummer") && oioubl_vej($addr_2, "husnummer")) { $l_retur .= "<cbc:BuildingNumber>" . oioubl_vej($addr_2, "husnummer") . "</cbc:BuildingNumber>\n"; } else { $l_retur .= "<cbc:BuildingNumber>0</cbc:BuildingNumber>\n"; } $l_retur .= "<cbc:CityName>" . $bynavn . "</cbc:CityName>\n"; $l_retur .= "<cbc:PostalZone>" . $postnr . "</cbc:PostalZone>\n"; $l_retur .= "<cac:Country>\n"; $l_retur .= "<cbc:IdentificationCode>" . oioubl_landekode($land) . "</cbc:IdentificationCode>\n"; $l_retur .= "</cac:Country>\n"; $l_retur .= "</cac:PostalAddress>\n"; $l_retur .= "<cac:PartyLegalEntity>\n"; $l_retur .= "<cbc:RegistrationName>" . $firmanavn . "</cbc:RegistrationName>\n"; $l_retur .= "<cbc:CompanyID schemeID=\"DK:CVR\">DK" . $cvrnr . "</cbc:CompanyID>\n"; $l_retur .= "</cac:PartyLegalEntity>\n"; $l_retur .= "<cac:Contact>\n"; $l_retur .= oioubl_kontaktinfo($kontakt, "BuyerContact"); # $l_retur.="<cbc:Telephone>".$tlf."</cbc:Telephone>\n"; # $l_retur.="<cbc:ElectronicMail>".$email."</cbc:ElectronicMail>\n"; $l_retur .= "</cac:Contact>\n"; $l_retur .= "</cac:Party>\n"; $l_retur .= "</cac:AccountingCustomerParty>\n"; if ($l_doctype == "Invoice") { $l_retur .= "<cac:Delivery>\n"; $l_retur .= "<cbc:ActualDeliveryDate>" . $r_faktura['ordredate'] . "</cbc:ActualDeliveryDate>\n"; $l_retur .= "</cac:Delivery>\n"; $l_retur .= "<cac:PaymentMeans>\n"; $l_retur .= "<cbc:ID>1</cbc:ID>\n"; $l_retur .= "<cbc:PaymentMeansCode>42</cbc:PaymentMeansCode>\n"; $l_retur .= "<cbc:PaymentDueDate>{$l_forfaldsdate}</cbc:PaymentDueDate>\n"; $l_retur .= "<cbc:PaymentChannelCode listAgencyID=\"320\" listID=\"urn:oioubl:codelist:paymentchannelcode-1.1\">DK:BANK</cbc:PaymentChannelCode>\n"; $l_retur .= "<cac:PayeeFinancialAccount>\n"; $l_retur .= "<cbc:ID>" . str_replace(" ", "", $r_egen['bank_konto']) . "</cbc:ID>\n"; $l_retur .= "<cac:FinancialInstitutionBranch>\n"; $l_retur .= "<cbc:ID>" . $r_egen['bank_reg'] . "</cbc:ID>\n"; $l_retur .= "</cac:FinancialInstitutionBranch>\n"; $l_retur .= "</cac:PayeeFinancialAccount>\n"; $l_retur .= "</cac:PaymentMeans>\n"; $l_retur .= "<cac:PaymentTerms>\n"; $l_retur .= "<cbc:ID>1</cbc:ID>\n"; $l_retur .= "<cbc:PaymentMeansID>1</cbc:PaymentMeansID>\n"; $l_retur .= "<cbc:Amount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb + $l_momsbeloeb) . "</cbc:Amount>\n"; $l_retur .= "</cac:PaymentTerms>\n"; } $l_retur .= "<cac:TaxTotal>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_momsbeloeb) . "</cbc:TaxAmount>\n"; $l_retur .= "<cac:TaxSubtotal>\n"; $l_retur .= "<cbc:TaxableAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_momspligtigt) . "</cbc:TaxableAmount>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_momsbeloeb) . "</cbc:TaxAmount>\n"; $l_retur .= "<cac:TaxCategory>\n"; $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxcategoryid-1.1\">StandardRated</cbc:ID>\n"; $l_retur .= "<cbc:Percent>" . $l_momssats . "</cbc:Percent>\n"; $l_retur .= "<cac:TaxScheme>\n"; $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxschemeid-1.1\">63</cbc:ID>\n"; $l_retur .= "<cbc:Name>Moms</cbc:Name>\n"; $l_retur .= "</cac:TaxScheme>\n"; $l_retur .= "</cac:TaxCategory>\n"; $l_retur .= "</cac:TaxSubtotal>\n"; $l_retur .= "</cac:TaxTotal>\n"; $l_retur .= "<cac:LegalMonetaryTotal>\n"; $l_retur .= "<cbc:LineExtensionAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb) . "</cbc:LineExtensionAmount>\n"; $l_retur .= "<cbc:TaxExclusiveAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_momsbeloeb) . "</cbc:TaxExclusiveAmount>\n"; $l_retur .= "<cbc:TaxInclusiveAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb + $l_momsbeloeb) . "</cbc:TaxInclusiveAmount>\n"; $l_retur .= "<cbc:PayableAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb + $l_momsbeloeb) . "</cbc:PayableAmount>\n"; $l_retur .= "</cac:LegalMonetaryTotal>\n"; # Ordrelinjer $tjeksum = 0; $posnr = 0; #20150922 $query = db_select("select * from ordrelinjer where ordre_id = {$l_ordreid} order by posnr", __FILE__ . " linje " . __LINE__); while ($r_linje = db_fetch_array($query)) { $posnr++; #20150922 if ($db_encode != "UTF8") { $varenr = utf8_encode($r_linje['varenr']); $enhed = utf8_encode($r_linje['enhed']); $beskrivelse = utf8_encode($r_linje['beskrivelse']); } else { $varenr = $r_linje['varenr']; $enhed = $r_linje['enhed']; $beskrivelse = $r_linje['beskrivelse']; } if (!$beskrivelse) { $beskrivelse = "."; } $varenr = htmlspecialchars($varenr, ENT_QUOTES); $enhed = htmlspecialchars($enhed, ENT_QUOTES); $beskrivelse = htmlspecialchars($beskrivelse, ENT_QUOTES); $pris = $r_linje['pris'] * 1; $antal = $r_linje['antal']; if (!$antal) { #20150922 $pris = 0; $antal = 1; } $momsfri = $r_linje['momsfri']; $varemomssats = $r_linje['momssats'] * 1; if (!$momsfri && !$varemomssats) { $varemomssats = $l_momssats; } if ($varemomssats > $l_momssats) { $varemomssats = $l_momssats; } if (!$varenr) { $varenr = '.'; } #phr 20080803 + 20150922 if ($r_linje['procent']) { $pris *= $r_linje['procent'] / 100; } #20150525 $pris = $pris - $r_linje['rabat'] * $pris / 100; #20140206 + næste 2 linjer $linjepris = afrund($r_linje['antal'] * $pris, 2); $pris = afrund($pris, 2); $linjemoms = afrund($linjepris / 100 * $varemomssats, 2); if ($l_ptype == "PCM") { $l_fortegn = -1; $tjeksum -= $linjepris; #20150825 } else { $l_fortegn = 1; $tjeksum += $linjepris; } $l_retur .= "<cac:" . $l_doctype . "Line>\n"; $l_retur .= "<cbc:ID>" . $posnr . "</cbc:ID>\n"; $l_retur .= "<cbc:" . $l2_doctype . "Quantity unitCode=\"" . oioubl_enhed($enhed) . "\">" . $l_fortegn * $antal . "</cbc:" . $l2_doctype . "Quantity>\n"; $l_retur .= "<cbc:LineExtensionAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_fortegn * $linjepris) . "</cbc:LineExtensionAmount>\n"; $l_retur .= "<cac:TaxTotal>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_fortegn * $linjemoms) . "</cbc:TaxAmount>\n"; #20150825 $l_retur .= "<cac:TaxSubtotal>\n"; $l_retur .= "<cbc:TaxableAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_fortegn * $linjepris) . "</cbc:TaxableAmount>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_fortegn * $linjemoms) . "</cbc:TaxAmount>\n"; $l_retur .= "<cac:TaxCategory>\n"; if ($momsfri) { $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxcategoryid-1.1\">ZeroRated</cbc:ID>\n"; } else { $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxcategoryid-1.1\">StandardRated</cbc:ID>\n"; } $l_retur .= "<cbc:Percent>" . $varemomssats . "</cbc:Percent>\n"; $l_retur .= "<cac:TaxScheme>\n"; $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxschemeid-1.1\">63</cbc:ID>\n"; $l_retur .= "<cbc:Name>Moms</cbc:Name>\n"; $l_retur .= "</cac:TaxScheme>\n"; $l_retur .= "</cac:TaxCategory>\n"; $l_retur .= "</cac:TaxSubtotal>\n"; $l_retur .= "</cac:TaxTotal>\n"; $l_retur .= "<cac:Item>\n"; $l_retur .= "<cbc:Description>" . $beskrivelse . "</cbc:Description>\n"; $tmp = substr(utf8_decode($beskrivelse), 0, 40); $tmp = utf8_encode($tmp); $l_retur .= "<cbc:Name>" . $tmp . "</cbc:Name>\n"; # $l_retur.="<cbc:Name>".substr($beskrivelse,0,15)."</cbc:Name>\n"; $l_retur .= "<cac:SellersItemIdentification>\n"; $l_retur .= "<cbc:ID>" . $varenr . "</cbc:ID>\n"; $l_retur .= "</cac:SellersItemIdentification>\n"; $l_retur .= "</cac:Item>\n"; $l_retur .= "<cac:Price>\n"; $l_retur .= "<cbc:PriceAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $pris) . "</cbc:PriceAmount>\n"; # 20120515 $l_retur .= "<cbc:BaseQuantity unitCode=\"ANN\">1</cbc:BaseQuantity>\n"; $l_retur .= "<cbc:OrderableUnitFactorRate>1</cbc:OrderableUnitFactorRate>\n"; $l_retur .= "</cac:Price>\n"; $l_retur .= "</cac:" . $l_doctype . "Line>\n"; } if ($tjeksum != $l_sumbeloeb) { echo "{$tjeksum}!={$l_sumbeloeb}"; $l_retur .= "<cac:" . $l_doctype . "Line>\n"; $tmp = $posnr + 1; $l_retur .= "<cbc:ID>" . $tmp . "</cbc:ID>\n"; $l_retur .= "<cbc:" . $l2_doctype . "Quantity unitCode=\"" . oioubl_enhed($enhed) . "\">1</cbc:" . $l2_doctype . "Quantity>\n"; $l_retur .= "<cbc:LineExtensionAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb - $tjeksum) . "</cbc:LineExtensionAmount>\n"; $l_retur .= "<cac:TaxTotal>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", 0) . "</cbc:TaxAmount>\n"; $l_retur .= "<cac:TaxSubtotal>\n"; $l_retur .= "<cbc:TaxableAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb - $tjeksum) . "</cbc:TaxableAmount>\n"; $l_retur .= "<cbc:TaxAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", 0) . "</cbc:TaxAmount>\n"; $l_retur .= "<cac:TaxCategory>\n"; if ($momsfri) { $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxcategoryid-1.1\">ZeroRated</cbc:ID>\n"; } else { $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxcategoryid-1.1\">StandardRated</cbc:ID>\n"; } $l_retur .= "<cbc:Percent>" . $varemomssats . "</cbc:Percent>\n"; $l_retur .= "<cac:TaxScheme>\n"; $l_retur .= "<cbc:ID schemeAgencyID=\"320\" schemeID=\"urn:oioubl:id:taxschemeid-1.1\">63</cbc:ID>\n"; $l_retur .= "<cbc:Name>Moms</cbc:Name>\n"; $l_retur .= "</cac:TaxScheme>\n"; $l_retur .= "</cac:TaxCategory>\n"; $l_retur .= "</cac:TaxSubtotal>\n"; $l_retur .= "</cac:TaxTotal>\n"; $l_retur .= "<cac:Item>\n"; $l_retur .= "<cbc:Description>Afrunding</cbc:Description>\n"; # $tmp=substr(utf8_decode($beskrivelse),0,40); # $tmp=utf8_encode($tmp); $l_retur .= "<cbc:Name>Afrunding</cbc:Name>\n"; # $l_retur.="<cbc:Name>".substr($beskrivelse,0,15)."</cbc:Name>\n"; $l_retur .= "<cac:SellersItemIdentification>\n"; $l_retur .= "<cbc:ID>0</cbc:ID>\n"; $l_retur .= "</cac:SellersItemIdentification>\n"; $l_retur .= "</cac:Item>\n"; $l_retur .= "<cac:Price>\n"; $l_retur .= "<cbc:PriceAmount currencyID=\"{$l_valutakode}\">" . sprintf("%01.2f", $l_sumbeloeb - $tjeksum) . "</cbc:PriceAmount>\n"; # 20120515 $l_retur .= "<cbc:BaseQuantity unitCode=\"ANN\">1</cbc:BaseQuantity>\n"; $l_retur .= "<cbc:OrderableUnitFactorRate>1</cbc:OrderableUnitFactorRate>\n"; $l_retur .= "</cac:Price>\n"; $l_retur .= "</cac:" . $l_doctype . "Line>\n"; } $l_retur .= "</" . $l_doctype . ">\n"; # $l_retur.=oioubl_bottom($l_doctype); return $l_retur; }
$debettext[$x] = trim($row2['firmanavn']); $tmpffdato = forfaldsdag($transdate[$x], $row2['betalingsbet'], $row2['betalingsdage']); } if ($k_type[$x] == 'F' && $kredit[$x] && !$fejl) { $query2 = db_select("select beskrivelse, moms from kontoplan where kontonr='{$kredit[$x]}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__); $row2 = db_fetch_array($query2); $kredittext[$x] = trim($row2['beskrivelse']); if (trim($row2['moms'])) { $kredittext[$x] = $kredittext[$x] . " - " . trim($row2['moms']); } } if (($k_type[$x] == 'D' || $k_type[$x] == 'K') && $kredit[$x] && !$fejl) { $query2 = db_select("select firmanavn,betalingsbet,betalingsdage from adresser where kontonr='{$kredit[$x]}' and art = '{$k_type[$x]}'", __FILE__ . " linje " . __LINE__); $row2 = db_fetch_array($query2); $kredittext[$x] = trim($row2['firmanavn']); $tmpffdato = forfaldsdag($transdate[$x], $row2['betalingsbet'], $row2['betalingsdage']); } if (($d_type[$x] == 'D' && $debet[$x] || $k_type[$x] == 'K' && $kredit[$x]) && !$fejl && $gl_transdate[$x] && (!$forfaldsdato[$x] || $gl_transdate[$x] != $transdate[$x])) { #20140624 $forfaldsdato[$x] = $tmpffdato; } $betal_id[$x] = $row['betal_id']; } if (!$fejl) { db_modify("delete from tmpkassekl where kladde_id={$kladde_id}", __FILE__ . " linje " . __LINE__); } } for ($y = 1; $y <= $x; $y++) { if (!$fejl) { $antal_ex = $x; }
function bogfor_nu($id, $kilde) { include "../includes/genberegn.php"; include "../includes/forfaldsdag.php"; global $db; global $regnaar; global $valuta; global $valutakurs; global $difkto; global $title; $kilde == 'on' ? $webservice = 'on' : ($webservice = NULL); /* $r = db_fetch_array(db_select("select box7 from grupper where art = 'DIV' and kodenr = '3'",__FILE__ . " linje " . __LINE__)); $tjek_lagerdiff=$r['box7']; if ($tjek_lagerdiff) { include("../includes/genberegn.php"); include("../includes/lagervaerdi.php"); $pre_stockvalue=lagervaerdi($regnaar); $pre_finans=finanslager($regnaar); $pre_lagerdiff=$pre_finans-$pre_stockvalue; #cho "$pre_lagerdiff=$pre_finans-$pre_stockvalue<br>"; } */ # print "<table><tbody>"; $svar = "OK"; $regnaar = $regnaar * 1; #20130820 --> $x = 0; if ($webservice) { $qtxt = "select distinct(kontonr) as kontonr from kontoplan where (kontotype='D' or kontotype='S')"; } else { $qtxt = "select kontonr from kontoplan where regnskabsaar='{$regnaar}' and (kontotype='D' or kontotype='S')"; } $q = db_select($qtxt, __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $kontoplan[$x] = $r['kontonr']; $x++; } # <-- 20130820 # $fp=fopen("../temp/bogfor_nu.log","w"); # $linje="select * from ordrer where id = $id"; # fwrite($fp,$qtxt."\n"); $d_kontrol = 0; $k_kontrol = 0; $logdate = date("Y-m-d"); $logtime = date("H:i"); $uxtid = date("U"); $q = db_select("select box1, box2, box3, box4, box5 from grupper where art='RB'", __FILE__ . " linje " . __LINE__); if ($r = db_fetch_array($q)) { if (trim($r['box3']) == "on") { $faktbill = 1; } else { $faktbill = 0; } if (trim($r['box4']) == "on") { $modtbill = 1; } else { $modtbill = 0; } if (trim($r['box5']) == "on") { $no_faktbill = 1; $faktbill = 0; } else { $no_faktbill = 0; } } $projekt = array(); $idliste = array(); if (is_numeric($id)) { $tmp = "id = '" . $id . "'"; } else { $idliste = explode(",", $id); $antal = count($idliste); #cho " id er array<br>"; $tmp = "(id = '" . $idliste[0] . "'"; for ($x = 1; $x < $antal; $x++) { $tmp .= " or id = '" . $idliste[$x] . "'"; } $tmp .= ")"; } $x = 0; $moms = 0; $sum = 0; $modtaget = 0; $modtaget2 = 0; $betaling = array(); #20150518 (Denne og de to næste er flyttet fra "over select * from pos_betalinger") $modtaget = array(); #20150518 $bnr = -1; #20150518 #cho "select * from ordrer where $tmp<br>"; $q = db_select("select * from ordrer where {$tmp}", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { #cho "Sum $r[sum] $r[moms]<br>"; $art = $r['art']; if ($kilde == 'Dagsafslutning') { $art = 'PO'; } $ordre_id = $r['id']; #20120905 $konto_id = $r['konto_id']; $kontonr = str_replace(" ", "", $r['kontonr']); $firmanavn = trim($r['firmanavn']); $modtagelse = $r['modtagelse']; $transdate = $r['fakturadate']; $fakturanr = $r['fakturanr']; $ordrenr = $r['ordrenr']; $momssats = $r['momssats'] * 1; #cho "$firmanavn | $ordrenr<br>"; $valuta = $r['valuta']; $kred_ord_id = $r['kred_ord_id']; if (!$valuta) { $valuta = 'DKK'; } $projekt[0] = $r['projekt']; $betalingsbet = $r['betalingsbet']; $betalingsdage = $r['betalingsdage'] * 1; $betalt = $r['betalt'] * 1; /* if ($art=='PO') { $betaling=$r['felt_1']; $modtaget+=$r['felt_2']; $betaling2=$r['felt_3']; $modtaget2+=$r['felt_4']; $kasse=$r['felt_5']*1; if ($betalingsbet=='Kontant') { $konto_id=0; $kontonr=NULL; } } else $kasse=0; */ if ($art == 'PO') { #20150505 $qtxt = "select * from pos_betalinger where ordre_id='{$ordre_id}' order by betalingstype"; $q2 = db_select($qtxt, __FILE__ . " linje " . __LINE__); while ($r2 = db_fetch_array($q2)) { # for ($c=0;$c<count($betaling);$c++) echo "$bnr | $c | $bnretaling[$c]==$r2[betalingstype] | $r2[amount]<br>"; if (in_array($r2['betalingstype'], $betaling)) { #cho __line__."<br>"; for ($c = 0; $c < count($betaling); $c++) { if ($betaling[$c] == $r2['betalingstype']) { $modtaget[$c] += $r2['amount']; #cho "B $betaling[$c]==$r2[betalingstype] --> $modtaget[$c] -- $r2[amount]<br>"; } } } else { $bnr++; $betaling[$bnr] = $r2['betalingstype']; $modtaget[$bnr] = $r2['amount']; } } $kasse = $r['felt_5'] * 1; if ($betalingsbet == 'Kontant') { $konto_id = 0; $kontonr = NULL; } } else { $kasse = 0; } # $refnr; if ($momssats) { $moms += $r['moms'] * 1; } # else {$moms=afrund($r['sum']*$r['momssats']/100,2);} $sum += $r['sum'] + $r['moms']; $ordreantal = $x; $forfaldsdate = usdate(forfaldsdag($r['fakturadate'], $betalingsbet, $betalingsdage)); if ($art == 'PO') { $r2 = db_fetch_array(db_select("select id, afd from ansatte where initialer = '{$r['ref']}'", __FILE__ . " linje " . __LINE__)); } else { $r2 = db_fetch_array(db_select("select id, afd from ansatte where navn = '{$r['ref']}'", __FILE__ . " linje " . __LINE__)); } $afd = $r2['afd'] * 1; #sikkerhed for at 'afd' har en vaerdi $ansat = $r2['id'] * 1; if ($no_faktbill == 1) { $bilag = '0'; } else { $bilag = trim($fakturanr); } $udlign = 0; } # if ($sum) { /* if ($art=='PO' && $betalt >= $sum) { $kontonr=0; $konto_id=0; } */ if ($art != 'PO') { $r = db_fetch_array(db_select("select gruppe from adresser where id='{$konto_id}'", __FILE__ . " linje " . __LINE__)); $debitorgruppe = $r['gruppe']; $r = db_fetch_array(db_select("select box1 from grupper where art='DG' and kodenr='{$debitorgruppe}'", __FILE__ . " linje " . __LINE__)); $momskode = substr(trim($r['box1']), 1, 1); if ($moms && !$momskode) { return "Debitorgruppe {$debitorgruppe} ikke tilnkyttet en momsgruppe"; } } else { #saa er det en kontantordre # global $kasse; # global $betaling; # global $betaling2; # global $modtaget; # global $modtaget2; $tmparray = array(); $r = db_fetch_array(db_select("select * from grupper where art = 'POS' and kodenr = '1'", __FILE__ . " linje " . __LINE__)); $tmparray = explode(chr(9), $r['box7']); $momskode = $tmparray[$kasse - 1]; if ($moms && !$momskode) { return "Fejl i momskode for kasse {$kasse}!"; } } if (!is_numeric($id) || $betalingsbet == "Kontant" || $betalingsbet == "Kreditkort" || $betalingsbet == "Forud" && $art == 'PO') { #20130820+20150306 $tmp = NULL; $openpost = NULL; $r = db_fetch_array(db_select("select * from grupper where art = 'DIV' and kodenr = '3'", __FILE__ . " linje " . __LINE__)); #cho "select * from grupper where art = 'DIV' and kodenr = '3'<br>"; if ($betalingsbet == "Kontant") { $tmp = $r['box7']; } elseif ($betalingsbet == "Kreditkort") { $tmp = $r['box10']; } #cho "tmp $tmp<br>"; if ($tmp) { if (in_array($tmp, $kontoplan)) { $openpost = NULL; $kontonr = $tmp; } else { $tekst = "Kontonummer for {$betalingsbet} er ikke gyldigt\\nTjek Indstillinger > Diverse >Ordrerelaterede valg"; return $tekst; } } else { $openpost = 1; } } elseif ($art == 'PO' && !$kontonr) { $openpost = NULL; } else { $openpost = 1; } if (substr($art, 1, 1) == 'K' && $openpost && $kred_ord_id) { $beskrivelse = "Kreditnota - " . $fakturanr; $r = db_fetch_array(db_select("select fakturanr,fakturadate from ordrer where id='{$kred_ord_id}'", __FILE__ . " linje " . __LINE__)); $tmp = $sum * -1; if ($r2 = db_fetch_array(db_select("select * from openpost where konto_id='{$konto_id}' and amount='{$tmp}' and faktnr='{$r['fakturanr']}' and transdate='{$r['fakturadate']}' and udlignet != '1'", __FILE__ . " linje " . __LINE__))) { $transdate > $r2['transdate'] ? $udlign_date = $transdate : ($udlign_date = $r2['transdate']); $r2 = db_fetch_array(db_select("select max(udlign_id) as udlign_id from openpost", __FILE__ . " linje " . __LINE__)); $udlign_id = $r2['udlign_id'] + 1; db_modify("update openpost set udlignet='1',udlign_date='{$udlign_date}',udlign_id='{$udlign_id}' where konto_id='{$konto_id}' and amount='{$tmp}' and faktnr='{$r['fakturanr']}' and transdate='{$r['fakturadate']}'", __FILE__ . " linje " . __LINE__); $udlign = 1; } } elseif ($art == 'PO') { is_numeric($id) ? $beskrivelse = "Bon - " . $fakturanr : ($beskrivelse = "Kontantsalg kasse - " . $kasse); if ($kilde == 'Dagsafslutning') { $beskrivelse = $kilde . " - kassenr: " . $kasse; } } elseif ($openpost) { $beskrivelse = "Faktura - " . $fakturanr; } elseif ($betalingsbet == "Kontant") { $beskrivelse = "Kontantsalg: Faktura - " . $fakturanr; } else { $beskrivelse = "Kreditkort salg: Faktura - " . $fakturanr; } # 20120905 - Indsat grundet dobbelt bogforing af ordre id 4207 i regnskab saldi_510 #cho "select id from transaktioner where ordre_id='$ordre_id'<br>"; if ($r = db_fetch_array(db_select("select id,ordre_id from transaktioner where ordre_id='{$ordre_id}'", __FILE__ . " linje " . __LINE__))) { $tekst = "Bogføring afbrudt - tjek kontrolspor (id {$r['id']} oid {$r['ordre_id']})"; print "<BODY onLoad=\"javascript:alert('{$tekst}')\">"; return $tekst; } if ($kontonr && $openpost) { $tmp = $sum; if (db_fetch_array(db_select("select id from openpost where konto_id='{$konto_id}' and konto_nr='{$kontonr}' and faktnr='{$fakturanr}' and amount='{$tmp}' and beskrivelse='{$beskrivelse}' and udlignet='{$udlign}' and transdate='{$transdate}' and kladde_id='{$udlign}' and refnr='{$id}' and valuta='{$valuta}' and valutakurs='{$valutakurs}' and forfaldsdate='{$forfaldsdate}'", __FILE__ . " linje " . __LINE__))) { $tekst = "Bogføring afbrudt - tjek kontrolspor"; print "<BODY onLoad=\"javascript:alert('{$tekst}')\">"; return $tekst; } if ($udlign && $udlign_id && $udlign_date) { db_modify("insert into openpost (konto_id,konto_nr,faktnr,amount,beskrivelse,udlignet,udlign_id,udlign_date,transdate,uxtid,kladde_id,refnr,valuta,valutakurs,forfaldsdate,projekt) values ('{$konto_id}','{$kontonr}','{$fakturanr}','{$tmp}','{$beskrivelse}','{$udlign}','{$udlign_id}','{$udlign_date}','{$transdate}','{$uxtid}','{$udlign}','{$id}','{$valuta}','{$valutakurs}','{$forfaldsdate}','{$projekt['0']}')", __FILE__ . " linje " . __LINE__); } else { db_modify("insert into openpost (konto_id,konto_nr,faktnr,amount,beskrivelse,udlignet,transdate,uxtid,kladde_id,refnr,valuta,valutakurs,forfaldsdate,projekt) values ('{$konto_id}','{$kontonr}','{$fakturanr}','{$tmp}','{$beskrivelse}','{$udlign}','{$transdate}','{$uxtid}','{$udlign}','{$id}','{$valuta}','{$valutakurs}','{$forfaldsdate}','{$projekt['0']}')", __FILE__ . " linje " . __LINE__); } $r = db_fetch_array(db_select("select max(id) as id from openpost where konto_id = '{$konto_id}' and faktnr = '{$fakturanr}' and refnr='{$id}'", __FILE__ . " linje " . __LINE__)); $openpost_id = $r['id']; $r = db_fetch_array(db_select("select gruppe from adresser where id='{$konto_id}'", __FILE__ . " linje " . __LINE__)); $r = db_fetch_array(db_select("select beskrivelse, box2 from grupper where art = 'DG' and kodenr='{$r['gruppe']}'", __FILE__ . " linje " . __LINE__)); $kontonr = $r['box2']; # Kontonr aendres fra at vaere leverandoerkontonr til finanskontonr $tekst = "Kontonummer for Debitorgruppe `{$r['beskrivelse']}` er ikke gyldigt"; if (!$kontonr && $webservice) { return $tekst; } elseif (!$kontonr) { print "<BODY onLoad=\"javascript:alert('{$tekst}')\">"; } } if (!in_array($kontonr, $kontoplan) && $art != 'PO') { $tekst = "Kontonummer {$kontonr} findes ikke i kontoplanen for regnskabsaar {$regnaar}"; return $tekst; exit; } if ($art == 'PO' && $sum) { #saa er det en kontantordre (POS) $retur = $sum; $tmparray = array(); $r = db_fetch_array(db_select("select box6 from grupper where art = 'POS' and kodenr = '2'", __FILE__ . " linje " . __LINE__)); $div_kort_kto = trim($r['box6']); $r = db_fetch_array(db_select("select * from grupper where art = 'POS' and kodenr = '1'", __FILE__ . " linje " . __LINE__)); if (!$konto_id) { #20140616 $tmparray = explode(chr(9), $r['box2']); $kassekto = $tmparray[$kasse - 1]; $kontonr = $kassekto; } #else $tmparray = explode(chr(9), $r['box3']); $afd = $tmparray[$kasse - 1] * 1; $tmparray = explode(chr(9), $r['box5']); $kortantal = $r['box4'] * 1; $korttyper = explode(chr(9), $r['box5']); $kortkonti = explode(chr(9), $r['box6']); $kortnavn = NULL; if ($div_kort_kto) { #20140129 for ($b = 0; $b < count($betaling); $b++) { #20150505 if (strpos($betaling[$b], "|")) { list($betaling[$b], $kortnavn) = explode("|", $betaling[$b]); } } # if (strpos($betaling2,"|")) list($betaling2,$kortnavn)=explode("|",$betaling2); $korttyper[$kortantal] = 'Betalingskort'; $kortkonti[$kortantal] = $div_kort_kto; $kortantal++; } for ($x = 0; $x < $kortantal; $x++) { #20150505 #cho __LINE__." $korttyper[$x] -->"; for ($b = 0; $b < count($betaling); $b++) { #cho __LINE__." $betaling[$b]==$korttyper[$x] -->"; #cho "$modtaget[$b]<br>"; if ($betaling[$b] == $korttyper[$x]) { $kontonr = $kortkonti[$x]; #20150507 $debet = afrund($modtaget[$b], 2); $kredit = '0'; $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $retur = $retur - $modtaget[$b]; $sum = $sum - $modtaget[$b]; if ($debet) { if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$kortkonti[$x]}','{$fakturanr}','{$debet}','{$kredit}','0',{$afd},'{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$kortkonti[$x]}','0','{$debet}','{$kredit}','0',{$afd},'{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','0','{$kasse}')"; } db_modify($qtxt, __FILE__ . " linje " . __LINE__); $qtxt = "update kontoplan set saldo=saldo+'{$debet}' where kontonr='{$kortkonti[$x]}' and regnskabsaar='{$regnaar}'"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); } } #xit; /* if ($betaling2==$korttyper[$x]) { $debet=afrund($modtaget2,2); $kredit='0'; $d_kontrol=$d_kontrol+$debet; $k_kontrol=$k_kontrol+$kredit; $sum=$sum-$modtaget2; if (is_numeric($id)) { $qtxt="insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','$transdate','$beskrivelse','$kortkonti[$x]','$fakturanr','$debet','$kredit','0',$afd,'$logdate','$logtime','$projekt[0]','$ansat','$id','$kasse')"; } else { $qtxt="insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','$transdate','$beskrivelse','$kortkonti[$x]','0','$debet','$kredit','0',$afd,'$logdate','$logtime','$projekt[0]','$ansat','0','$kasse')"; } db_modify($qtxt,__FILE__ . " linje " . __LINE__); $qtxt="update kontoplan set saldo=saldo+'$debet' where kontonr='$kortkonti[$x]' and regnskabsaar='$regnaar'"; db_modify($qtxt,__FILE__ . " linje " . __LINE__); } */ } } #cho __LINE__." $konto_id | $openpost -> $kontonr<br>"; if (!$konto_id) { $kontonr = $kassekto; } #20150518 (Ellers fortsætter den med at bogføre på samme kontonr) #20150521 #cho __LINE__." $konto_id-> $kontonr<br>"; } $sum = afrund($sum, 3); if ($sum) { if ($sum > 0) { $debet = $sum; $kredit = '0'; } else { $debet = '0'; $kredit = $sum * -1; } if ($valutakurs) { $kredit = afrund($kredit * $valutakurs / 100, 3); $debet = afrund($debet * $valutakurs / 100, 3); } # Omregning til DKR. $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$kontonr}','{$fakturanr}','{$debet}','{$kredit}','0',{$afd},'{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$kontonr}','0','{$debet}','{$kredit}','0',{$afd},'{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','0','{$kasse}')"; } #cho __LINE__." $qtxt<br>"; #xit; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; $qtxt = "update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$kontonr}' and regnskabsaar='{$regnaar}'"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); } if ($valutakurs) { $maxdif = 2; } #Der tillades 2 oeres afrundingsdiff $p = 0; $projektliste = ''; if (is_numeric($id)) { $tmp = "ordre_id = '" . $id . "'"; } else { $idliste = explode(",", $id); $antal = count($idliste); $tmp = "(ordre_id = '" . $idliste[0] . "'"; for ($x = 1; $x < $antal; $x++) { $tmp .= " or ordre_id = '" . $idliste[$x] . "'"; } $tmp .= ")"; } db_modify("update ordrelinjer set projekt='' where projekt is NULL and {$tmp}", __FILE__ . " linje " . __LINE__); $q = db_select("select distinct(projekt) from ordrelinjer where {$tmp} and vare_id >'0'", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { # if(trim($r['projekt'])) { $p++; $projekt[$p] = trim($r['projekt']); $projektliste ? $projektliste .= "<br>" . $projekt[$p] : ($projektliste = $projekt[$p]); # } } $p ? $projektantal = $p : ($projektantal = 1); if ($projektliste && $openpost) { db_modify("update openpost set projekt='{$projektliste}' where id='{$openpost_id}'", __FILE__ . " linje " . __LINE__); } # for ($p=1;$p<=$projektantal;$p++) for ($t = 1; $t <= 2; $t++) { for ($p = 1; $p <= $projektantal; $p++) { $y = 0; $tjek = array(); $bogf_konto = array(); if (is_numeric($id)) { $tmp = "ordre_id = '" . $id . "'"; } else { $idliste = explode(",", $id); $antal = count($idliste); $tmp = "(ordre_id = '" . $idliste[0] . "'"; for ($x = 1; $x < $antal; $x++) { $tmp .= " or ordre_id = '" . $idliste[$x] . "'"; } $tmp .= ")"; } if ($t == 1) { $qtxt = "select * from ordrelinjer where {$tmp} and projekt='{$projekt[$p]}' and posnr>='0' order by bogf_konto"; } else { $qtxt = "select * from ordrelinjer where {$tmp} and projekt='{$projekt[$p]}' and posnr<'0' order by bogf_konto"; } #cho __LINE__."$qtxt<br>"; $q = db_select($qtxt, __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { #cho __LINE__." $y<br>"; if ($valutakurs && $valutakurs != 100) { $maxdif = $maxdif + 2; } #Og yderligere 2 pr ordrelinje. if (!in_array($r['bogf_konto'], $bogf_konto)) { $y++; $bogf_konto[$y] = $r['bogf_konto']; if ($r['rabatart'] == 'amount') { # $pris[$y]=$r['pris']*$r['antal']-($r['rabat']*$r['antal']); # remmet 20140424b $linjesum = $r['pris'] * $r['antal'] - $r['rabat'] * $r['antal']; #20140424b $r['procent'] || $r['procent'] != '' ? $pris[$y] = $linjesum * $r['procent'] / 100 : ($pris[$y] = $linjesum); #20140424b } else { # $pris[$y]=$r['pris']*$r['antal']-($r['pris']*$r['antal']*$r['rabat']/100); # remmet 20140424b $linjesum = $r['pris'] * $r['antal'] - $r['pris'] * $r['antal'] * $r['rabat'] / 100; #20140424b $r['procent'] || $r['procent'] != '' ? $pris[$y] = $linjesum * $r['procent'] / 100 : ($pris[$y] = $linjesum); #20140424b if ($art == 'PO') { $pris[$y] = afrund($pris[$y], 3); } else { $pris[$y] = afrund($pris[$y], 3); } #Afrunding tilfoejet 2009.01.26 grundet diff i ordre 98 i saldi_104 -- 2011.02.07 ændret til 2 decimaler ordre_id 1325 saldi_329 #cho "$pris[$y]<br>"; } } else { for ($a = 1; $a <= $y; $a++) { if ($bogf_konto[$a] == $r['bogf_konto']) { if ($r['rabatart'] == 'amount') { # $pris[$a]+=$r['pris']*$r['antal']-($r['rabat']*$r['antal']); # remmet 20140424b $linjesum = $r['pris'] * $r['antal'] - $r['rabat'] * $r['antal']; #20140424b } else { # $pris[$a]=$pris[$a]+($r['pris']*$r['antal']-($r['pris']*$r['antal']*$r['rabat']/100)); # remmet 20140424b $linjesum = $r['pris'] * $r['antal'] - $r['pris'] * $r['antal'] * $r['rabat'] / 100; #20140424b } $r['procent'] || $r['procent'] != '' ? $pris[$a] += $linjesum * $r['procent'] / 100 : ($pris[$a] += $linjesum); #20140424b if ($art == 'PO') { $pris[$a] = afrund($pris[$a], 3); } else { $pris[$a] = afrund($pris[$a], 3); } #Afrunding tilfoejet 2009.01.26 grundet diff i ordre 98 i saldi_104 -- 2011.02.07 ændret til 2 decimaler ordre_id 1325 saldi_329 } } } } $ordrelinjer = $y; if ($indbetaling) { $ordrelinjer = 0; } for ($y = 1; $y <= $ordrelinjer; $y++) { if ($bogf_konto[$y] && $pris[$y]) { if ($pris[$y] > 0) { $kredit = $pris[$y]; $debet = 0; } else { $kredit = 0; $debet = $pris[$y] * -1; } if ($t == 1 && $valutakurs) { $kredit = $kredit * $valutakurs / 100; $debet = $debet * $valutakurs / 100; } # Omregning til DKR. $kredit = afrund($kredit, 3); $debet = afrund($debet, 3); $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$bogf_konto[$y]}','{$fakturanr}','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt[$p]}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$bogf_konto[$y]}','0','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt[$p]}','{$ansat}','0','{$kasse}')"; } #cho __LINE__."$qtxt<br>"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; $qtxt = "update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$bogf_konto[$y]}' and regnskabsaar='{$regnaar}'"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); } elseif ($pris[$y]) { $svar = "Fejl i kontoopsætning"; if (!$webservice) { print "<BODY onLoad=\"javascript:alert('{$svar}')\">"; } else { return "{$svar}"; } exit; } } } } #xit; if ($momskode) { $query = db_select("select box1 from grupper where art='SM' and kodenr='{$momskode}'", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); if ($box1 = trim($row['box1'])) { # 20150522 if ($moms > 0) { $kredit = $moms; $debet = '0'; } else { $kredit = '0'; $debet = $moms * -1; } if ($valutakurs) { $kredit = afrund($kredit * $valutakurs / 100, 3); $debet = afrund($debet * $valutakurs / 100, 3); } # Omregning til DKR. $kredit = afrund($kredit, 3); $debet = afrund($debet, 3); $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $diff = afrund($d_kontrol - $k_kontrol, 3); $absdiff = abs($diff); if ($moms && $valutakurs && $valutakurs != 100 && $absdiff >= 0.01 && $absdiff <= 0.05) { if ($debet > 0) { $debet = $debet + $diff; $d_kontrol = $d_kontrol + $diff; } elseif ($kredit > 0) { $kredit = $kredit + $diff; $k_kontrol = $k_kontrol + $diff; } } $moms = afrund($moms, 2); if ($moms) { if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id,kasse_nr) values ('0', '{$transdate}', '{$beskrivelse}', '{$box1}', '{$fakturanr}', '{$debet}', '{$kredit}', '0', '{$afd}', '{$logdate}', '{$logtime}', '{$projekt['0']}', '{$ansat}', '{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id,kasse_nr) values ('0', '{$transdate}', '{$beskrivelse}', '{$box1}', '0', '{$debet}', '{$kredit}', '0', '{$afd}', '{$logdate}', '{$logtime}', '{$projekt['0']}', '{$ansat}', '0','{$kasse}')"; } #cho __LINE__." $qtxt<br>"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; $qtxt = "update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$box1}' and regnskabsaar='{$regnaar}'"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); } $valutakurs = $valutakurs * 1; } elseif ($moms) { return "Fejl i momsopsætning"; } } if (is_numeric($id)) { $tmp = "id = '" . $id . "'"; } else { $idliste = explode(",", $id); $antal = count($idliste); $tmp = "(id = '" . $idliste[0] . "'"; for ($x = 1; $x < $antal; $x++) { $tmp .= " or id = '" . $idliste[$x] . "'"; } $tmp .= ")"; } $tidspkt = date("H:i"); db_modify("update ordrer set status='4',valutakurs='{$valutakurs}' where {$tmp}", __FILE__ . " linje " . __LINE__); if (is_numeric($id)) { $tmp = "ordre_id = '" . $id . "'"; } else { $idliste = explode(",", $id); $antal = count($idliste); $tmp = "(ordre_id = '" . $idliste[0] . "'"; for ($x = 1; $x < $antal; $x++) { $tmp .= " or ordre_id = '" . $idliste[$x] . "'"; } $tmp .= ")"; } db_modify("delete from ordrelinjer where {$tmp} and posnr < 0", __FILE__ . " linje " . __LINE__); $d_kontrol = afrund($d_kontrol, 2); $k_kontrol = afrund($k_kontrol, 2); if ($diff = afrund($d_kontrol - $k_kontrol, 2)) { $debet = 0; $kredit = 0; if ($diff < 0) { $debet = $diff * -1; } else { $kredit = $diff; } $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); #cho "$diff > maxdif $maxdif<br>"; if ($art == 'PO') { #20140628 #cho "select box1,box2 from grupper where grupper.art='OreDif'<br>"; $r = db_fetch_array(db_select("select box1,box2 from grupper where grupper.art='OreDif'", __FILE__ . " linje " . __LINE__)); $difkto = $r['box2'] * 1; $maxdif = $r['box1'] * 100; if (!db_fetch_array(db_select("select id from kontoplan where kontonr='{$difkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__))) { return "Kontonr {$difkto} (Øredifferencer) eksisterer ikke"; } $diff = 0; $q = db_select("select debet,kredit from transaktioner where beskrivelse='{$beskrivelse}' and logdate='{$logdate}' and logtime='{$logtime}' and kasse_nr='{$kasse}'", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $d = afrund($r['debet'], 2); $k = afrund($r['kredit'], 2); #cho "tmp $d $k<br>"; $diff += $d - $k; } if ($diff) { if ($diff < 0) { $debet = $diff * -1; } else { $kredit = $diff; } $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$difkto}','{$fakturanr}','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$difkto}','0','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','0','{$kasse}')"; } #cho __LINE__." $qtxt<br>"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; db_modify("update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$difkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__); } #xit; } elseif ($valuta != 'DKK' && abs($diff) <= $maxdif) { #Der maa max vaere en afvigelse paa 1 oere pr ordrelinje m fremmed valuta; $r = db_fetch_array(db_select("select box3 as difkto from grupper where grupper.art='VK' and grupper.box1='{$valuta}'", __FILE__ . " linje " . __LINE__)); $difkto = $r['difkto'] * 1; if (!db_fetch_array(db_select("select id from kontoplan where kontonr='{$difkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__))) { return "Kontonr {$difkto} (kursdiff) eksisterer ikke"; } if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$difkto}','{$fakturanr}','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$difkto}','0','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','0','{$kasse}')"; } #cho __LINE__."$qtxt<br>"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; db_modify("update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$difkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__); #xit; } elseif (abs($diff) < 0.05) { if ($r = db_fetch_array(db_select("select * from grupper where art = 'OreDif'", __FILE__ . " linje " . __LINE__))) { $oredifkto = $r['box2']; } else { return 'Manglende kontonummer til øredifferencer - Se indstillinger -> diverse -> ørediff'; } $r = db_fetch_array(db_select("select id from kontoplan where kontotype = 'D' and kontonr = '{$oredifkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__)); if ($r['id']) { if (is_numeric($id)) { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$oredifkto}','{$fakturanr}','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','{$id}','{$kasse}')"; } else { $qtxt = "insert into transaktioner (bilag,transdate,beskrivelse,kontonr,faktura,debet,kredit,kladde_id,afd,logdate,logtime,projekt,ansat,ordre_id,kasse_nr) values ('0','{$transdate}','{$beskrivelse}','{$oredifkto}','0','{$debet}','{$kredit}','0','{$afd}','{$logdate}','{$logtime}','{$projekt['0']}','{$ansat}','0','{$kasse}')"; } #cho __LINE__."$qtxt<br>"; db_modify($qtxt, __FILE__ . " linje " . __LINE__); $tmp = $debet - $kredit; db_modify("update kontoplan set saldo=saldo+'{$tmp}' where kontonr='{$oredifkto}' and regnskabsaar='{$regnaar}'", __FILE__ . " linje " . __LINE__); } else { return 'Manglende kontonummer til øredifferencer - Se indstillinger -> diverse -> ørediff'; } } else { $svar = "Der er konstateret en uoverensstemmelse i posteringssummen, ID {$ordre_id} ordre {$ordrenr}, d={$d_kontrol}, k={$k_kontrol} kontakt DANOSOFT på telefon 4690 2208"; if ($art == 'PO') { echo "{$svar}<br>"; } $message = $db . " | Uoverensstemmelse i posteringssum: ordre_id={$id}, d={$d_kontrol}, k={$k_kontrol} | " . __FILE__ . " linje " . __LINE__ . " | " . $brugernavn . " " . date("Y-m-d H:i:s"); $headers = 'From: fejl@saldi.dk' . "\r\n" . 'Reply-To: fejl@saldi.dk' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail('*****@*****.**', 'SALDI Fejl', $message, $headers); return "{$svar}"; #20130506 exit; } } if ($konto_id) { $r = db_fetch_array(db_select("select sum(amount) from openpost where udlignet!='1' and konto_id = '{$konto_id}'", __FILE__ . " linje " . __LINE__)); $saldo = $r['amount'] * 1; db_modify("update adresser set saldo='{$saldo}' where id='{$konto_id}'", __FILE__ . " linje " . __LINE__); } if ($title != "Massefakturering" && !$webservice && $art != 'PO') { genberegn($regnaar); } return $svar; }
function flytordre($kladde_id, $ordre_id) { global $regnaar; global $connection; global $aarstart; global $aarslut; include "../includes/forfaldsdag.php"; transaktion("begin"); if (!$aarstart) { $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 = trim($row['box2']); $aarstart = trim($year . $row['box1']); $year = trim($row['box4']); $aarslut = trim($year . $row['box3']); } } $query = db_select("select box1, box2, box3, box4, box5 from grupper where art='RB'", __FILE__ . " linje " . __LINE__); if ($row = db_fetch_array($query)) { if (trim($row['box3']) == "on") { $faktbill = 1; } else { $faktbill = 0; } if (trim($row['box4']) == "on") { $modtbill = 1; } else { $modtbill = 0; } if (trim($row['box5']) == "on") { $no_faktbill = 1; $faktbill = 0; } else { $no_faktbill = 0; } } $x = 0; $query = db_select("select * from ordrer where status=3 and id='{$ordre_id}' order by fakturadate", __FILE__ . " linje " . __LINE__); if ($row = db_fetch_array($query)) { list($year, $month, $day) = split('-', $row['fakturadate']); $ym = $year . $month; if ($ym >= $aarstart && $ym <= $aarslut) { $id = $row['id']; $art = $row['art']; $konto_id = $row['konto_id']; $kontonr = str_replace(" ", "", $row['kontonr']); $firmanavn = trim($row['firmanavn']); $modtagelse = $row['modtagelse']; $transdate = $row['fakturadate']; $forfaldsdate = usdate(forfaldsdag($transdate, $row['betalingsbet'], $row['betalingsdage'])); $fakturanr = addslashes($row['fakturanr']); $ordrenr = $row['ordrenr']; $valuta = $row['valuta']; if ($valuta && $valuta != 'DKK') { $r = db_fetch_array(db_select("select kodenr from grupper where box1='{$valuta}' and art='VK'", __FILE__ . " linje " . __LINE__)); $valuta = $r['kodenr'] * 1; } else { $valuta = 0; } $projekt[0] = $row['projekt']; $moms = $row['moms'] * 1; $sum = $row['sum'] + $moms; $ordreantal = $x; $q = db_select("select id, afd from ansatte where navn = '{$row['ref']}'", __FILE__ . " linje " . __LINE__); $r = db_fetch_array($q); $afd = $r['afd'] * 1; $ansat = $r['id'] * 1; if (!$konto_id) { $firmanavn = "Kontantsalg"; $betalt = $row['betalt']; $retur = $betalt - $sum; $betaling1 = $row['felt_1']; $betalt1 = $row['felt_2'] * 1; $betaling2 = $row['felt_3']; $betalt2 = $row['felt_4'] * 1; $kasse = $row['felt_5'] * 1; $kortnavn = array(); $kortkto = array(); $r = db_fetch_array(db_select("select * from grupper where art = 'POS' and kodenr='{$kasse}'", __FILE__ . " linje " . __LINE__)); $tmparray = explode(chr(9), $r['box2']); $kontonr = $tmparray[$kasse - 1]; $kortnavn = explode(chr(9), $r['box5']); $kortkto = explode(chr(9), $r['box6']); $tmparray = explode(chr(9), $r['box7']); $momsgruppe = $tmparray[$kasse - 1]; $z = 0; if ($betaling1 == 'Kontant') { $kortkto1 = $kontonr; $betalt1 = $betalt1 - $retur; $retur = 0; } if ($betaling2 == 'Kontant') { $kortkto2 = $kontonr; $betalt2 = $betalt2 - $retur; $retur = 0; } while ($kortkto[$z]) { if ($betaling1 == $kortnavn[$z]) { $kortkto1 = $kortkto[$z]; } if ($betaling2 == $kortnavn[$z]) { $kortkto2 = $kortkto[$z]; } $z++; } $r = db_fetch_array(db_select("select box1 from grupper where art='SM' and kodenr='{$momskode}'", __FILE__ . " linje " . __LINE__)); $box1 = trim($r['box1']); } if (substr($art, 0, 1) == 'K' && $modtagelse > 0 && $modtbill == 1) { $bilag = $modtagelse; } elseif ((substr($art, 0, 1) == 'D' || $art == 'PO') && $no_faktbill == 1) { $bilag = '0'; } elseif ((substr($art, 0, 1) == 'D' || $art == 'PO') && $faktbill == 1) { $bilag = trim($fakturanr); } else { $tmp1 = substr($aarstart, 0, 4) . "-" . substr($aarstart, 4, 2) . "-01"; $tmp2 = 31; while (!checkdate(substr($aarslut, 4, 2), $tmp2, substr($aarslut, 0, 4))) { $tmp2--; if ($tmp2 < 28) { break 1; } #20130210 } $tmp2 = substr($aarslut, 0, 4) . "-" . substr($aarslut, 4, 2) . "-" . $tmp2; $row = db_fetch_array(db_select("select MAX(bilag) as bilag from kassekladde where transdate>='{$tmp1}' and transdate<='{$tmp2}'", __FILE__ . " linje " . __LINE__)); $bilag = $row['bilag'] + 1; } $p = 0; $q = db_select("select distinct(projekt) from ordrelinjer where ordre_id={$id} and vare_id >\t'0'", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $p++; $projekt[$p] = $r['projekt']; } $projektantal = $p; if (substr($art, 0, 1) == 'K') { if (substr($art, 1, 1) == 'K') { $beskrivelse = "Lev. Kreditnota - " . $fakturanr; } else { $beskrivelse = "Lev.Faktura - " . $fakturanr; } $beskrivelse = addslashes($beskrivelse); db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'K', '{$kontonr}', '{$fakturanr}', '{$sum}', 'on', '{$kladde_id}', '{$afd}', '{$valuta}', '{$projekt['0']}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); for ($p = 1; $p <= $projektantal; $p++) { $query = db_select("select * from ordrelinjer where ordre_id='{$id}' and projekt = '{$projekt[$p]}'", __FILE__ . " linje " . __LINE__); $y = 0; $bogf_konto = array(); while ($row = db_fetch_array($query)) { $bogf_kto = $row['bogf_konto']; if ($valuta != 'DKK' && $row['posnr'] < 0) { $bogf_kto = $bogf_kto * -1; } if (!in_array($bogf_kto, $bogf_konto)) { $y++; $posnr[$y] = $row['posnr']; $bogf_konto[$y] = trim($bogf_kto); $pris[$y] = afrund($row['pris'] * $row['antal'] - $row['pris'] * $row['antal'] * $row['rabat'] / 100, 3); } else { for ($a = 1; $a <= $y; $a++) { if ($bogf_konto[$a] == $bogf_kto) { $pris[$a] = $pris[$a] + afrund($row['pris'] * $row['antal'] - $row['pris'] * $row['antal'] * $row['rabat'] / 100, 3); } } } } if ($valuta) { for ($a = 1; $a <= $y; $a++) { $bogf_konto[$a] = abs($bogf_konto[$a]); } } $ordrelinjer = $y; for ($y = 1; $y <= $ordrelinjer; $y++) { if ($bogf_konto[$y]) { if ($posnr[$y] < 0) { $tmpvaluta = 0; } else { $tmpvaluta = $valuta; } $kontoart[$y] = $art; if ($pris[$y] < 0) { $pris[$y] = $pris[$y] * -1; db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$bogf_konto[$y]}', '{$fakturanr}', '{$pris[$y]}', 'on', '{$kladde_id}', '{$afd}', '{$tmpvaluta}', '{$projekt[$p]}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } elseif ($pris[$y] > 0) { db_modify("insert into kassekladde (bilag, transdate, beskrivelse, d_type, debet, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$bogf_konto[$y]}', '{$fakturanr}', '{$pris[$y]}', 'on', '{$kladde_id}', '{$afd}', '{$tmpvaluta}', '{$projekt[$p]}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } } } } $query = db_select("select gruppe from adresser where id='{$konto_id}';", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $query = db_select("select box1 from grupper where art='KG' and kodenr='{$row['gruppe']}';", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $box1 = substr(trim($row['box1']), 1, 1); if (substr(trim($row['box1']), 0, 1) == 'E') { $query = db_select("select box1, box2, box3 from grupper where art='EM' and kodenr='{$box1}'", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $box1 = trim($row['box3']); # Ser lidt forvirrende ud, men den er go nok - fordi koebsmomsen ligger i box 3 v. udenlandsmoms. $moms = $sum / 100 * $row['box2']; #moms af varekoeb i udland beregnes db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$row['box1']}', '{$fakturanr}', '{$moms}', 'on', '{$kladde_id}', '{$afd}', '{$valuta}', '{$projekt['0']}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } else { $query = db_select("select box1 from grupper where art='KM' and kodenr='{$box1}'", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $box1 = trim($row['box1']); } db_modify("insert into kassekladde (bilag, transdate, beskrivelse, d_type, debet, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$box1}', '{$fakturanr}', '{$moms}', 'on', '{$kladde_id}', '{$afd}', '{$valuta}', '{$projekt['0']}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } else { #################### Debitor / POS ordrer #################### if ($art == 'RB') { $beskrivelse = "Rykker - " . $ordrenr; } elseif (substr($art, 1, 1) == 'K') { $beskrivelse = "Kreditnota - " . $fakturanr; } elseif ($art == 'PO') { $beskrivelse = "Kassebon - " . $fakturanr; } else { $beskrivelse = "Faktura - " . $fakturanr; } if ($sum < 0) { if ($art == 'PO') { $dk = 'F'; } else { $dk = 'D'; } $tmp = $sum * -1; #indsat 50.02.11 grunder vejl v. hentning af kreditnota db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', '{$dk}', '{$kontonr}', '{$fakturanr}', '{$tmp}', 'on', '{$kladde_id}', '{$afd}', '{$valuta}', '{$projekt['0']}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } else { if ($art == 'PO') { if ($betaling1 && $betalt1) { db_modify("insert into kassekladde (bilag,transdate,beskrivelse,d_type,debet,faktura,amount,momsfri,kladde_id,afd,valuta,projekt,ansat,ordre_id,forfaldsdate) values ('{$bilag}','{$transdate}','{$beskrivelse}','F','{$kortkto1}','{$fakturanr}','{$betalt1}','on','{$kladde_id}','{$afd}','{$valuta}','{$projekt['0']}','{$ansat}','{$ordre_id}','{$forfaldsdate}')", __FILE__ . " linje " . __LINE__); } if ($betaling2 && $betalt2) { db_modify("insert into kassekladde (bilag,transdate,beskrivelse,d_type,debet,faktura,amount,momsfri,kladde_id,afd,valuta,projekt,ansat,ordre_id,forfaldsdate) values ('{$bilag}','{$transdate}','{$beskrivelse}','F','{$kortkto2}','{$fakturanr}','{$betalt2}','on','{$kladde_id}','{$afd}','{$valuta}','{$projekt['0']}','{$ansat}','{$ordre_id}','{$forfaldsdate}')", __FILE__ . " linje " . __LINE__); } if ($retur) { db_modify("insert into kassekladde (bilag,transdate,beskrivelse,k_type,kredit,faktura,amount,momsfri,kladde_id,afd,valuta,projekt,ansat,ordre_id,forfaldsdate) values ('{$bilag}','{$transdate}','{$beskrivelse}','F','{$kontonr}','{$fakturanr}','{$retur}','on','{$kladde_id}','{$afd}','{$valuta}','{$projekt['0']}','{$ansat}','{$ordre_id}','{$forfaldsdate}')", __FILE__ . " linje " . __LINE__); } } else { db_modify("insert into kassekladde (bilag,transdate,beskrivelse,d_type,debet,faktura,amount,momsfri,kladde_id,afd,valuta,projekt,ansat,ordre_id,forfaldsdate) values ('{$bilag}','{$transdate}','{$beskrivelse}','D','{$kontonr}','{$fakturanr}','{$sum}','on','{$kladde_id}','{$afd}','{$valuta}','{$projekt['0']}','{$ansat}','{$ordre_id}','{$forfaldsdate}')", __FILE__ . " linje " . __LINE__); } } for ($p = 1; $p <= $projektantal; $p++) { $query = db_select("select * from ordrelinjer where ordre_id={$id} and projekt = '{$projekt[$p]}'", __FILE__ . " linje " . __LINE__); $y = 0; $bogf_konto = array(); while ($row = db_fetch_array($query)) { $bogf_kto = $row['bogf_konto']; if ($valuta != 'DKK' && $row['posnr'] < 0) { $bogf_kto = $bogf_kto * -1; } if (!in_array($bogf_kto, $bogf_konto)) { $y++; $posnr[$y] = $row['posnr']; $bogf_konto[$y] = $bogf_kto; $pris[$y] = afrund($row['pris'] * $row['antal'] - $row['pris'] * $row['antal'] * $row['rabat'] / 100, 3); } else { for ($a = 1; $a <= $y; $a++) { if ($bogf_konto[$a] == $bogf_kto) { $pris[$a] = $pris[$a] + afrund($row['pris'] * $row['antal'] - $row['pris'] * $row['antal'] * $row['rabat'] / 100, 3); } } } } if ($valuta) { for ($a = 1; $a <= $y; $a++) { $bogf_konto[$a] = abs($bogf_konto[$a]); } } $ordrelinjer = $y; for ($y = 1; $y <= $ordrelinjer; $y++) { if ($bogf_konto[$y]) { if ($posnr[$y] < 0) { $tmpvaluta = 0; } else { $tmpvaluta = $valuta; } if ($pris[$y] < 0) { $pris[$y] = $pris[$y] * -1; db_modify("insert into kassekladde (bilag, transdate, beskrivelse, d_type, debet, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$bogf_konto[$y]}', '{$fakturanr}', '{$pris[$y]}', 'on', '{$kladde_id}', '{$afd}', '{$tmpvaluta}', '{$projekt[$p]}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } elseif ($pris[$y] > 0) { db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$bogf_konto[$y]}', '{$fakturanr}', '{$pris[$y]}', 'on', '{$kladde_id}', '{$afd}', '{$tmpvaluta}', '{$projekt[$p]}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } } } } if ($art != 'RB') { if ($art != 'PO') { $r = db_fetch_array(db_select("select gruppe from adresser where id='{$konto_id}'", __FILE__ . " linje " . __LINE__)); $r = db_fetch_array(db_select("select box1 from grupper where art='DG' and kodenr='{$r['gruppe']}'", __FILE__ . " linje " . __LINE__)); $momsgruppe = substr(trim($r['box1']), 1, 1); } $r = db_fetch_array(db_select("select box1 from grupper where art='SM' and kodenr='{$momsgruppe}'", __FILE__ . " linje " . __LINE__)); $box1 = trim($r['box1']); if ($moms && $box1) { db_modify("insert into kassekladde (bilag, transdate, beskrivelse, k_type, kredit, faktura, amount, momsfri, kladde_id, afd, valuta, projekt, ansat, ordre_id) values ('{$bilag}', '{$transdate}', '{$beskrivelse}', 'F', '{$box1}', '{$fakturanr}', '{$moms}', 'on', '{$kladde_id}', '{$afd}', '{$valuta}', '{$projekt['0']}', '{$ansat}', '{$ordre_id}')", __FILE__ . " linje " . __LINE__); } } } db_modify("update ordrer set status=4 where id={$id}", __FILE__ . " linje " . __LINE__); db_modify("delete from ordrelinjer where ordre_id={$id} and posnr < 0", __FILE__ . " linje " . __LINE__); } else { print "<BODY onLoad=\"javascript:alert('Ordredato uden for regnskabsår!')\">"; } } transaktion("commit"); #exit; }
function send_mails($kontoantal, $konto_id, $email, $fra, $til) { global $db; global $brugernavn; global $bgcolor; global $bgcolor5; global $charset; ini_set("include_path", ".:../phpmailer"); require "class.phpmailer.php"; $tmpmappe = "../temp/{$db}/" . str_replace(" ", "_", $brugernavn); mkdir($tmpmappe); for ($x = 1; $x <= $kontoantal; $x++) { mkdir("{$tmpmappe}/{$x}"); if ($konto_id[$x] && $email[$x] && $fra[$x] && $til[$x] && strpos($email[$x], '@')) { $fromdate[$x] = usdate($fra[$x]); $todate[$x] = usdate($til[$x]); $mailtext = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTMP 4.01 Transitional//EN\">\n"; $mailtext .= "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\">\n"; $row = db_fetch_array(db_select("select firmanavn from adresser where art = 'S'", __FILE__ . " linje " . __LINE__)); $mailtext .= "<title>Kontoudtog fra {$row['firmanavn']}</title></head>\n"; $mailtext .= "<body bgcolor={$bgcolor} link='#000000' vlink='#000000' alink='#000000' center=''>\n"; $mailtext .= "<table width = 100% cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tbody>\n"; $mailtext .= "<tr><td colspan=\"5\"><b>{$row['firmanavn']}</b></td><td colspan=\"2\" align=\"right\">Dato</td><td align=right> " . date('d-m-Y') . "</td></tr>\n"; $mailtext .= "<tr><td colspan=8><hr></td></tr>\n"; $mailtext .= "<tr><td colspan=\"8\" style=\"font-size:115%;font-weight:bold\">Kontoudtog</td></tr>\n"; $row = db_fetch_array(db_select("select * from adresser where id={$konto_id[$x]}", __FILE__ . " linje " . __LINE__)); $mailtext .= "<tr><td colspan=\"5\">{$row['firmanavn']}</td><td colspan=\"2\" align=\"right\">Kontonr.</td><td align=right> {$row['kontonr']}</td></tr>\n"; $mailtext .= "<tr><td colspan=\"8\">{$row['addr1']}</td></tr>\n"; if ($row[addr2]) { $mailtext .= "<tr><td colspan=\"8\">{$row['addr2']}</td></tr>\n"; } $mailtext .= "<tr><td colspan=\"8\">{$row['postnr']} {$row['bynavn']}</td></tr>\n"; $mailtext .= "<tr><td><br></td></tr>\n"; $mailtext .= "<tr><td width=\"10%\"> Dato</td><td width=\"5%\"> Bilag</td><td width=\"5%\"> Faktura</td><td width=\"40%\" align=\"center\"> Tekst</td><td> Forfaldsdato</td><td width=\"10%\" align=\"right\"> Debet</td><td width=\"10%\" align=\"right\"> Kredit</td><td width=\"10%\" align=\"right\"> Saldo</td></tr>\n"; $mailtext .= "<tr><td colspan=8><hr></td></tr>\n"; $betalingsbet = trim($row['betalingsbet']); $betalingsdage = $row['betalingsdage']; $kontosum = 0; $primo = 0; $primoprint = 0; $query = db_select("select * from openpost where konto_id={$konto_id[$x]} and transdate<='{$todate[$x]}' order by transdate, faktnr", __FILE__ . " linje " . __LINE__); while ($row = db_fetch_array($query)) { $amount = afrund($row['amount'], 2); $forfaldsdag = NULL; if ($row['forfaldsdate']) { $forfaldsdag = dkdato($row['forfaldsdate']); } if ($row['transdate'] < $fromdate[$x]) { $primoprint = 0; $kontosum = $kontosum + $amount; } else { if ($primoprint == 0) { $tmp = dkdecimal($kontosum); $linjebg = $bgcolor5; $color = '#000000'; $mailtext .= "<tr bgcolor=\"{$linjebg}\"><td colspan=\"3\"></td><td>Primosaldo</td><td colspan=\"3\"></td><td align=right> {$tmp}</td></tr>\n"; $primoprint = 1; } if ($linjebg != $bgcolor) { $linjebg = $bgcolor; $color = '#000000'; } elseif ($linjebg != $bgcolor5) { $linjebg = $bgcolor5; $color = '#000000'; } $mailtext .= "<tr bgcolor=\"{$linjebg}\"><td> " . dkdato($row['transdate']) . " </td><td> {$row['refnr']} </td><td> {$row['faktnr']} </td><td> {$row['beskrivelse']}</td>\n"; if ($amount < 0) { $tmp = 0 - $amount; } else { $tmp = $amount; } $tmp = dkdecimal($tmp); if (!$forfaldsdag) { $forfaldsdag = forfaldsdag($row['transdate'], $betalingsbet, $betalingsdage); } if ($row[udlignet] != '1' && $forfaldsdag < $currentdate) { $stil = "<span style='color: rgb(255, 0, 0);'>"; } else { $stil = "<span style='color: rgb(0, 0, 0);'>"; } if ($amount > 0) { $mailtext .= "<td>{$stil}{$forfaldsdag}</td><td align=right>{$stil} {$tmp}</td><td></td>\n"; $forfaldsum = $forfaldsum + $amount; } else { $mailtext .= "<td></td><td></td><td align=right>{$stil}{$tmp}</td>\n"; } $kontosum = $kontosum + $amount; $tmp = dkdecimal($kontosum); $mailtext .= "<td align=right> {$tmp}</td>\n"; $mailtext .= "</tr>\n"; } } if ($primoprint == 0) { $tmp = dkdecimal($kontosum); $mailtext .= "<tr><td></td><td></td><td></td><td> Primosaldo</td><td></td><td></td><td></td><td align=right> {$tmp}</td></tr>\n"; } $mailtext .= "<tr><td colspan=\"8\"><hr></td></tr>\n"; $row = db_fetch_array(db_select("select * from adresser where art = 'S'", __FILE__ . " linje " . __LINE__)); $mailtext .= "<tr><td colspan=\"8\">\n"; if ($row['bank_konto']) { $mailtext .= "<p>Et eventuelt udestående bedes indbetalt hurtigst muligt på vores bankkonto med\n"; if ($row['bank_reg']) { $mailtext .= " reg.nr. " . $row['bank_reg'] . " og"; } $mailtext .= " kontonr. " . $row['bank_konto']; if ($row['bank_navn']) { $mailtext .= " i " . $row['bank_navn']; } $mailtext .= ".</p>\n"; } if ($row['tlf']) { $mailtext .= "<p>Hvis du har spørgsmål, så kontakt os på telefon " . $row['tlf']; $mailtext .= ".</p>\n</td></tr>\n"; } $mailtext .= "<tr><td colspan=\"8\"><hr></td></tr>\n"; $mailtext .= "<tr><td colspan=\"8\" align=\"center\">\n"; $mailtext .= "<p style=\"font-size:80%\">" . $row['firmanavn']; if ($row['addr1']) { $mailtext .= " * " . $row['addr1']; } if ($row['addr2']) { $mailtext .= " * " . $row['addr2']; } if ($row['postnr']) { $mailtext .= " * " . $row['postnr'] . " " . $row['bynavn']; } if ($row['tlf']) { $mailtext .= " * tlf " . $row['tlf']; } if ($row['fax']) { $mailtext .= " * fax " . $row['fax']; } if ($row['cvr']) { $mailtext .= " * cvr " . $row['fax']; } $mailtext .= "<p>\n</td></tr>\n"; $mailtext .= "</table></body></html>\n"; #echo "select * from adresser where art='S'<br>"; $row = db_fetch_array(db_select("select * from adresser where art='S'", __FILE__ . " linje " . __LINE__)); $afsendermail = $row['email']; $afsendernavn = $row['firmanavn']; #echo "AFSM $afsendermail<br>"; if ($charset == "UTF-8") { $subjekt = utf8_decode($subjekt); $mailtext = utf8_decode($mailtext); $afsendernavn = utf8_decode($afsendernavn); $afsendermail = utf8_decode($afsendermail); #echo "MM $mailtext<br>"; } $fp = fopen("{$tmpmappe}/{$x}/kontoudtog.html", "w"); fwrite($fp, $mailtext); fclose($fp); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "localhost"; // SMTP servers $mail->SMTPAuth = false; // turn on SMTP authentication if (strpos($_SERVER['SERVER_NAME'], 'saldi.dk')) { #20121029 if ($_SERVER['SERVER_NAME'] == 'ssl.saldi.dk') { $mail->From = $db . '@ssl.saldi.dk'; } elseif ($_SERVER['SERVER_NAME'] == 'ssl2.saldi.dk') { $mail->From = $db . '@ssl2.saldi.dk'; } elseif ($_SERVER['SERVER_NAME'] == 'ssl3.saldi.dk') { $mail->From = $db . '@ssl3.saldi.dk'; } else { $mail->From = '*****@*****.**'; } #20140128 $mail->FromName = $afsendernavn; } else { $mail->From = $afsendermail; $mail->FromName = $afsendernavn; } if (strpos($email[$x], ";")) { #20150305-2 $tmp = array(); $tmp = explode(";", $email[$x]); for ($i = 0; $i < count($tmp); $i++) { if (strpos($tmp[$i], "@")) { $mail->AddAddress($tmp[$i]); } } } else { $mail->AddAddress($email[$x]); } $mail->AddBCC($afsendermail); $mail->AddReplyTo($afsendermail, $afsendernavn); $mail->WordWrap = 50; // set word wrap $mail->AddAttachment("{$tmpmappe}/{$x}/kontoudtog.html"); // attachment $mail->IsHTML(true); // send as HTML $mail->Subject = "Kontoudtog fra {$afsendernavn}"; $mailbody = "<html><body>\n"; $mailbody .= "<p>Hermed fremsendes kontoudtog fra " . $afsendernavn . ".</p>\n"; $mailbody .= "<p>Den vedlagte fil er en HTML-fil og kan ses i din webbrowser eksempelvis \n"; $mailbody .= "ved at dobbeltklikke på den.</p>\n"; $mailbody .= "<hr />\n<p>"; $mailbody .= $row['firmanavn'] . "<br />\n"; if ($row['addr1']) { $mailbody .= $row['addr1'] . "<br />\n"; } if ($row['addr2']) { $mailbody .= $row['addr2'] . "<br />\n"; } if ($row['postnr']) { $mailbody .= $row['postnr'] . " " . $row['bynavn'] . "<br />\n"; } if ($row['tlf']) { $mailbody .= "tlf " . $row['tlf']; } if ($row['fax']) { $mailbody .= " * fax " . $row['fax']; } if ($row['cvr']) { $mailbody .= " * cvr " . $row['fax']; } $mailbody .= "</p></body></html>"; $mailaltbody = "Hermed fremsendes kontoudtog fra " . $afsendernavn . ".\n\n"; $mailaltbody .= "Den vedlagte fil er en HTML-fil og kan ses i din webbrowser eksempelvis \n"; $mailaltbody .= "ved at dobbeltklikke på den.\n"; $mailaltbody .= "-- \n"; $mailaltbody .= $row['firmanavn'] . "\n"; if ($row['addr1']) { $mailaltbody .= $row['addr1'] . "\n"; } if ($row['addr2']) { $mailaltbody .= $row['addr2'] . "\n"; } if ($row['postnr']) { $mailaltbody .= $row['postnr'] . " " . $row['bynavn'] . "\n"; } if ($row['tlf']) { $mailaltbody .= "tlf " . $row['tlf']; } if ($row['fax']) { $mailaltbody .= " * fax " . $row['fax']; } if ($row['cvr']) { $mailaltbody .= " * cvr " . $row['fax']; } if ($charset == "UTF-8") { $mailbody = utf8_decode($mailbody); $mailaltbody = utf8_decode($mailaltbody); } $mail->Body = $mailbody; $mail->AltBody = $mailaltbody; if (!$mail->Send()) { echo "Fejl i afsendelse til {$email[$x]}<p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Kontoudtog sendt til {$email[$x]}<br>"; # sleep(2); } } for ($x = 1; $x <= $kontoantal; $x++) { unlink("{$tmpmappe}/{$x}/kontoudtog.html"); rmdir("{$tmpmappe}/{$x}"); } # unlink("$tmpmappe/kontoudtog.html"); rmdir($tmpmappe); }
#cho "$r1[transdate] $saldo $r1[amount]<br>"; $debet = 0; $kredit = 0; $r1['amount'] >= 0 ? $debet = $r1['amount'] : ($kredit = $r1['amount'] * -1); $saldo += $debet - $kredit; if (!$r1['valuta']) { $r1['valuta'] = 'DKK'; } if (!$r1['valutakurs']) { $r1['valutakurs'] = 100; } $valuta = $r1['valuta']; $valutakurs = $r1['valutakurs'] * 1; $dkkamount = $r1['amount'] * 100 / $valutakurs; if ($debet) { $forfaldsdato = forfaldsdag($r1['transdate'], $betalingsbet, $betalingsdage); } else { $forfaldsdato = NULL; } if ($deb_valuta != "DKK" && $deb_valuta != $valuta) { $amount = $dkkamount * 100 / $deb_valutakurs; } elseif ($deb_valuta == $valuta) { $amount = $r2['amount']; } else { $amount = $dkkamount; } if ($deb_valuta == 'DKK') { $amount = $dkkamount; } # $saldo+=$amount; 20150316 $dkkforfalden += $dkkamount;
$mailmodt_id = $r['box1']; $email = $r['box2']; $ffdage = $r['box5']; $chkdate = $r['box8']; if (!$ffdage || $chkdate == $dd) { echo ''; } else { $rykkerdate = usdate(forfaldsdag($dd, 'netto', $ffdage)); $x = 0; $konto_id = array(); $x = 0; # $q=db_select("select openpost.* from openpost,adresser where openpost.udlignet = '0' and openpost.forfaldsdate >= '$rykkerdate' and openpost.amount>'0' and adresser.id=openpost.konto_id and adresser.art = 'D' order by openpost.konto_id",__FILE__ . " linje " . __LINE__); $q = db_select("select openpost.* from openpost,adresser where openpost.udlignet = '0' and openpost.amount>'0' and adresser.id=openpost.konto_id and adresser.art = 'D' order by openpost.konto_id", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { # echo "$r[forfaldsdate] <= $dd<br>"; $rykkerdate = usdate(forfaldsdag($r['forfaldsdate'], 'netto', $ffdage)); # echo "$rykkerdate <= $dd<br>"; if ($rykkerdate <= $dd) { if (!db_fetch_array(db_select("select id from ordrelinjer where enhed = '{$r['id']}'", __FILE__ . " linje " . __LINE__))) { #Tjekker om der allerede eksisterer en rykker på ordren. if (!in_array($r['konto_id'], $konto_id)) { $konto_id[$x] = $r['konto_id']; #Liste over konto id numre der skal rykkes $x++; } } } } $ff_antal = $x; #echo "$ff_antal $rykkerdate <br>"; #exit;
function bogfor_nu($id, $webservice) { include "../includes/genberegn.php"; include "../includes/forfaldsdag.php"; global $db; global $regnaar; global $valuta; global $valutakurs; global $difkto; global $title; # print "<table><tbody>"; $svar = "OK"; $d_kontrol = 0; $k_kontrol = 0; $logdate = date("Y-m-d"); $logtime = date("H:i"); $q = db_select("select box1, box2, box3, box4, box5 from grupper where art='RB'", __FILE__ . " linje " . __LINE__); if ($r = db_fetch_array($q)) { if (trim($r['box3']) == "on") { $faktbill = 1; } else { $faktbill = 0; } if (trim($r['box4']) == "on") { $modtbill = 1; } else { $modtbill = 0; } if (trim($r['box5']) == "on") { $no_faktbill = 1; $faktbill = 0; } else { $no_faktbill = 0; } } $projekt = array(); $x = 0; $q = db_select("select * from ordrer where id='{$id}'", __FILE__ . " linje " . __LINE__); if ($r = db_fetch_array($q)) { $art = $r['art']; $konto_id = $r['konto_id']; $kontonr = str_replace(" ", "", $r['kontonr']); $firmanavn = trim($r['firmanavn']); $modtagelse = $r['modtagelse']; $transdate = $r['fakturadate']; $fakturanr = $r['fakturanr']; $ordrenr = $r['ordrenr']; #echo "$firmanavn | $ordrenr<br>"; $valuta = $r['valuta']; $kred_ord_id = $r['kred_ord_id']; if (!$valuta) { $valuta = 'DKK'; } $projekt[0] = $r['projekt'] * 1; $betalingsbet = $r['betalingsbet']; $betalingsdage = $r['betalingsdage'] * 1; # $refnr; $moms = $r['moms'] * 1; # else {$moms=afrund($r['sum']*$r['momssats']/100,2);} $sum = $r['sum'] + $moms; #echo "sum $r[sum] + $moms = $sum<br>"; #exit; $ordreantal = $x; $forfaldsdate = usdate(forfaldsdag($r['fakturadate'], $betalingsbet, $betalingsdage)); $r2 = db_fetch_array(db_select("select id, afd from ansatte where navn = '{$r['ref']}'", __FILE__ . " linje " . __LINE__)); $afd = $r2['afd'] * 1; #sikkerhed for at 'afd' har en vaerdi $ansat = $r2['id'] * 1; if ($no_faktbill == 1) { $bilag = '0'; } else { $bilag = trim($fakturanr); } $udlign = 0; if (substr($art, 1, 1) == 'K') { $beskrivelse = "Kreditnota - " . $fakturanr; $r = db_fetch_array(db_select("select fakturanr,fakturadate from ordrer where id='{$kred_ord_id}'", __FILE__ . " linje " . __LINE__)); $tmp = $sum * -1; if (db_fetch_array(db_select("select * from openpost where konto_id='{$konto_id}' and amount='{$tmp}' and faktnr='{$r['fakturanr']}' and transdate='{$r['fakturadate']}' and udlignet != '1'", __FILE__ . " linje " . __LINE__))) { db_modify("update openpost set udlignet = 1 where konto_id='{$konto_id}' and amount='{$tmp}' and faktnr='{$r['fakturanr']}' and transdate='{$r['fakturadate']}'"); $udlign = 1; } } elseif ($art == 'PO') { $beskrivelse = "Bon - " . $fakturanr; } else { $beskrivelse = "Faktura - " . $fakturanr; } if ($art != 'PO') { db_modify("insert into openpost (konto_id, konto_nr, faktnr, amount, beskrivelse, udlignet, transdate, kladde_id, refnr, valuta, valutakurs, forfaldsdate) values ('{$konto_id}', '{$kontonr}', '{$fakturanr}', '{$sum}', '{$beskrivelse}', '{$udlign}', '{$transdate}', '{$udlign}', '{$id}', '{$valuta}', '{$valutakurs}','{$forfaldsdate}')", __FILE__ . " linje " . __LINE__); $r = db_fetch_array(db_select("select gruppe from adresser where id='{$konto_id}'", __FILE__ . " linje " . __LINE__)); $r = db_fetch_array(db_select("select beskrivelse, box2 from grupper where art = 'DG' and kodenr='{$r['gruppe']}'", __FILE__ . " linje " . __LINE__)); $kontonr = $r['box2']; # Kontonr aendres fra at vaere leverandoerkontonr til finanskontonr $tekst = "Kontonummer for Debitorgruppe `{$r['beskrivelse']}` er ikke gyldigt"; if (!$kontonr && $webservice) { return $tekst; } elseif (!$kontonr) { print "<BODY onLoad=\"javascript:alert('{$tekst}')\">"; } } else { $kontonr = "58200"; } # midleritdig kun til brug med POS if ($sum > 0) { $debet = $sum; $kredit = '0'; } else { $debet = '0'; $kredit = $sum * -1; } if ($valutakurs) { $kredit = afrund($kredit * $valutakurs / 100, 3); $debet = afrund($debet * $valutakurs / 100, 3); } # Omregning til DKR. $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); #echo "A insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '$transdate', '$beskrivelse', '$kontonr', '$fakturanr', '$debet', '$kredit', '0', $afd, '$logdate', '$logtime', '$projekt[0]', '$ansat', '$id')<br>"; db_modify("insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '{$transdate}', '{$beskrivelse}', '{$kontonr}', '{$fakturanr}', '{$debet}', '{$kredit}', '0', {$afd}, '{$logdate}', '{$logtime}', '{$projekt['0']}', '{$ansat}', '{$id}')", __FILE__ . " linje " . __LINE__); if ($valutakurs) { $maxdif = 2; } #Der tillades 2 oeres afrundingsdiff $p = 0; $q = db_select("select distinct(projekt) from ordrelinjer where ordre_id={$id} and vare_id >\t'0'", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $p++; $projekt[$p] = $r['projekt'] * 1; } $projektantal = $p; for ($t = 1; $t <= 2; $t++) { for ($p = 1; $p <= $projektantal; $p++) { $y = 0; $tjek = array(); $bogf_konto = array(); if ($t == 1) { #echo "select * from ordrelinjer where ordre_id='$id' and projekt='$projekt[$p]' and posnr>=0<br>"; $q = db_select("select * from ordrelinjer where ordre_id='{$id}' and projekt='{$projekt[$p]}' and posnr>=0", __FILE__ . " linje " . __LINE__); } else { #echo "select * from ordrelinjer where ordre_id='$id' and projekt='$projekt[$p]' and posnr<0<br>"; $q = db_select("select * from ordrelinjer where ordre_id='{$id}' and projekt='{$projekt[$p]}' and posnr<0", __FILE__ . " linje " . __LINE__); } while ($r = db_fetch_array($q)) { if ($valutakurs) { $maxdif = $maxdif + 2; } #Og yderligere 2 pr ordrelinje. $tmp = $projekt[$p] . ":" . $r['bogf_konto']; if (!in_array($r['bogf_konto'], $bogf_konto)) { $y++; $bogf_konto[$y] = $r['bogf_konto']; $pris[$y] = $r['pris'] * $r['antal'] - $r['pris'] * $r['antal'] * $r['rabat'] / 100; $pris[$y] = afrund($pris[$y], 3); #Afrunding tilfoejet 2009.01.26 grundet diff i ordre 98 i saldi_104 } else { for ($a = 1; $a <= $y; $a++) { if ($bogf_konto[$a] == $r['bogf_konto']) { $pris[$a] = $pris[$a] + ($r['pris'] * $r['antal'] - $r['pris'] * $r['antal'] * $r['rabat'] / 100); $pris[$a] = afrund($pris[$a], 3); #Afrunding tilfoejet 2009.01.26 grundet diff i ordre 98 i saldi_104 } } } } $ordrelinjer = $y; #echo "ol $ordrelinjer<br>"; for ($y = 1; $y <= $ordrelinjer; $y++) { if ($bogf_konto[$y]) { if ($pris[$y] > 0) { $kredit = $pris[$y]; $debet = 0; } else { $kredit = 0; $debet = $pris[$y] * -1; } if ($t == 1 && $valutakurs) { $kredit = $kredit * $valutakurs / 100; $debet = $debet * $valutakurs / 100; } # Omregning til DKR. $kredit = afrund($kredit, 3); $debet = afrund($debet, 3); $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); #echo "B insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '$transdate', '$beskrivelse', '$bogf_konto[$y]', '$fakturanr', '$debet', '$kredit', '0','$afd', '$logdate', '$logtime', '$projekt[$p]', '$ansat', '$id')<br>"; db_modify("insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '{$transdate}', '{$beskrivelse}', '{$bogf_konto[$y]}', '{$fakturanr}', '{$debet}', '{$kredit}', '0','{$afd}', '{$logdate}', '{$logtime}', '{$projekt[$p]}', '{$ansat}', '{$id}')", __FILE__ . " linje " . __LINE__); } } } } $query = db_select("select gruppe from adresser where id='{$konto_id}';", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $query = db_select("select box1 from grupper where art='DG' and kodenr='{$row['gruppe']}';", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $box1 = substr(trim($row[box1]), 1, 1); $query = db_select("select box1 from grupper where art='SM' and kodenr='{$box1}'", __FILE__ . " linje " . __LINE__); $row = db_fetch_array($query); $box1 = trim($row['box1']); if ($moms > 0) { $kredit = $moms; $debet = '0'; } else { $kredit = '0'; $debet = $moms * -1; } if ($valutakurs) { $kredit = afrund($kredit * $valutakurs / 100, 3); $debet = afrund($debet * $valutakurs / 100, 3); } # Omregning til DKR. $kredit = afrund($kredit, 3); $debet = afrund($debet, 3); $d_kontrol = $d_kontrol + $debet; $k_kontrol = $k_kontrol + $kredit; $diff = afrund($d_kontrol - $k_kontrol, 3); $absdiff = abs($diff); if ($moms && $valutakurs && $valutakurs != 100 && $absdiff >= 0.01 && $absdiff <= 0.05) { if ($debet > 0) { $debet = $debet + $diff; $d_kontrol = $d_kontrol + $diff; } elseif ($kredit > 0) { $kredit = $kredit + $diff; $k_kontrol = $k_kontrol + $diff; } } #echo "moms $moms<br>"; $moms = afrund($moms, 2); #echo "C insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '$transdate', '$beskrivelse', '$box1', '$fakturanr', '$debet', '$kredit', '0', '$afd', '$logdate', '$logtime', '$projekt[0]', '$ansat', '$id')<br>"; if ($moms) { db_modify("insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '{$transdate}', '{$beskrivelse}', '{$box1}', '{$fakturanr}', '{$debet}', '{$kredit}', '0', '{$afd}', '{$logdate}', '{$logtime}', '{$projekt['0']}', '{$ansat}', '{$id}')", __FILE__ . " linje " . __LINE__); } $valutakurs = $valutakurs * 1; #echo "update ordrer set status=4, valutakurs=$valutakurs where id=$id<br>"; db_modify("update ordrer set status=4, valutakurs={$valutakurs} where id={$id}", __FILE__ . " linje " . __LINE__); db_modify("delete from ordrelinjer where ordre_id={$id} and posnr < 0", __FILE__ . " linje " . __LINE__); } $d_kontrol = afrund($d_kontrol, 2); $k_kontrol = afrund($k_kontrol, 2); #echo "$d_kontrol $k_kontrol<br>"; if ($diff = afrund($d_kontrol - $k_kontrol)) { if ($valuta != 'DKK' && abs($diff) <= $maxdif) { #Der maa max vaere en afvigelse paa 1 oere pr ordrelinje m fremmed valuta; $debet = 0; $kredit = 0; if ($diff < 0) { $debet = $diff * -1; } else { $kredit = $diff; } $debet = afrund($debet, 2); $kredit = afrund($kredit, 2); #echo "D insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '$transdate', '$beskrivelse', '$difkto', '$fakturanr', '$debet', '$kredit', '0', '$afd', '$logdate', '$logtime', '$projekt[0]', '$ansat', '$id')<br>"; db_modify("insert into transaktioner (bilag, transdate, beskrivelse, kontonr, faktura, debet, kredit, kladde_id, afd, logdate, logtime, projekt, ansat, ordre_id) values ('0', '{$transdate}', '{$beskrivelse}', '{$difkto}', '{$fakturanr}', '{$debet}', '{$kredit}', '0', '{$afd}', '{$logdate}', '{$logtime}', '{$projekt['0']}', '{$ansat}', '{$id}')", __FILE__ . " linje " . __LINE__); } else { # echo "Id $id<br>"; # echo "D $d_kontrol K $k_kontrol<br>"; $message = $db . " | Uoverensstemmelse i posteringssum: ordre_id={$id}, d={$d_kontrol}, k={$k_kontrol} | " . __FILE__ . " linje " . __LINE__ . " | " . $brugernavn . " " . date("Y-m-d H:i:s"); $headers = 'From: fejl@saldi.dk' . "\r\n" . 'Reply-To: fejl@saldi.dk' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail('*****@*****.**', 'SALDI Fejl', $message, $headers); if (!$webservice) { print "<BODY onLoad=\"javascript:alert('Der er konstateret en uoverensstemmelse i posteringssummen, ordre {$ordrenr}, kontakt DANOSOFT på telefon 4690 2208')\">"; } else { return "Der er konstateret en uoverensstemmelse i posteringssummen, ordre {$ordrenr}, kontakt DANOSOFT på telefon 4690 2208' debet {$debet} != kredit {$kredit}"; } # print "<meta http-equiv=\"refresh\" content=\"0;URL=ordre.php?id=$id\">"; exit; } } if ($title != "Massefakturering" && !$webservice) { genberegn($regnaar); } return $svar; }
function kontokort($dato_fra, $dato_til, $konto_fra, $konto_til, $rapportart, $kontoart) { # global $connection; global $bruger_id; global $top_bund; global $md; global $popup; # global $returside; # global $rapportart; global $bgcolor; global $bgcolor5; global $regnaar; global $menu; $uudlign = if_isset($_GET['uudlign']); if ($uudlign) { db_modify("update openpost set udlignet='0',udlign_id='0' where udlign_id='{$uudlign}'", __FILE__ . " linje " . __LINE__); } $r = db_fetch_array(db_select("select box1, box2, box3, box4 from grupper where art='RA' and kodenr='{$regnaar}'", __FILE__ . " linje " . __LINE__)); $regnstart = "01-" . trim($r['box1']) . "-" . trim($r['box2']); $tmp = 31; while (!checkdate(trim($r['box3']), $tmp, trim($r['box4']))) { $tmp--; if ($tmp < 28) { break 1; } } $regnslut = $tmp . "-" . trim($r['box3']) . "-" . trim($r['box4']); $difflink = 0; $kontoart = trim($kontoart); $kilde = if_isset($_GET['kilde']); $kilde_kto_fra = if_isset($_GET['kilde_kto_fra']); $kilde_kto_til = if_isset($_GET['kilde_kto_til']); if ($kontoart == 'K') { $returnpath = "../kreditor/"; } else { $returnpath = "../debitor/"; } $tmp = $konto_fra; # #cho $_GET['returside']; $kontoart == 'D' ? $tekst = 'DRV' : ($tekst = 'KRV'); if (isset($_GET['returside'])) { $returside = $_GET['returside']; } elseif ($r = db_fetch_array(db_select("select * from grupper where art = '{$tekst}' and kodenr = '{$bruger_id}'", __FILE__ . " linje " . __LINE__))) { $dato_fra = $r['box2']; $dato_til = $r['box3']; $konto_fra = $r['box4']; $konto_til = $r['box5']; $rapportart = $r['box6']; } if ($r = db_fetch_array(db_select("select id from grupper where art = 'PRJ'", __FILE__ . " linje " . __LINE__))) { $prj = 'Projekt'; } else { $prj = ''; } if ($tmp && $tmp != $konto_fra && !$returside) { $returside = "rapport.php?rapportart={$rapportart}"; #&submit=ok®naar=$regnaar&dato_fra=$dato_fra&dato_til=$dato_til&konto_fra=$konto_fra&konto_til=$konto_til"; $konto_fra = $tmp; $konto_til = $konto_fra; } elseif (!$returside) { $returside = "rapport.php?dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}"; } if ($dato_fra && $dato_til) { $fromdate = usdate($dato_fra); $todate = usdate($dato_til); } elseif ($dato_fra && !$dato_til) { # $fromdate=usdate($dato_fra); $todate = usdate($dato_fra); } $luk = "<a accesskey=L href=\"{$returside}\">"; print "<table width = 100% cellpadding=\"1\" cellspacing=\"1\" border=\"0\"><tbody>"; if ($menu == 'T') { $leftbutton = "<a title=\"Klik her for at komme til startsiden\" href=\"../debitor/rapport.php\" accesskey=\"L\">LUK</a>"; $rightbutton = NULL; $vejledning = NULL; include "../includes/topmenu.php"; print "<div id=\"topmenu\" style=\"position:absolute;top:6px;right:0px\">"; } elseif ($menu == 'S') { include "../includes/sidemenu.php"; } else { print "<tr><td colspan=\"9\" height=\"8\">"; print "<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\"><tbody>"; #B print "<td width=\"10%\" {$top_bund}>{$luk} Luk</a></td>"; if ($kontoart == 'K') { $tekst = "Kreditorrapport - kontokort"; } else { $tekst = "Debitorapport - kontokort"; } print "<td width=\"80%\" {$top_bund}>{$tekst}</td>"; # print "<td width=\"10%\" $top_bund><a href=kontoprint.php?dato_fra=$dato_fra&dato_til=$dato_til&konto_fra=$konto_fra&konto_til=$konto_til&kontoart=$kontoart>Udskriv</a></td>"; print "<td width=\"10%\" {$top_bund} onClick=\"javascript:kontoprint=window.open('kontoprint.php?dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&kontoart={$kontoart}','kontoprint' ,'left=10,top=10,width=800,height=400,scrollbars=yes,resizable=yes,menubar=no,location=no');\"onMouseOver=\"this.style.cursor = 'pointer'\" title=\"'Udskriv kontoudtog som PDF'\">Udskriv</td>\n"; print "</tbody></table>"; #B s**t print "</td></tr>\n"; } if (is_numeric($konto_fra) && is_numeric($konto_til)) { $tekst = "select id from adresser where " . nr_cast('kontonr') . ">='{$konto_fra}' and " . nr_cast('kontonr') . "<='{$konto_til}' and art = '{$kontoart}' order by " . nr_cast('kontonr') . ""; } elseif ($konto_fra && $konto_fra != '*') { $konto_fra = str_replace("*", "%", $konto_fra); $tmp1 = strtolower($konto_fra); $tmp2 = strtoupper($konto_fra); $tekst = "select id from adresser where (firmanavn like '{$konto_fra}' or lower(firmanavn) like '{$tmp1}' or upper(firmanavn) like '{$tmp2}') and art = '{$kontoart}' order by firmanavn"; } else { $tekst = "select id from adresser where art = '{$kontoart}' order by firmanavn"; } $kontonr = array(); $x = 0; $query = db_select("{$tekst}", __FILE__ . " linje " . __LINE__); while ($row = db_fetch_array($query)) { $x++; $konto_id[$x] = $row['id']; } $kto_id = array(); $kontoantal = $x; $x = 0; # finder alle konti med bevaegelser i den anfoerte periode eller aabne poster fra foer perioden if ($kontoantal == 1) { #20140505 - Fjerner udligning hvis udligningssum er skæv. $y = 0; $qtxt = "select distinct(udlign_id) from openpost where udlignet = '1' and udlign_id>'0' and konto_id='{$konto_id['1']}'"; $q = db_select("{$qtxt}", __FILE__ . " linje " . __LINE__); while ($r = db_fetch_array($q)) { $udlign_id[$y] = $r['udlign_id'] * 1; $y++; } /* for ($y=0;$y<count($udlign_id);$y++){ $sum=0; $qtxt="select amount,valutakurs from openpost where udlign_id = '$udlign_id[$y]' and konto_id='$konto_id[1]'"; $q=db_select("$qtxt",__FILE__ . " linje " . __LINE__); while ($r=db_fetch_array($q)) { if ($r['valutakurs']) $sum+=afrund($r['amount']*$r['valutakurs']/100,2); else $sum+=afrund($r['amount'],2); } if (afrund($sum,2)*1) { db_modify("update openpost set udlignet='0', udlign_id='0' where udlign_id = '$udlign_id[$y]' and konto_id='$konto_id[1]'"); } } */ } for ($y = 1; $y <= $kontoantal; $y++) { # if ($fromdate && $todate) $query = db_select("select amount from openpost where transdate>='$fromdate' and transdate<='$todate' and konto_id='$konto_id[$y]'",__FILE__ . " linje " . __LINE__); if ($todate) { $tekst = "select amount from openpost where transdate<='{$todate}' and konto_id='{$konto_id[$y]}'"; } else { $tekst = "select amount from openpost where konto_id='{$konto_id[$y]}'"; } #cho $tekst; $query = db_select("{$tekst}", __FILE__ . " linje " . __LINE__); while ($row = db_fetch_array($query)) { if (!in_array($konto_id[$y], $kto_id)) { $x++; $kto_id[$x] = $konto_id[$y]; } } } $kontoantal = $x; for ($x = 1; $x <= $kontoantal; $x++) { $q = db_select("select * from adresser where id={$kto_id[$x]}", __FILE__ . " linje " . __LINE__); $r = db_fetch_array($q); $art = trim($r['art']) . "G"; $betalingsbet = trim($r['betalingsbet']); $betalingsdage = $r['betalingsdage']; $r2 = db_fetch_array(db_select("select box3 from grupper where art='{$art}' and kodenr='{$r['gruppe']}'", __FILE__ . " linje " . __LINE__)); $valuta = trim($r2['box3']); if (!$valuta) { $valuta = 'DKK'; } else { $r2 = db_fetch_array(db_select("select kodenr from grupper where box1 = '{$valuta}' and art='VK'", __FILE__ . " linje " . __LINE__)); $valutakode = $r2['kodenr']; } $valutakode *= 1; #20140505 # print "<tr><td colspan=8><hr></td></tr>\n"; print "<tr><td colspan=9><hr></td></tr>\n"; print "<tr><td><br></td></tr>\n"; print "<tr><td><br></td></tr>\n"; print "<tr><td colspan=3>" . stripslashes($r['firmanavn']) . "</td></tr>\n"; print "<tr><td colspan=3>" . stripslashes($r['addr1']) . "</td></tr>\n"; print "<tr><td colspan=3>" . stripslashes($r['addr2']) . "</td><td colspan=5 align=right>Kontonr</td><td align=right>{$r['kontonr']}</td></tr>\n"; print "<tr><td colspan=3>" . stripslashes($r['postnr']) . " " . stripslashes($r['bynavn']) . "</td><td colspan=5 align=right>Dato</td><td align=right>" . date('d-m-Y') . "</td></tr>\n"; print "<tr><td colspan=8 align=right>Valuta</td><td align=right>{$valuta}</td></tr>\n"; print "<tr><td><br></td></tr>\n"; print "<tr><td><br></td></tr>\n"; print "<tr><td>Dato</td><td>Bilag</td><td>Faktura</td><td>Tekst</td><td>{$prj}</td><td>Forfaldsdato</td><td align=right>Debet</td><td align=right>Kredit</td><td align=right>Saldo</td></tr>\n"; print "<tr><td colspan=9><hr></td></tr>\n"; $kontosum = 0; $primo = 0; $oppid = array(); $amount = array(); $beskrivelse = array(); $valutakurs = array(); $oppvaluta = array(); $faktnr = array(); $forfaldsdag = array(); $primoprint[$x] = 0; $baggrund = $bgcolor; $dkksum = 0; $y = 0; $qtxt = "select max(id) as max_valdif_id from openpost where konto_id='{$kto_id[$x]}' and abs(amount) = '0.001'"; $r2 = db_fetch_array(db_select("{$qtxt}", __FILE__ . " linje " . __LINE__)); $max_valdif_id = $r2['max_valdif_id']; if ($todate) { $qtxt = "select * from openpost where konto_id='{$kto_id[$x]}' and transdate<='{$todate}' order by transdate,id,faktnr,refnr"; } else { $qtxt = "select * from openpost where konto_id='{$kto_id[$x]}' order by transdate,id,faktnr,refnr"; } #20160414 $q2 = db_select("{$qtxt}", __FILE__ . " linje " . __LINE__); while ($r2 = db_fetch_array($q2)) { $y++; $baggrund == $bgcolor ? $baggrund = $bgcolor5 : ($baggrund = $bgcolor); $oppid[$y] = $r2['id']; $amount[$y] = afrund($r2['amount'], 2); $amount[$y] = $r2['amount']; #cho "ID $r2[id] Amount: $amount[$y]=".$r2['amount']."|".$r2['valutakurs']."<br>"; $beskrivelse[$y] = $r2['beskrivelse']; #cho "$r2[valutakurs]<br>"; $valutakurs[$y] = $r2['valutakurs'] * 1; $oppvaluta[$y] = $r2['valuta']; $faktnr[$y] = $r2['faktnr']; if (!$oppvaluta[$y]) { $oppvaluta[$y] = 'DKK'; $valutakurs[$y] = 100; #20140503 } #cho "$dkkamount[$y]=afrund($amount[$y]*$valutakurs[$y]/100,2)<br>"; #cho "$amount[$y] $oppvaluta[$y] DKK $dkkamount[$y]<br>"; $forfaldsdag[$y] = $r2['forfaldsdate']; $r2['projekt'] ? $projekt[$y] = $r2['projekt'] : ($projekt[$y] = ''); $r2['kladde_id'] ? $refnr[$y] = $r2['refnr'] : ($refnr[$y] = ''); if (!strlen($valutakurs[$y])) { $valutakurs[$y] = 100; } $transdate[$y] = $r2['transdate']; $udlignet[$y] = $r2['udlignet']; $udlign_id[$y] = $r2['udlign_id']; if ($oppvaluta[$y] != 'DKK' && $valutakurs[$y] == 100) { $r3 = db_fetch_array(db_select("select kodenr from grupper where box1 = '{$oppvaluta[$y]}' and art='VK'", __FILE__ . " linje " . __LINE__)); $r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$r3['kodenr']}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__)); $valutakurs[$y] = $r3['kurs'] * 1; $dkkamount[$y] = $amount[$y] * $valutakurs[$y] / 100; $beskrivelse[$y] = $r2['beskrivelse'] . " - (Omregnet fra DKK til {$valuta}" . dkdecimal($dkkamount[$y]) . ", kurs " . dkdecimal($valutakurs[$y]) . ")"; # db_modify("update openpost set valutakurs='$valutakurs[$y]' where id='$oppid[$y]'"); } elseif ($valuta != "DKK" && $valutakurs[$y] == 100) { if ($r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$valutakode}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__))) { $dkkamount[$y] = $amount[$y]; $amount[$y] = $amount[$y] * 100 / $r3['kurs']; $beskrivelse[$y] = $r2['beskrivelse'] . " - (Omregnet til {$valuta} fra DKK " . dkdecimal($dkkamount[$y]) . ", kurs " . dkdecimal($r3['kurs']) . ")"; } elseif ($r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$valutakode}' order by valdate", __FILE__ . " linje " . __LINE__))) { $amount[$y] = $amount[$y] * 100 / $r3['kurs']; $beskrivelse[$y] = $r2['beskrivelse'] . " - (Omregnet til {$valuta} fra DKK " . dkdecimal($dkkamount[$y]) . ", kurs " . dkdecimal($r3['kurs']) . ")"; } } elseif ($oppvaluta[$y] != 'DKK' && $valuta == "DKK" && $valutakurs[$y] != 100) { $beskrivelse[$y] = $r2['beskrivelse'] . " - (Omregnet til DKK fra " . $oppvaluta[$y] . " " . dkdecimal($amount[$y]) . ", kurs " . dkdecimal($valutakurs[$y]) . ")"; $amount[$y] = $amount[$y] * $valutakurs[$y] / 100; #cho __line__." $amount[$y]=$amount[$y]*$valutakurs[$y]/100<br>"; } elseif ($valuta != "DKK" && $valuta == $oppvaluta[$y] && $valutakurs[$y] != 100) { #cho "Opp $oppvaluta[$y] $valuta<br>"; $valutakurs[$y] *= 1; if (!$valutakurs[$y] && $oppvaluta[$y] && $oppvaluta[$y] != '-') { #cho "select kodenr from grupper where box1 = '$oppvaluta[$y]' and art='VK'<br>"; $r3 = db_fetch_array(db_select("select kodenr from grupper where box1 = '{$oppvaluta[$y]}' and art='VK'", __FILE__ . " linje " . __LINE__)); #cho "select kurs from valuta where gruppe ='$r3[kodenr]' and valdate <= '$transdate[$y]' order by valdate desc<br>"; $r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$r3['kodenr']}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__)); $valutakurs[$y] = $r3['kurs'] * 1; # if ($valutakurs) #cho "update openpost set valutakurs='$valutakurs[$y]' where id='$oppid[$y]'<br>"; # if ($valutakurs) db_modify("update openpost set valutakurs='$valutakurs[$y]' where id='$oppid[$y]'"); } $dkkamount[$y] = $amount[$y] * $valutakurs[$y] / 100; #cho "DKKA $dkkamount[$y]=A $amount[$y]*VK $valutakurs[$y]/100<br>"; #cho $r2['beskrivelse']."| $amount[$y]<br>"; if ($oppvaluta[$y] != '-' && abs($amount[$y]) >= 0.005) { if (!strpos($beskrivelse[$y], 'Udligning af valutadiff')) { $beskrivelse[$y] = $r2['beskrivelse'] . " - (DKK " . dkdecimal($dkkamount[$y]) . ")"; } } elseif (abs($amount[$y]) < 0.005) { $beskrivelse[$y] = $r2['beskrivelse']; } else { $beskrivelse[$y] = $r2['beskrivelse'] . " - (DKK " . dkdecimal($amount[$y]) . ")"; } } elseif ($oppvaluta[$y] != $valuta && $oppvaluta[$y] != '-') { if (!$valutakurs[$y]) { #cho "select kodenr from grupper where box1 = '$oppvaluta[$y]' and art='VK'<br>"; $r3 = db_fetch_array(db_select("select kodenr from grupper where box1 = '{$oppvaluta[$y]}' and art='VK'", __FILE__ . " linje " . __LINE__)); #cho "select kurs from valuta where gruppe ='$r3[kodenr]' and valdate <= '$transdate[$y]' order by valdate desc<br>"; $r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$r3['kodenr']}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__)); $valutakurs[$y] = $r3['kurs'] * 1; } $r3 = db_fetch_array(db_select("select kodenr from grupper where box1 = '{$valuta}' and art='VK'", __FILE__ . " linje " . __LINE__)); #cho "select kurs from valuta where gruppe ='$r3[kodenr]' and valdate <= '$transdate[$y]' order by valdate desc<br>"; $r3 = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$r3['kodenr']}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__)); $dagskurs = $r3['kurs'] * 1; #cho "$dagskurs<br>"; $beskrivelse[$y] .= " {$oppvaluta[$y]} " . dkdecimal($amount[$y]) . " Kurs {$valutakurs[$y]}"; $amount[$y] *= $valutakurs[$y] / $dagskurs; $dkkamount[$y] = $amount[$y] * $valutakurs[$y] / 100; #cho "$dkkamount[$y]=$amount[$y]*$valutakurs[$y]/100<br>"; } else { $beskrivelse[$y] = $r2['beskrivelse']; $dkkamount[$y] = $amount[$y]; #20160503 } if ($oppvaluta[$y] == "-") { $dkkamount[$y] = $amount[$y]; $amount[$y] = 0; $forfaldsdate[$y] = ''; } } $kontosum = 0; $primo = 0; $pre_openpost = 0; for ($y = 1; $y <= count($oppid); $y++) { $diff = 0; #cho "$amount[$y] <=> $dkkamount[$y]<br>"; if ($transdate[$y] < $fromdate) { $primoprint[$x] = 0; $kontosum += $amount[$y]; $dkksum += $dkkamount[$y]; } else { if ($primoprint[$x] == 0) { $tmp = dkdecimal($kontosum); $tmp2 = ""; if ($valuta != 'DKK') { $tmp2 = " - Beløb kan være omregnet fra DKK"; } print "<tr><td><br></td><td><br></td><td><br></td><td>Primosaldo {$tmp2}<br></td><td><br></td><td><br></td><td><br></td><td><br></td><td align=right title=\"DKK " . dkdecimal($dkksum, 2) . "\">{$tmp}<br></td></tr>\n"; $primoprint[$x] = 1; } print "<tr bgcolor=\"{$baggrund}\"><td valign=\"top\">" . dkdato($transdate[$y]) . "<br></td><td valign=\"top\">{$refnr[$y]}<br></td><td valign=\"top\">{$faktnr[$y]}<br></td><td valign=\"top\">" . stripslashes($beskrivelse[$y]) . "<br></td><td valign=\"top\">{$projekt[$y]}</td>"; if ($amount[$y] < 0) { $tmp = 0 - $amount[$y]; } else { $tmp = $amount[$y]; } $tmp = dkdecimal($tmp); if (!$forfaldsdag[$y]) { $forfaldsdag[$y] = usdate(forfaldsdag($transdate[$y], $betalingsbet, $betalingsdage)); } # if (($row[udlignet]!='1')&&($forfaldsdag<$currentdate)){$stil="<span style='color: rgb(255, 0, 0);'>";} # else {$stil="<span style='color: rgb(0, 0, 0);'>";} if ($amount[$y] > 0) { # (($kontoart=='D' && $amount>0) || ($kontoart=='K' && $amount<0)) { $kontoart == 'D' ? $ffdag = dkdato($forfaldsdag[$y]) : ($ffdag = NULL); if ($udlignet[$y] != '1') { $pre_openpost = 1; print "<td valign=\"top\"><span style='color: rgb(255, 0, 0);'>{$ffdag}<br></td><td valign=\"top\" align=\"right\" title=\"Klik her for at udligne åbne poster\"><span style='color: rgb(255, 0, 0);'><a href=\"../includes/udlign_openpost.php?post_id={$oppid[$y]}&dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&returside={$returside}&retur=" . $returnpath . "rapport.php\">{$tmp}</a><br></td><td style=\"color:{$baggrund};text-align:right\">0</td>"; } else { $titletag = "Udlign id={$udlign_id[$y]}. Klik for at ophæve udligning"; $alink = "rapport.php?rapportart=kontokort&kilde=openpost&kto_fra={$kto_fra}&kilde_kto_til={$kto_til}=&dato_fra{$dato_fra}=&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&submit=ok&uudlign={$udlign_id[$y]}"; $onclick = "return confirm('Vil du ophæve udligningen af dette beløb samt modstående med udlign id {$udlign_id[$y]}')"; print "<td valign=\"top\"><span style='color: rgb(0, 0, 0);'>{$ffdag}<br></td><td title=\"{$titletag}\" valign=\"top\" align=\"right\"><span style=\"color: rgb(0, 0, 0);\"><a onclick=\"{$onclick}\" href=\"{$alink}\"style=\"text-decoration:none;\" >{$tmp}<br></a></span></td><td style=\"color:{$baggrund};text-align:right\">0</td>"; } $forfaldsum = $forfaldsum + $amount[$y]; } else { $kontoart == 'K' ? $ffdag = dkdato($forfaldsdag[$y]) : ($ffdag = NULL); if ($udlignet[$y] != '1') { print "<td><span style='color: rgb(255, 0, 0);'>{$ffdag}<br></td><td style=\"color:{$baggrund};text-align:right\">0</td><td valign=\"top\" align=right title=\"Klik her for at udligne åbne poster\"><span style='color: rgb(255, 0, 0);'><a href=\"../includes/udlign_openpost.php?post_id={$oppid[$y]}&dato_fra={$dato_fra}&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&returside={$returside}&retur=" . $returnpath . "rapport.php\">{$tmp}</a><br></td>"; $pre_openpost = 1; } else { $titletag = "Udlign id={$udlign_id[$y]}. Klik for at ophæve udligning"; $alink = "rapport.php?rapportart=kontokort&kilde=openpost&kto_fra={$kto_fra}&kilde_kto_til={$kto_til}=&dato_fra{$dato_fra}=&dato_til={$dato_til}&konto_fra={$konto_fra}&konto_til={$konto_til}&submit=ok&uudlign={$udlign_id[$y]}"; $onclick = "return confirm('Vil du ophæve udligningen af dette beløb samt modstående med udlign id {$udlign_id[$y]}')"; print "<td>{$ffdag}<br></td><td style=\"color:{$baggrund};text-align:right\">0</td><td title=\"{$titletag}\" valign=\"top\" align=\"right\"><span style=\"color: rgb(0, 0, 0);\"><a onclick=\"{$onclick}\" href=\"{$alink}\"style=\"text-decoration:none;\" >{$tmp}<br></a></span></td>"; } } $kontosum += afrund($amount[$y], 2); $dkksum += $dkkamount[$y]; $dkksum = afrund($dkksum, 2); #cho "$dkksum | $dkkamount[$y]<br>"; $tmp = dkdecimal($kontosum); $dkktmp = dkdecimal($dkksum); if ($valuta != 'DKK' && $kontosum != $dkksum) { $title = "DKK: {$dkktmp}"; } else { $title = ""; } #cho "$transdate[$y] | $dkkamount[$y] | $dkksum<br>"; if ($valuta != 'DKK' && !$difflink) { #cho "select kurs from valuta where gruppe ='$valutakode' and valdate <= '$transdate[$y]' order by valdate desc<br>"; if ($r = db_fetch_array(db_select("select kurs from valuta where gruppe ='{$valutakode}' and valdate <= '{$transdate[$y]}' order by valdate desc", __FILE__ . " linje " . __LINE__))) { $dagskurs = $r['kurs']; $chkamount = $kontosum * $dagskurs / 100; #cho "$kontosum*$dagskurs/100 Kontrolsum $chkamount<br>"; $diff = afrund($chkamount - $dkksum, 2); #cho "Saldodiff: ".$chkamount."!=".$dkksum." rest: ".$diff."<br>"; # if ($chkamount!=$dkksum) #cho "Saldodiff: ".$chkamount."!=".$dkksum." rest". $chkamount!=$dkksum."<br>"; # #cho "tt $transdate[$y]<br>"; } } # $diff=afrund($kontosum*$valutakurs/100-$dkksum,3); #if ($diff && !$difflink) #cho "Diff m. 3 dec. $diff<br>"; # $diff=afrund($diff,2); #if (afrund($diff,2) && !$difflink) #cho "Diff m. 2 dec. ".afrund($diff,2)."<br>"; /* if ($diff && !$difflink && $oppvaluta!='DKK') { #cho "$diff && !$difflink<br>"; $ny_kurs=$valutakurs; $ny_diff=afrund($kontosum*$ny_kurs/100-$dkksum,2); $gl_diff=$ny_diff; #cho "A Ny diff $ny_diff<br>"; while ($ny_diff && abs($ny_diff)<=abs($gl_diff)) { #cho "Ny diff $ny_diff Kurs $ny_kurs<br>"; if (abs($ny_diff)>10) $ny_kurs+=0.1; else $ny_kurs+=0.001; $ny_diff=afrund($kontosum*$ny_kurs/100-$dkksum,2); } # $ny_kurs=$valutakurs; # $ny_diff=afrund($kontosum*$ny_kurs/100-$dkksum,2); #cho "B Ny diff $ny_diff<br>"; $gl_diff=$ny_diff; while ($ny_diff && abs($ny_diff)<=abs($gl_diff)) { #cho "Ny diff $ny_diff Kurs $ny_kurs<br>"; if (abs($ny_diff)>10) $ny_kurs-=0.1; else $ny_kurs-=0.001; $ny_diff=afrund($kontosum*$ny_kurs/100-$dkksum,2); } if (abs($ny_diff)>0.01) { #cho "Kurs reguleres ikke<br>"; $ny_kurs=$valutakurs; } else #cho "Ny Diff $ny_diff Kurs reguleres fra $valutakurs til $ny_kurs<br>"; # #cho "Afrundet diff på summen".afrund($kontosum*$ny_kurs/100-$dkksum,3)." Kurs $valutakurs<br>"; #cho "Beløb på denne post DKK ".$dkkamount." Eur ".$amount."<br>"; #cho "Diff $diff | $valutakurs | $ny_kurs<br>"; #cho } */ #cho "($diff>0.005 && !$difflink && $valuta!='DKK' && $oppvaluta[$y]!='-')<br>"; $regulering = afrund($diff, 2); # else $regulering=afrund($dkksum+$diff,2)-afrund($dkksum,2); if ($regulering && !$difflink && $valuta != 'DKK' && ($oppvaluta[$y] != '-' || $y == count($oppid)) && $transdate[$y] >= usdate($regnstart) && $transdate[$y] <= usdate($regnslut)) { # && $transdate>=$regnstart && $transdate<=$regnslut $vis_difflink = 1; for ($i = 1; $i <= count($oppid); $i++) { if ($transdate[$i] == $transdate[$y] && $oppvaluta[$i] == '-') { $vis_difflink = 0; } } if ($y == count($oppid) && !$kontosum) { $vis_difflink = 1; } # $vis_difflink=0; # if ($oppid[$y] >= $max_valdif_id && ($vis_difflink && (abs($regulering) > 0.01 || $y == count($oppid)))) { $difflink = 1; if ($regnstart <= date("Y-m-d") && $regnslut >= date("Y-m-d")) { $title .= "Klik for at regulere værdien i DKK fra " . dkdecimal($dkksum) . " til " . dkdecimal($dkksum + $regulering) . " pr. " . dkdato($transdate[$y]); $tmp2 = "<a href=\"../includes/ret_valutadiff.php?bfdate={$transdate[$y]}&"; $tmp2 .= "valuta={$valuta}&diff={$regulering}&post_id={$oppid[$y]}&dato_fra={$dato_fra}&dato_til={$dato_til}&"; $tmp2 .= "konto_fra={$konto_fra}&konto_til={$konto_til}&returside={$returside}&retur=" . $returnpath . "rapport.php\" "; $tmp2 .= "onclick=\"confirmSubmit({$confirm})\">{$tmp}</a>"; $tmp = $tmp2; } else { $title = NULL; } } } elseif ($y == count($oppid) && abs($tmp) < 0.01 && abs($dkksum) > 0.01 && $regnslut >= date("Y-m-d")) { $title .= "Klik for at regulere værdien i DKK fra " . dkdecimal($dkksum) . " til " . dkdecimal($dkksum + $regulering) . " pr. " . date("d-m-Y"); $tmp2 = "<a href=\"../includes/ret_valutadiff.php?bfdate=" . date("Y-m-d") . "&"; $tmp2 .= "valuta={$valuta}&diff={$regulering}&post_id={$oppid[$y]}&dato_fra={$dato_fra}&dato_til={$dato_til}&"; $tmp2 .= "konto_fra={$konto_fra}&konto_til={$konto_til}&returside={$returside}&retur=" . $returnpath . "rapport.php\" "; $tmp2 .= "onclick=\"confirmSubmit({$confirm})\">{$tmp}</a>"; $tmp = $tmp2; } print "<td valign=\"top\" align=right title=\"{$title}\">{$tmp}<br></td>"; print "</tr>\n"; } } if ($primoprint[$x] == 0) { $tmp = dkdecimal($kontosum); print "<tr><td><br></td><td><br></td><td><br></td><td>Primosaldo<br></td><td><br></td><td><br></td><td><br></td><td><br></td><td align=right title=\"DKK sum {$dkktmp}\">{$tmp}<br></td></tr>\n"; } } print "<tr><td colspan=9><hr></td></tr>\n"; print "</tbody></table>"; }
function udskriv($ansat_antal, $ansat_id, $startdato, $slutdato) { global $returside; for ($a = 1; $a <= $ansat_antal; $a++) { if ($r = db_fetch_array(db_select("select * from ansatte where id = '{$ansat_id[$a]}'", __FILE__ . " linje " . __LINE__))) { $ref = $r['navn']; } if ($r = db_fetch_array(db_select("select * from grupper where art = 'DIV' and kodenr = '1'", __FILE__ . " linje " . __LINE__))) { $box1 = $r['box1']; $box2 = $r['box2']; $box3 = $r['box3']; $box4 = $r['box4']; } if ($box1 == 'ref') { $personkilde = "and ordrer.ref='{$ref}'"; } elseif ($box1 == 'kua') { $personkilde = "and adresser.kontoansvarlig = '{$ansat_id[$a]}'"; } else { $personkilde = "and (adresser.kontoansvarlig = '{$ansat_id[$a]}' or ((adresser.kontoansvarlig = NULL or adresser.kontoansvarlig = '0') and ordrer.ref='{$ref}'))"; } if ($box2 == 'kort') { $kostkilde = "kort"; } else { $kostkilde = "batch"; } if ($box4 == 'fak') { $grundlag = "fak"; } else { $grundlag = "bet"; } if ($a == 1) { # $slutmaaned=date("m"); # $slutaar=date("Y"); # $default_slutdato=$box3."-".$slutmaaned."-".$slutaar; $default_startdato = predato($box3 . "-" . date("m") . "-" . date("Y")); $default_slutdato = slutdato($default_startdato); if (!$startdato) { $startdato = $default_startdato; $slutdato = $default_slutdato; } print "<table width=100% border=0 cellspacing=0 cellpadding=0><tbody>"; print "<table width = 100% cellpadding=\"1\" cellspacing=\"1\" border=\"0\"><tbody>"; print "<tr>\n"; print "<td width=\"10%\" {$top_bund}><font face=\"Helvetica, Arial, sans-serif\" color=\"#000066\"><a href={$returside} accesskey=L>Luk</a></td>"; print "<td width=\"80%\" {$top_bund}><font face=\"Helvetica, Arial, sans-serif\" color=\"#000066\">Provisionsrapport</td>"; print "<td width=\"10%\" {$top_bund}><font face=\"Helvetica, Arial, sans-serif\" color=\"#000066\"><br></td>"; print "</tr>\n"; print "<form name=provisionsrapport action=provisionsrapport.php method=post>\n"; print "<tr><td colspan='3'><input type=submit value=\"Periode\" name=\"submit\"><select name=periode>"; print "<option>{$startdato} : {$slutdato}</option>"; $tmp = $default_startdato; $tmp2 = $default_slutdato; for ($x = 12; $x >= 1; $x--) { print "<option>{$tmp} : {$tmp2}</option>"; $tmp = predato($tmp); $tmp2 = slutdato($tmp); } print "</select> "; print "</form>\n"; print "<tr><td colspan='3'><b>{$ref}</b></td></tr>"; # Kan ikke forstaa, hvorfor der ikke skal vaere en overskrift, hvis der blot er flere... } else { print "<tr><td colspan='3'><b>{$ref}</b></td></tr>"; } print "</tbody></table>"; print "<tr><td valign=top>"; print "<table width=100% align=center valign=top border=0 cellspacing=0 cellpadding=0><tbody>"; print "<tr><td></td></tr>"; print "<tr><td colspan=7><br></td></tr>"; if ($grundlag == 'bet') { print "<tr><td colspan=7> Betalte fakturaer i peroiden.</td><tr>"; } else { print "<tr><td colspan=7> Fakturerede ordrer i perioden.</td><tr>"; } print "<tr><td colspan=7><br></td><tr>"; if ($grundlag == 'bet') { print "<tr><td width=15%> Fakturadato</td><td> Betalingsdato</td><td align=right width=10%> Fakturanr</td><td align=right width=15%> Kostpris</td><td align=right width=15%> Salgspris</td><td align=right width=15%> Dæknings-<br />bidrag</td><td align=right width=15%> Provision</td><tr>"; } else { print "<tr><td width=15%> Fakturadato</td><td> Forfaldsdato</td><td align=right width=10%> Fakturanr</td><td align=right width=15%> Kostpris</td><td align=right width=15%> Salgspris</td><td align=right width=15%> Dæknings-<br />bidrag</td><td align=right width=15%> Provision</td><tr>"; } print "<tr><td colspan=7><hr></td><tr>"; $x = 0; $faktliste = array(); $startdate = usdate($startdato); $slutdate = usdate($slutdato); $sum = 0; $kostsum = 0; $pro_sum = 0; if ($grundlag == 'bet') { $q1 = db_select("SELECT ordrer.firmanavn as firmanavn, ordrer.fakturadate as faktdate, openpost.udlign_date as udlign_date, openpost.faktnr as faktnr, ordrer.id as ordre_id, grupper.box6 as box6, grupper.id as gruppe_id from adresser, openpost, ordrer, grupper where (ordrer.art='DO' or ordrer.art='DK') {$personkilde} and adresser.id=openpost.konto_id and adresser.gruppe=" . nr_cast("grupper.kodenr") . " and grupper.art='DG' and ordrer.fakturanr=openpost.faktnr and openpost.udlign_date >= '{$startdate}' and openpost.udlign_date <= '{$slutdate}' and openpost.udlignet = '1' and openpost.faktnr>'0' order by openpost.udlign_date, openpost.faktnr", __FILE__ . " linje " . __LINE__); } else { $q1 = db_select("SELECT ordrer.firmanavn as firmanavn, ordrer.fakturadate as faktdate, ordrer.fakturanr as faktnr, ordrer.id as ordre_id , ordrer.betalingsbet as betalingsbet, ordrer.betalingsdage, grupper.box6 as box6, grupper.id as gruppe_id from adresser, ordrer, grupper where (ordrer.art='DO' or ordrer.art='DK') and adresser.id=ordrer.konto_id and adresser.gruppe=" . nr_cast("grupper.kodenr") . " and grupper.art='DG' {$personkilde} and ordrer.status>=3 and ordrer.fakturadate >= '{$startdate}' and ordrer.fakturadate <= '{$slutdate}' order by ordrer.fakturadate, ordrer.fakturanr", __FILE__ . " linje " . __LINE__); } while ($r1 = db_fetch_array($q1)) { if (!in_array($r1['faktnr'], $faktliste)) { $x++; $pris[$x] = 0; $kostpris[$x] = 0; $faktliste[$x] = $r1['faktnr']; $firmanavn = str_replace(" ", " ", stripslashes($r1['firmanavn'])); if ($r1[box6] != NULL) { $pro_procent[$x] = $r1['box6']; } else { $pro_procent[$x] = 100; } if ($ansat_id[$a] && $r1[gruppe_id] && ($r2 = db_fetch_array(db_select("SELECT provision from provision where ansat_id='{$ansat_id[$a]}' and gruppe_id='{$r1['gruppe_id']}'", __FILE__ . " linje " . __LINE__)))) { $provision = $r2['provision']; } else { $provision = 0; } if ($grundlag == 'bet') { list($tmp, $tmp2, $tmp3) = varelinjer($r1[ordre_id], $r1[faktdate], $r1[udlign_date], $provision, $r1['faktnr'], $r1['firmanavn'], $pro_procent[$x]); } else { list($tmp, $tmp2, $tmp3) = varelinjer($r1[ordre_id], $r1[faktdate], forfaldsdag($r1[faktdate], $r1[betalingsbet], $r1[betalingsdage]), $provision, $r1['faktnr'], $firmanavn, $pro_procent[$x]); } $sum = $sum + $tmp; $kostsum = $kostsum + $tmp2; $pro_sum = $pro_sum + $tmp3; } } $tmp = $sum - $kostsum; $tmp2 = $pro_sum / 100 * $pro_procent[$x]; print "<tr><td colspan=7><hr></td></tr>"; print "<tr><td colspan=3> I alt</td><td align=right>" . dkdecimal($kostsum) . "</td><td align=right>" . dkdecimal($sum) . "</td><td align=right>" . dkdecimal($tmp) . "</td><td align=right>" . dkdecimal($tmp2) . "</td></tr>"; print "<tr><td colspan=7><hr></td></tr>"; print "<tr><td colspan=7><br></td></tr>"; if ($grundlag == 'bet') { print "<tr><td colspan=7> Fakturaer som ikke er betalt</td><tr>"; print "<tr><td colspan=7><br></td><tr>"; print "<tr><td> Fakturadato</td><td> Forfaldsdato</td><td align=right>Fakturanr</td><td align=right> Kostpris</td><td align=right> Salgspris</td><td align=right> DB</td><td align=right> Provision</td><tr>"; print "<tr><td colspan=7><hr></td><tr>"; $sum = 0; $kostsum = 0; $pro_sum = 0; $faktliste = array(); $q1 = db_select("SELECT ordrer.firmanavn as firmanavn, ordrer.fakturadate as faktdate, openpost.faktnr as faktnr, ordrer.id as ordre_id, ordrer.betalingsbet as betalingsbet, ordrer.betalingsdage, grupper.box6 as box6, grupper.id as gruppe_id from adresser, openpost, ordrer, grupper where (ordrer.art='DO' or ordrer.art='DK') and adresser.gruppe=" . nr_cast("grupper.kodenr") . " and grupper.art='DG' {$personkilde} and adresser.id=openpost.konto_id and ordrer.fakturanr=openpost.faktnr and ordrer.konto_id=openpost.konto_id and openpost.udlignet = '0' and openpost.faktnr>'0' order by openpost.transdate, openpost.faktnr", __FILE__ . " linje " . __LINE__); while ($r1 = db_fetch_array($q1)) { if (!in_array($r1['faktnr'], $faktliste)) { $x++; $pris[$x] = 0; $kostpris[$x] = 0; $faktliste[$x] = $r1['faktnr']; $firmanavn = str_replace(" ", " ", stripslashes($r1['firmanavn'])); if ($r1[box6] != NULL) { $pro_procent[$x] = $r1['box6']; } else { $pro_procent[$x] = 100; } if ($ansat_id[$a] && $r1[gruppe_id] && ($r2 = db_fetch_array(db_select("SELECT provision from provision where ansat_id='{$ansat_id[$a]}' and gruppe_id='{$r1['gruppe_id']}'", __FILE__ . " linje " . __LINE__)))) { $provision = $r2['provision']; } else { $provision = 0; } list($tmp, $tmp2, $tmp3) = varelinjer($r1[ordre_id], $r1[faktdate], forfaldsdag($r1[faktdate], $r1[betalingsbet], $r1[betalingsdage]), $provision, $r1[faktnr], $firmanavn, $pro_procent[$x]); $sum = $sum + $tmp; $kostsum = $kostsum + $tmp2; $pro_sum = $pro_sum + $tmp3; } } $tmp = $sum - $kostsum; $tmp2 = $pro_sum / 100 * $pro_procent[$x]; print "<tr><td colspan=7><hr></td></tr>"; print "<tr><td colspan=3> I alt</td><td align=right>" . dkdecimal($kostsum) . "</td><td align=right>" . dkdecimal($sum) . "</td><td align=right>" . dkdecimal($tmp) . "</td><td align=right>" . dkdecimal($tmp2) . "</td></tr>"; print "<tr><td colspan=7><hr></td></tr>"; print "<tr><td colspan=7><br></td></tr>"; print "<tr><td colspan=7><br></td></tr>"; } } print "</tr></tbody></table>"; print "</td></tr>"; print "</tbody></table>"; }