<?php error_reporting(E_ALL); ini_set("display_errors",0); //The same syntax can be used with functions that return references, and with the new operator (since PHP 4.0.4 and before PHP 5.0.0): function find_var($bar){ } $bar = null; $foo =& find_var($bar); ?>
function importer($filnavn, $fejllog) { global $charset; global $bgcolor; global $bgcolor5; $accountingsupplierparty = NULL; $cvrnr = NULL; $fejl = NULL; $firmanavn = NULL; $linjenr = 0; $orderreference = NULL; $party = null; $partyname = NULL; $indhold = null; $ean = NULL; $sekliste = array('ID'); $fp = fopen($filnavn, 'r'); if ($fp) { # $x=0; $indhold = NULL; while ($linje[$x] = fgets($fp)) { $indhold .= $linje[$x]; } # $linjeantal=$x; fclose($fp); } $ordrenr = find_var($indhold, '', 'id'); $ordredate = find_var($indhold, '', 'issuedate'); $k_cvrnr = find_var($indhold, 'accountingsupplierparty,party', 'endpoinid schemeid="dk:cvr"'); $k_firmanavn = find_var($indhold, 'accountingsupplierparty,partyname', 'name'); $k_vejnavn = find_var($indhold, 'accountingsupplierparty,postaladdress', 'streetname'); $k_husnr = find_var($indhold, 'accountingsupplierparty,postaladdress', 'buildingnumber'); $k_bynavn = find_var($indhold, 'accountingsupplierparty,postaladdress', 'cityname'); $k_postnr = find_var($indhold, 'accountingsupplierparty,postaladdress', 'postalzone'); $k_land = find_var($indhold, 'accountingsupplierparty,country', 'identificationcode'); $k_telefon = find_var($indhold, 'accountingsupplierparty,contact', 'telephone'); $k_email = find_var($indhold, 'accountingsupplierparty,contact', 'electronicmail'); $d_cvrnr = find_var($indhold, 'accountingcustomerparty,party', 'endpoinid schemeid="dk:cvr"'); $d_firmanavn = find_var($indhold, 'accountingcustomerparty,partyname', 'name'); $d_vejnavn = find_var($indhold, 'accountingcustomerparty,postaladdress', 'streetname'); $d_husnr = find_var($indhold, 'accountingcustomerparty,postaladdress', 'buildingnumber'); $d_bynavn = find_var($indhold, 'accountingcustomerparty,postaladdress', 'cityname'); $d_postnr = find_var($indhold, 'accountingcustomerparty,postaladdress', 'postalzone'); $d_land = find_var($indhold, 'accountingcustomerparty,country', 'identificationcode'); $d_telefon = find_var($indhold, 'accountingcustomerparty,contact', 'telephone'); $d_email = find_var($indhold, 'accountingcustomerparty,contact', 'electronicmail'); $o_sum = find_var($indhold, 'legalmonetarytotal', 'lineextensionamount'); $o_totalsum = find_var($indhold, 'paymentterms', 'amount'); $o_moms = find_var($indhold, 'taxtotal', 'taxamount'); $pos = explode(",", find_antal_vars($indhold, '<cac:InvoiceLine>')); $antal_ordrelinjer = count($pos); $sum = 0; $momssum = 0; $d_momssats = 0; for ($x = 0; $x < $antal_ordrelinjer; $x++) { $string = substr($indhold, $pos[$x]); $l_varenr[$x] = find_var($string, 'invoiceline,sellersitemidentification', 'id'); $l_antal[$x] = find_var($string, 'invoiceline', 'invoicedquantity'); $l_tekst[$x] = find_var($string, 'invoiceline,item', 'name'); $l_pris[$x] = find_var($string, 'invoiceline,price', 'priceamount'); $l_momssats[$x] = find_var($string, 'invoiceline', 'percent'); $sum += $l_pris[$x]; $momssum += $l_pris[$x] / 100 * $l_momssats[$x]; if ($l_momssats[$x] > $d_momssats) { $d_momssats = $l_momssats[$x]; } } if ($r = db_fetch_array(db_select("select * from adresser where art = 'D' and kontonr = '{$d_telefon}'", __FILE__ . " linje " . __LINE__))) { $d_konto_id = $r['id']; } else { $fejl = "Debitor {$d_firmanavn}, med kontonummer: {$d_telefon} eksisterer ikke"; fejllog("{$fejl}", "{$fejllog}"); return $fejl; } for ($x = 0; $x < $antal_ordrelinjer; $x++) { if ($l_varenr[$x] != 'TEXT') { if ($r = db_fetch_array(db_select("select * from varer where varenr = '{$l_varenr[$x]}'", __FILE__ . " linje " . __LINE__))) { $l_vare_id[$x] = $r['id']; } else { $fejl = "Vare {$l_varenr[$x]} eksisterer ikke"; fejllog("{$fejl}", "{$fejllog}"); return $fejl; } } } $tidspkt = date('U'); $d_addr1 = $d_vejnavn . " " . $d_husnr; $d_addr2 = ''; $betalingsbet = 'Netto'; $betalingsdage = 8; $valuta = 'DKK'; $valutakurs = '100'; $sprog = 'Dansk'; transaktion('begin'); if (!$fejl) { $r = db_fetch_array(db_select("select max(ordrenr) as ordrenr from ordrer where art = 'DO' or art = 'DK'", __FILE__ . " linje " . __LINE__)); $d_ordrenr = $r['ordrenr'] + 1; db_modify("insert into ordrer(ordrenr,konto_id,kontonr,firmanavn,addr1,postnr,bynavn,land,email,ordredate,levdate,fakturadate,art,betalingsbet,betalingsdage,status,tidspkt,valuta,valutakurs,momssats,sum,moms)values('{$d_ordrenr}','{$d_konto_id}','{$d_telefon}','{$d_firmanavn}','{$d_addr1}','{$d_postnr}','{$d_bynavn}','{$d_land}','{$d_email}','{$ordredate}','{$ordredate}','{$ordredate}','DO','{$betalingsbet}','{$betalingsdage}','1','{$tidspkt}','{$valuta}','{$valutakurs}','{$d_momssats}','{$o_sum}','{$o_moms}')", __FILE__ . " linje " . __LINE__); if ($r = db_fetch_array(db_select("select id from ordrer where art = 'DO' and kontonr = '{$d_telefon}' and tidspkt = '{$tidspkt}'", __FILE__ . " linje " . __LINE__))) { $d_ordre_id = $r['id']; } else { $fejl = "Ordre ikke oprettet (Debitor {$d_firmanavn}, med kontonummer: {$d_telefon})"; fejllog("{$fejl}", "{$fejllog}"); return $fejl; } } if (!$fejl) { for ($x = 0; $x < $antal_ordrelinjer; $x++) { $pos = $x + 1; if (strtolower($l_varenr[$x]) == 'text') { db_modify("insert into ordrelinjer(posnr,ordre_id,beskrivelse)values('{$pos}','{$d_ordre_id}','{$l_tekst[$x]}')", __FILE__ . " linje " . __LINE__); } else { $l_antal[$x] *= 1; #20121220 $l_pris[$x] *= 1; #20121220 $l_momssats[$x] *= 1; $l_momssats[$x] ? $momsfri = '' : ($momsfri = 'on'); db_modify("insert into ordrelinjer(posnr,ordre_id,vare_id,varenr,antal,beskrivelse,pris,momssats,momsfri,kostpris)values('{$pos}','{$d_ordre_id}','{$l_vare_id[$x]}','{$l_varenr[$x]}','{$l_antal[$x]}','{$l_tekst[$x]}','{$l_pris[$x]}','{$l_momssats[$x]}','{$momsfri}','0')", __FILE__ . " linje " . __LINE__); } } } if (!$fejl) { db_modify("update ordrer set tidspkt= '' where id='{$d_ordre_id}'", __FILE__ . " linje " . __LINE__); transaktion('commit'); } #echo "Fejl >$fejl<<br>"; if ($fejl) { return "{$fejl}"; } else { return "OK"; } /* $linjebg=$bgcolor5; print "<tr><td valign=\"top\" align=\"center\"><table valign=\"top\"><tbody>"; print "<tr bgcolor=\"$bgcolor5\"><td width=\"100px\"><b>Firmanavn:</b></td><td width=\"200px\">$k_firmanavn<br></td><td width=\"100px\"><b>Ordrenr:</b></td><td width=\"200px\">$ordrenr<br></td></tr>\n"; print "<tr><td><b>Adresse:</b></td><td>$k_vejnavn $k_husnr<br></td><td><b>Ordredate:</td><td>$ordredate<br></td></tr>\n"; print "<tr bgcolor=\"$bgcolor5\"><td><b>Adresse:</b></td><td>$k_postnr $k_bynavn<br></td><td><b>Fakturanr:</b></td><td>$k_fakturanr<br></td></tr>\n"; print "<tr><td><b>Land:</b></td><td>$k_land<br></td><td><b>Cvr:</b></td><td>$k_cvrnr<br></td></tr>\n"; print "<tr bgcolor=\"$bgcolor5\"><td bgcolor=\"$bgcolor5\"><b>Telefon:</b></td><td>$k_telefon<br></td><td><b></b></td><br><td><br></td></tr>\n"; print "</tbody></table></td></tr>"; print "<tr><td valign=\"top\" align=\"center\"><table valign=\"top\"><tbody>"; print "<tr bgcolor=\"$bgcolor5\"><td width=\"100px\"><b>(Firma)navn:</b></td><td width=\"200px\">$d_firmanavn<br></td><td width=\"100px\"><b>Ordrenr:</b></td><td width=\"200px\">$ordrenr<br></td></tr>\n"; print "<tr><td><b>Adresse:</b></td><td>$d_vejnavn $d_husnr<br></td><td><b>Ordredate:</td><td>$ordredate<br></td></tr>\n"; print "<tr bgcolor=\"$bgcolor5\"><td><b>Adresse:</b></td><td>$d_postnr $d_bynavn<br></td><td><b>Fakturanr:</b></td><td>$fakturanr<br></td></tr>\n"; print "<tr><td><b>Land:</b></td><td>$land<br></td><td><b>Cvr:</b></td><td>$d_cvrnr<br></td></tr>\n"; print "<tr bgcolor=\"$bgcolor5\"><td bgcolor=\"$bgcolor5\"><b>Telefon:</b></td><td>$d_telefon<br></td><td><b></b></td><br><td><br></td></tr>\n"; print "</tbody></table></td></tr>"; print "<tr><td valign=\"top\" align=\"center\"><table valign=\"top\"><tbody>"; print "<tr bgcolor=\"$linjebg\"><td width=\"100px\"><b>Varenr</b></td><td width=\"50px\" align=\"right\"><b>Antal</b></td><td width=\"500px\"><b>Beskrivelse</b></td><td width=\"50px\"><b>Købspris</b></td><td width=\"70px\" align=\"right\"><b>Moms %</b></td>\n"; for ($x=0;$x<$antal_ordrelinjer;$x++) { if ($linjebg!=$bgcolor) { $linjebg=$bgcolor; } else { $linjebg=$bgcolor5; } $l_posnr[$x]=$x+1; print "<tr bgcolor=\"$linjebg\"><td>$l_varenr[$x]</td><td align=\"right\">".dkdecimal($l_antal[$x])."</td><td>$l_tekst[$x]</td><td align=\"right\">".dkdecimal($l_pris[$x])."</td><td align=\"right\">".dkdecimal($l_momssats[$x])."</td>\n"; # echo "Pos $l_posnr[$x], vnr $l_varenr[$x], antal $l_antal[$x], tekst $l_tekst[$x], pris $l_pris[$x], momssats $l_momssats[$x]<br>"; } print "<tr><td colspan=\"5\"><hr></td></tr>"; print "</tbody></table>"; print "</td></tr>"; */ }
function vis_oioubl($filnavn) { global $charset; global $bgcolor; global $bgcolor5; global $firmanavn; global $kontonr; global $vejnavn; global $husnr; global $postnr; global $bynavn; global $land; global $cvrnr; global $ordredate; global $fakturadate; global $l_varenr; global $l_pris; global $l_tekst; global $l_antal; global $l_sum; global $l_moms; global $l_momssats; global $l_posnr; $accountingsupplierparty = NULL; $cvrnr = NULL; $firmanavn = NULL; $linjenr = 0; $orderreference = NULL; $party = null; $partyname = NULL; $indhold = null; $ean = NULL; $fp = fopen($filnavn, 'r'); if ($fp) { $x = 0; while ($linje[$x] = fgets($fp)) { $x++; } $linjeantal = $x; fclose($fp); } for ($x = 0; $x <= $linjeantal; $x++) { $linje[$x] = trim($linje[$x]); $tmp = strtolower($linje[$x]); #cho htmlentities($linje[$x])." -> ".htmlentities($tmp)."<br>"; if ((strstr($tmp, "<cbc:id>") || $orderid) && !$fakturanr) { $orderid = 1; $find = "<cbc:id"; if (strstr($tmp, "{$find}")) { $fakturanr = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:id>")) { $orderid = 0; } } if ((strstr($tmp, "<cbc:issuedate>") || $inv_date) && !$fakturadate) { $inv_date = 1; $find = "<cbc:issuedate"; if (strstr($tmp, "{$find}")) { $fakturadate = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:issuedate>")) { $inv_date = 0; } } if (strstr($tmp, "<cac:orderreference>") || $orderreference) { $orderreference = 1; $find = "<cbc:salesorderid"; if (strstr($tmp, "{$find}")) { $ordrenr = find_var($tmp, $linje[$x], $find); } $find = "<cbc:issuedate"; if (strstr($tmp, "{$find}")) { $ordredate = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:orderreference>")) { $orderreference = 0; } } if (strstr($tmp, "<cac:accountingsupplierparty>") || $accountingsupplierparty) { #cho "Z1 $tmp -> $linje[$x] ->\"cbc:endpointid\"<br>"; $accountingsupplierparty = 1; if (strstr($tmp, "<cac:party>") || $party) { $party = 1; $find = "<cbc:endpointid"; if (strstr($tmp, "{$find}")) { $cvrnr = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "<cac:partyname>") || $partyname) { $partyname = 1; $find = "<cbc:name"; if (strstr($tmp, "{$find}")) { $firmanavn = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:partyname>")) { $partyname = 0; } } if (strstr($tmp, "<cac:postaladdress>") || $postaladdress) { $postaladdress = 1; $find = "<cbc:streetname"; if (strstr($tmp, "{$find}")) { $vejnavn = find_var($tmp, $linje[$x], $find); } $find = "<cbc:buildingnumber"; if (strstr($tmp, "{$find}")) { $husnr = find_var($tmp, $linje[$x], $find); } $find = "<cbc:cityname"; if (strstr($tmp, "{$find}")) { $bynavn = find_var($tmp, $linje[$x], $find); } $find = "<cbc:postalzone"; if (strstr($tmp, "{$find}")) { $postnr = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "<cac:country>") || $country) { $country = 1; $find = "<cbc:identificationcode"; if (strstr($tmp, "{$find}")) { $land = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:country>")) { $country = 0; } } if (strstr($tmp, "</cac:partyname>")) { $partyname = 0; } if (strstr($tmp, "</cac:postaladdress>")) { $postaladdress = 0; } } if (strstr($tmp, "<cbc:telephone>") || $telephone) { $country = 1; $find = "<cbc:telephone"; if (strstr($tmp, "{$find}")) { $telefon = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:telephone>")) { $telephone = 0; } } if (strstr($tmp, "</cbc:party>")) { $party = 0; } } if (strstr($tmp, "</cac:accountingsupplierparty>")) { $accountingsupplierparty = 0; } } #---------------- ordrelinjer ------------- if (strstr($tmp, "<cac:invoiceline") || $invoiceline) { $invoiceline = 1; if (strstr($tmp, "<cbc:note>") || $linenote) { $linenote = 1; $find = "<cbc:note"; if (strstr($tmp, "{$find}")) { $linjenote[$linjenr] .= find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cbc:note>")) { $linenote = 0; } } if (strstr($tmp, "<cbc:invoicedquantity") || $invoicedquantity) { #cho htmlentities($tmp); $invoicedquantity = 1; $find = "<cbc:invoicedquantity"; if (strstr($tmp, "{$find}")) { $l_antal[$linjenr] = find_var($tmp, $linje[$x], $find); } #cho "<br>$linjenr antal ".$l_antal[$linjenr]."<br>"; if (strstr($tmp, "</cbc:invoicedquantity>")) { $invoicedquantity = 0; } } if (strstr($tmp, "<cbc:lineextensionamount") || $lineextensionamount) { $lineextensionamount = 1; $find = "<cbc:lineextensionamount"; if (strstr($tmp, "{$find}")) { $l_sum[$linjenr] = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cbc:lineextensionamount>")) { $lineextensionamount = 0; } } if (strstr($tmp, "<cac:taxtotal") || $taxtotal) { $taxtotal = 1; if (strstr($tmp, "<cbc:taxamount") || $taxamount) { $taxamount = 1; $find = "<cbc:taxamount"; if (strstr($tmp, "{$find}")) { $l_moms[$linjenr] = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cbc:taxamount>")) { $taxamount = 0; } } if (strstr($tmp, "<cbc:percent") || $percent) { $percent = 1; $find = "<cbc:percent"; if (strstr($tmp, "{$find}")) { $l_momssats[$linjenr] = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cbc:percent>")) { $percent = 0; } } if (strstr($tmp, "</cac:taxtotal>")) { $taxtotal = 0; } } if (strstr($tmp, "<cbc:description") || $description) { $description = 1; $find = "<cbc:description"; if (strstr($tmp, "{$find}")) { $l_tekst[$linjenr] = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cbc:description>")) { $description = 0; } } if (strstr($tmp, "<cac:price") || $price) { #cho "Pris $l_pris[$linjenr]<br>"; $price = 1; if (strstr($tmp, "<cbc:priceamount") || $priceamount) { $priceamount = 1; $find = "<cbc:priceamount"; if (strstr($tmp, "{$find}")) { $l_pris[$linjenr] = find_var($tmp, $linje[$x], $find); } #cho "$linjenr Pris $l_pris[$linjenr]<br>"; if (strstr($tmp, "</cbc:priceamount>")) { $priceamount = 0; } } if (strstr($tmp, "</cac:price>")) { $price = 0; } } if (strstr($tmp, "<cac:sellersitemidentification") || $sellersitemidentification) { $sellersitemidentification = 1; $find = "<cbc:id"; if (strstr($tmp, "{$find}")) { $l_varenr[$linjenr] = find_var($tmp, $linje[$x], $find); } if (strstr($tmp, "</cac:sellersitemidentification>")) { $sellersitemidentification = 0; } } if (strstr($tmp, "</cac:invoiceline")) { $invoiceline = 0; if ($l_varenr[$linjenr]) { $linjenr++; } } } } if (!$ordredate && $fakturadate) { $ordredate = $fakturadate; } elseif (!$ordredate) { $ordredate = date("Y-m-d"); } $linjebg = $bgcolor5; print "<tr><td valign=\"top\" align=\"center\"><table valign=\"top\"><tbody>"; print "<tr bgcolor=\"{$bgcolor5}\"><td width=\"100px\"><b>Firmanavn:</b></td><td width=\"200px\">{$firmanavn}<br></td><td width=\"100px\"><b>Ordrenr:</b></td><td width=\"200px\">{$ordrenr}<br></td></tr>\n"; print "<tr><td><b>Adresse:</b></td><td>{$vejnavn} {$husnr}<br></td><td><b>Ordredate:</td><td>{$ordredate}<br></td></tr>\n"; print "<tr bgcolor=\"{$bgcolor5}\"><td><b>Adresse:</b></td><td>{$postnr} {$bynavn}<br></td><td><b>Fakturanr:</b></td><td>{$fakturanr}<br></td></tr>\n"; print "<tr><td><b>Land:</b></td><td>{$land}<br></td><td><b>Cvr:</b></td><td>{$cvrnr}<br></td></tr>\n"; print "<tr bgcolor=\"{$bgcolor5}\"><td bgcolor=\"{$bgcolor5}\"><b>Telefon:</b></td><td>{$telefon}<br></td><td><b></b></td><br><td><br></td></tr>\n"; print "</tbody></table></td></tr>"; print "<tr><td valign=\"top\" align=\"center\"><table valign=\"top\"><tbody>"; print "<tr bgcolor=\"{$linjebg}\"><td width=\"100px\"><b>Varenr</b></td><td width=\"50px\" align=\"right\"><b>Antal</b></td><td width=\"500px\"><b>Beskrivelse</b></td><td width=\"50px\"><b>Købspris</b></td><td width=\"70px\" align=\"right\"><b>Moms %</b></td>\n"; for ($x = 0; $x < $linjenr; $x++) { if ($linjebg != $bgcolor) { $linjebg = $bgcolor; } else { $linjebg = $bgcolor5; } $l_posnr[$x] = $x + 1; print "<tr bgcolor=\"{$linjebg}\"><td>{$l_varenr[$x]}</td><td align=\"right\">" . dkdecimal($l_antal[$x]) . "</td><td>{$l_tekst[$x]}</td><td align=\"right\">" . dkdecimal($l_pris[$x]) . "</td><td align=\"right\">" . dkdecimal($l_momssats[$x]) . "</td>\n"; #cho "Pos $l_posnr[$x], vnr $l_varenr[$x], antal $l_antal[$x], tekst $l_tekst[$x], pris $l_pris[$x], momssats $l_momssats[$x]<br>"; } print "<tr><td colspan=\"5\"><hr></td></tr>"; print "</tbody></table>"; print "</td></tr>"; # return($firmanavn.chr(9).$kontonr.chr(9).$vejnavn.chr(9).$husnr.chr(9).$postnr.chr(9).$bynavn.chr(9).$land.chr(9).$cvrnr.chr(9).$ordredate.chr(9).$l_varenr.chr(9).$l_pris.chr(9).$l_tekst.chr(9).$l_antal.chr(9).$l_sum.chr(9).$l_moms.chr(9).$l_momssats.chr(9).$l_posnr); }