Subversion-Projekte lars-tiefland.content-management

Revision

Revision 1 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    if ( !function_exists( 'numberFormat' ) )
    {
        function numberFormat( $nbr, $n = 2, $s = '.', $ss = '.' )
        {
            return number_format( $nbr, $n, $s, $ss );
        }
    }

    function getArtikelListe( $BestellID = null, $shops_ID = 1 )
    {
        $query = "
                        select
                                artikel_to_Bestellung.ID as ab_id,
                                artikel_to_Bestellung.status as artikelStatus,
                                artikel_to_Bestellung.Preis_pro_Stueck,
                                artikel_to_Bestellung.Menge,
                                artikel_to_Bestellung.Bezeichnung,
                                artikel_to_Bestellung.Bestellung,
                                artikel_to_Bestellung.rechnungStatus,
                                artikel_to_Bestellung.lieferscheinStatus,                       
                                " . artikelDatabase( $shops_ID ) . ".*,
                                ifnull(" . artikelDatabase( $shops_ID ) . ".Father, 1) as Father,
                                ifnull(artikel_to_Bestellung.Bezeichnung, " . artikelDatabase( $shops_ID ) .
            ".kurzbezeichnung) as kurzbezeichnung
                        from
                                shops
                        join
                                artikel_to_Bestellung
                        join
                                Bestellung
                        left join
                                " . artikelDatabase( $shops_ID ) . "
                        on
                                artikel_to_Bestellung.artikel=" . artikelDatabase( $shops_ID ) . ".ID
                        and
                                " . artikelDatabase( $shops_ID ) . ".language=Bestellung.Language
                        where
                                Bestellung.ID = " . $BestellID . "
                        and 
                                artikel_to_Bestellung.Bestellung = Bestellung.ID
            and
                artikel_to_Bestellung.status != 'storniert' 
                        and
                                shops.ID = Bestellung.shops_ID
            
                        order by
                                Father desc,
                                " . artikelDatabase( $shops_ID ) . ".Kennung
                        ";

        $result = mysql_query( $query ) or mail( "admin@weban.de",
            "Fehler in createOrderText.php", mysql_errno() . ": " .
            mysql_error() . "<hr>$query<hr>", "from: weban.de" );
        return $result;

    }

    function Bestellwert_brutto( $BestellID, $shops_ID )
    {
        if ( $BestellID == null )
        {
            return;
        }

        $result = getArtikelliste( $BestellID, $shops_ID );
        $preis = 0;
        while ( $zeile = mysql_fetch_array( $result ) )
        {
            $preis += $zeile['Menge'] * $zeile['Preis_pro_Stueck'];
        }
        return numberFormat( $preis, 2, ',', '.' );
    }


    function createOrderText( $BestellID = null, $shops_ID = 1 )
    {
        if ( $BestellID == null )
        {
            return;
        }

        $text = "\nMenge   Art-Nr. Artikelname                      Einzelpreis    Gesamtpreis\n___________________________________________________________________________\n";

        $result = getArtikelliste( $BestellID, $shops_ID );
        $preis = 0;
        while ( $zeile = mysql_fetch_array( $result ) )
        {
            //pre($zeile);
            $preis += $zeile['Menge'] * $zeile['Preis_pro_Stueck'];

            if ( !( ( $zeile["Father"] > -3 ) or ( $zeile["Father"] == "" ) ) and
                !( $zeile["artikelStatus"] != 'versand' ) )
            {
                $text = $text . "\n1     x Versand: " . str_pad( $zeile['kurzbezeichnung'],
                    42 ) . str_pad( number_format( $zeile['Preis_pro_Stueck'],
                    2, ',', '.' ), 11, " ", STR_PAD_LEFT ) . " Euro\n";
            }
            else
            {
                $optionen = "";
                /* START Artikeloptionen zusammenstellen */
                if ( isset( $zeile["options"] ) )
                {
                    if ( is_array( $zeile['option'] ) )
                    {
                        $query_Feature_options =
                            "select * from Feature_options where ID = " .
                            implode( " or ID = ", $zeile['option'] );
                        $result_Feature_options = mysql_query( $query_Feature_options ) or
                            mail( "admin@weban.de",
                            "Fehler2 in createOrderText.php", mysql_errno() .
                            ": " . mysql_error() . "<hr>$query<hr>",
                            "from: weban.de" );


                        while ( $zeile_Feature_options = mysql_fetch_array( $result_Feature_options ) )
                        {
                            $Feature_options[] = $zeile_Feature_options['Value'];
                        }
                        $optionen = " (" . implode( ", ", $Feature_options ) .
                            ")";
                        unset( $Feature_options );
                    }
                    else
                    {
                        $optionen = "";
                    }
                }
                $artikeltext = $zeile['kennung'] . " " . $zeile['kurzbezeichnung'] .
                    " " . $optionen;
                /* STOP Artikeloptionen zusammenstellen */
                $text = $text . str_pad( $zeile['Menge'], 5 ) . " x " .
                    str_pad( $artikeltext, 40 ) . " " . str_pad( numberFormat
                    ( $zeile['Preis_pro_Stueck'], 2, ',', '.' ), 6, " ",
                    STR_PAD_LEFT ) . " Euro" . str_pad( numberFormat( $zeile['Menge'] *
                    $zeile['Preis_pro_Stueck'], 2, ',', '.' ), 10, " ",
                    STR_PAD_LEFT ) . " Euro\n";
            }
        }
        $mwst = 19;
        $mwst = $preis / ( 100 + $mwst ) * $mwst;
        $text = $text .
            "___________________________________________________________________________\nGesamtsumme (Brutto): " .
            str_pad( numberFormat( $preis, 2, ',', '.' ), 48, " ",
            STR_PAD_LEFT ) . " Euro\nEnthaltene MwSt. (19 %):" . str_pad( numberFormat
            ( $mwst, 2, ',', '.' ), 46, " ", STR_PAD_LEFT ) . " Euro";
        /*
        echo "
        <!-- 
        $text 
        -->";
        */
        return $text;
    }

    function createOrderText_html( $BestellID = null, $shops_ID = 1 )
    {
        $text = "
    <table><tr align='left'><th>Menge</th><th>Art.Nr.</th><th>Artikelname</th><th>Einzelpreis</th><th>Gesamtpreis</th></tr>";
        $result = getArtikelListe( $BestellID, $shops_ID );

        $preis = 0;
        while ( $zeile = mysql_fetch_array( $result ) )
        {
            //pre($zeile);
            $preis += $zeile['Menge'] * $zeile['Preis_pro_Stueck'];
            if ( !( ( $zeile["Father"] > -3 ) or ( $zeile["Father"] == "" ) ) and
                !( $zeile["artikelStatus"] != 'versand' ) )
            {
                $items[] = "<td>" . $zeile["Menge"] .
                    "</td><td>Versand</td><td>" . $zeile["kurzbezeichnung"] .
                    "</td><td align='right'>" . number_format( $zeile["Preis_pro_Stueck"],
                    2, ',', '.' ) . " &euro;</td><td align='right'>" .
                    number_format( $zeile["Menge"] * $zeile["Preis_pro_Stueck"],
                    2, ',', '.' ) . " &euro;</td>";
            }
            else
            {
                $optionen = "";
                /* START Artikeloptionen zusammenstellen */
                if ( isset( $zeile["options"] ) )
                {
                    if ( is_array( $zeile['option'] ) )
                    {
                        $query_Feature_options =
                            "select * from Feature_options where ID = " .
                            implode( " or ID = ", $zeile['option'] );
                        $result_Feature_options = mysql_query( $query_Feature_options ) or
                            mail( "admin@weban.de",
                            "Fehler2 in createOrderText.php", mysql_errno() .
                            ": " . mysql_error() . "<hr>$query<hr>",
                            "from: weban.de" );


                        while ( $zeile_Feature_options = mysql_fetch_array( $result_Feature_options ) )
                        {
                            $Feature_options[] = $zeile_Feature_options['Value'];
                        }
                        $optionen = " (" . implode( ", ", $Feature_options ) .
                            ")";
                        unset( $Feature_options );
                    }
                    else
                    {
                        $optionen = "";
                    }
                }

                $artikeltext = $zeile['kennung'] . " " . $zeile['kurzbezeichnung'] .
                    " " . $optionen;
                /* STOP Artikeloptionen zusammenstellen */
                $items[] = "<td>" . $zeile["Menge"] . "</td><td>" . $zeile["kennung"] .
                    "</td><td>" . $zeile["kurzbezeichnung"] .
                    "</td><td align='right'>" . number_format( $zeile["Preis_pro_Stueck"],
                    2, ',', '.' ) . " &euro;</td><td align='right'>" .
                    number_format( $zeile["Menge"] * $zeile["Preis_pro_Stueck"],
                    2, ',', '.' ) . " &euro;</td>";
            }
        }
        $mwst = 19;
        $mwst = $preis / ( 100 + $mwst ) * $mwst;
        $items[] =
            "<td colspan='4'>Gesamtsumme (Brutto)</td><td align='right'>" .
            number_format( $preis, 2, ',', '.' ) . " &euro;</td>";
        $items[] =
            "<td colspan='4'>Enthaltene MwSt. (19 %):</td><td align='right'>" .
            number_format( $mwst, 2, ',', '.' ) . " &euro;</td>";
        $text .= "<tr>" . implode( "</tr><tr>", $items ) . "</tr>";
        /*$text = $text . "\n___________________________________________________________________________\nGesamtsumme (Brutto): " .
        str_pad( numberFormat($preis), 48, " ", STR_PAD_LEFT ) . " Euro\nEnthaltene MwSt. (19 %):" .
        str_pad( numberFormat($mwst), 46, " ", STR_PAD_LEFT ) . " Euro";*/
        $text .= " </table>";
        /*
        echo "
        <!-- 
        $text 
        -->";
        */
        return $text;
    }



    function createOrderText_html_v2( $BestellID = null, $shops_ID = 1 )
    {
        $text = "<table><tr><th style='vertical-align:top;align:left;'>Menge:</th><th style='vertical-align:top;align:left;'>Art.Nr.</th><th style='vertical-align:top;align:center;'>Artikelname</th><th style='vertical-align:top;align:right;'>Einzelpreis</th><th style='vertical-align:top;align:right;'>Gesamtpreis</th></tr>";
        $result = getArtikelListe( $BestellID, $shops_ID );

        $preis = 0;

        while ( $zeile = mysql_fetch_array( $result ) )
        {
            //pre($zeile);
            $preis += $zeile['Menge'] * $zeile['Preis_pro_Stueck'];
            if ( !( ( $zeile["Father"] > -3 ) or ( $zeile["Father"] == "" ) ) and
                !( $zeile["artikelStatus"] != 'versand' ) )
            {
                $items[] = "<td style='vertical-align:top;'>" . $zeile["Menge"] . "</td><td style='vertical-align:top;'>Versand und Zahlung:</td><td style='vertical-align:top;'>" . $zeile["kurzbezeichnung"] ."</td><td style='vertical-align:top;' align='right'>" . number_format( $zeile["Preis_pro_Stueck"],2, ',', '.' ) . " &euro;</td><td style='vertical-align:top;' align='right'>" .   number_format( $zeile["Menge"] * $zeile["Preis_pro_Stueck"], 2, ',', '.' ) . " &euro;</td>";
            }
            else
            {
                /* START Artikeloptionen zusammenstellen */
                $optionen = "";
                /* START Artikeloptionen zusammenstellen */
                if ( isset( $zeile["options"] ) )
                {
                    if ( is_array( $zeile['option'] ) )
                    {
                        $query_Feature_options =
                            "select * from Feature_options where ID = " .
                            implode( " or ID = ", $zeile['option'] );
                        $result_Feature_options = mysql_query( $query_Feature_options ) or
                            mail( "admin@weban.de",
                            "Fehler2 in createOrderText.php", mysql_errno() .
                            ": " . mysql_error() . "<hr>$query<hr>",
                            "from: weban.de" );


                        while ( $zeile_Feature_options = mysql_fetch_array( $result_Feature_options ) )
                        {
                            $Feature_options[] = $zeile_Feature_options['Value'];
                        }
                        $optionen = " (" . implode( ", ", $Feature_options ) .
                            ")";
                        unset( $Feature_options );
                    }
                    else
                    {
                        $optionen = "";
                    }
                }

                $artikeltext = $zeile['kennung'] . " " . $zeile['kurzbezeichnung'] .
                    " " . $optionen;
                /* STOP Artikeloptionen zusammenstellen */
                $items[] = "<td style='vertical-align:top;'>" . $zeile["Menge"] . "</td><td style='vertical-align:top;'>" . $zeile["kennung"] . "</td><td style='vertical-align:top;'>" . $zeile["kurzbezeichnung"] . " ".$optionen."</td><td style='vertical-align:top;' align='right'>" . number_format( $zeile["Preis_pro_Stueck"],2, ',', '.' ) . " &euro;</td><td style='vertical-align:top;' align='right'>" . number_format( $zeile["Menge"] * $zeile["Preis_pro_Stueck"], 2, ',', '.' ) . " &euro;</td>";
            }
        }
        $mwst = 19;
        $mwst = $preis / ( 100 + $mwst ) * $mwst;
        
        
        $items[] = "<td style='vertical-align:top;' colspan='4'>Enthaltene MwSt. (19 %): " . number_format( $mwst, 2, ',', '.' ) . " &euro;</td><td style='vertical-align:top;' align='right'></td>";
        $items[] = "<td style='vertical-align:top;' colspan='4'>Gesamtsumme (Brutto)</td><td style='text-decoration:underline;vertical-align:top;' align='right'>" . number_format( $preis, 2, ',', '.' ) . " &euro;</td>";
        $text .= "<tr>" . implode( "</tr><tr>", $items ) . "</tr>";
        /*$text = $text . "\n___________________________________________________________________________\nGesamtsumme (Brutto): " .
        str_pad( numberFormat($preis), 48, " ", STR_PAD_LEFT ) . " Euro\nEnthaltene MwSt. (19 %):" .
        str_pad( numberFormat($mwst), 46, " ", STR_PAD_LEFT ) . " Euro";*/
        $text .= " </table>";
        /*
        echo "
        <!-- 
        $text 
        -->";
        */
        return $text;
    }

    function getHerstellerFromId( $id )
    {
        
        $sql = "SELECT
                                        Name
                                FROM
                                        ".herstellerDatabase($shops_ID)."
                                WHERE
                                        ID=" . $id . "
                                ";
        die( $sql );
        if ( $res = mysql_query( $sql ) )
        {
            if ( $row = mysql_fetch_assoc( $res ) )
            {
                return $row['Name'];
            }
        }
        return false;
    }
?>