Revision 1 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
<?// Dateiname: $URL: http://server3/svn/content-management/trunk/Warenwirtschaft/includes/statistik/system.php $// Revision: $Rev: 4249 $// letzter Bearbeiter: $Author: tiefland $// letztes Bearbeitungsdatum: $Date: 2012-03-23 16:42:14 +0100 (Fr, 23. Mrz 2012) $function select_tpl( $formTagName, $options, $optionValueKey, $optionLabelKey,$preSelectValue = false, $required = false, $onChange = null ){if ( $required == false ){array_unshift( $options, array( $optionValueKey => false, $optionLabelKey =>"----------- alle -----------" ) );}$ret = "<select name=\"" . $formTagName . "\" onChange=\"$onChange\">";foreach ( $options as $option ){$ret .= "<option value=\"" . $option[$optionValueKey] . "\"";if ( $option[$optionValueKey] == $preSelectValue ){$ret .= " selected";}$ret .= ">" . $option[$optionLabelKey] . "</option>";}$ret .= "</select>";return $ret;}function select( $formTagName, $options, $optionValueKey, $optionLabelKey,$preSelectValue = false, $required = false, $onChange = null ){echo select_tpl( $formTagName, $options, $optionValueKey, $optionLabelKey,$preSelectValue, $required, $onChange );}function getShops( $shop_id = null, $filter = false, $start = 0, $ende =0, $start_v = 0, $ende_v = 0 ){$buffer = array();$query = "SELECT*FROMshops";$query .= ( !empty( $shop_id ) ) ? " WHERE ID=$shop_id" : "";$result = mysql_query( $query ) or die( mysql_errno() . ": " .mysql_error() . "<hr>$query<hr>" );while ( $zeile = mysql_fetch_assoc( $result ) ){$buffer[] = $zeile;}if ( $filter ){//Shops filternforeach ( $buffer as $id => $shop ){if ( get_umsatz( $start, $ende, $shop["ID"], 0 ) ||get_umsatz( $start_v, $ende_v, $shop["ID"], 0 ) ){$shops[] = $shop;}}}else{$shops = $buffer;}unset( $buffer );return $shops;}function getBestellarten(){global $user_rechte;$bestellarten = false;if ( isset( $user_rechte["Warenwirtschaft"]["bestellung"]["bestellart"] ) ){$sql = "SELECT * FROM bestellart";$query = mysql_query( $sql );if ( !$query ){return false;}while ( $db = mysql_fetch_assoc( $query ) ){$bestellarten[] = $db;}}return $bestellarten;}function getZahlungsarten(){global $user_rechte;$zahlungsarten = false;if ( isset( $user_rechte["Warenwirtschaft"]["bestellung"]["zahlungsart"] ) ){$sql = "SELECT * FROM zahlungsarten";$query = mysql_query( $sql );if ( !$query ){return false;}while ( $r = mysql_fetch_assoc( $query ) ){$zahlungsarten[$r['id']] = $r['name'];}}return $zahlungsarten;}function getDates(){$buffer[] = array( "datum" => strftime( "%G-%m" ), "datumText" =>strftime( "%B %G" ), );$buffer[] = array( "datum" => strftime( "%Y-%m", strtotime( "-1 month",time() ) ), "datumText" => strftime( "%B %Y", strtotime( "-1 month",time() ) ), );for ( $i = 2; $i <= 5; $i++ ){$buffer[] = array( "datum" => strftime( "%G-%m", strtotime( "-$i months" ) ),"datumText" => strftime( "%B %G", strtotime( "-$i months" ) ), );}if ( strftime( "%w" ) != 1 ){$start = strtotime( "last monday" );}else{$start = time();}$buffer[] = array( "datum" => strftime( "%G-%m-%dW", $start ),"datumText" => strftime( "Woche %V %G", $start ), );$buffer[] = array( "datum" => strftime( "%G-%m-%dW", strtotime( "-1 week",$start ) ), "datumText" => strftime( "Woche %V %G", strtotime( "-1 week",$start ) ), );for ( $i = 2; $i <= 5; $i++ ){$buffer[] = array( "datum" => strftime( "%G-%m-%dW", strtotime( "-$i weeks",$start ) ), "datumText" => strftime( "Woche %V %G",strtotime( "-$i weeks", $start ) ), );}return $buffer;}function getWeeks( $year = 2008, $maxReverse = 6 ){$paramYear = $year;$scalar = 0;$weekNow = date( "W", time() );$monthNow = date( "n", time() );$dateArray = array();$monthArray = array();$countedWeek = $weekNow;$countedMonth = $monthNow;for ( $i = $weekNow; $i > ( $weekNow - $maxReverse ); $i-- ){$dateArray[$scalar]['week'] = $countedWeek;$dateArray[$scalar]['year'] = $year;$dateArray[$scalar]['date_string'] = "kw," . $countedWeek . "," .$year;$dateArray[$scalar]['human_string'] = "$countedWeek/$year";if ( $countedWeek == 1 ){$year -= 1;$countedWeek = 1;}else{$countedWeek--;}$scalar++;}$year = $paramYear;for ( $i = $monthNow; $i > ( $monthNow - $maxReverse ); $i-- ){$dateArray[$scalar]['month'] = $countedMonth;$dateArray[$scalar]['year'] = $paramYear;$dateArray[$scalar]['date_string'] = "mon," . $countedMonth ."," . $year;$dateArray[$scalar]['human_string'] = date( "M", mktime( 0, 0, 0,$countedMonth, 1, $year ) ) . " $year";if ( $countedMonth == 1 ){$year -= 1;$countedMonth = 12;}else{$countedMonth--;}$scalar++;}return $dateArray;}/* ################################################################################ *//* Select-Abfrage an die Datenbank senden. *//* Methode um Select-Abfragen zentral an die Datenbank zu senden *//* NUR Select-Abfragen ! *//* Nur sinnvoll in Verbindung mit while-Schleifen. *//* Aufrufbeispiel: while($zeile=mysqlSelect("select ....")) {...} *//* ################################################################################ */function mysqlSelect( $query ){if ( !preg_match( "/^select/i", trim( $query ) ) )// Abbrechen falls query nicht mit "select beginnt"{return false;}static $status; // Statuswerte der jeweiligen queries speichern$hash = md5( $query );if ( !$status[$hash] ){$status[$hash] = array( "result" => "", "numRows" => 0,"endOfResult" => false );}$result = &$status[$hash]["result"];$numRows = &$status[$hash]["numRows"];$endOfResult = &$status[$hash]["endOfResult"];if ( ( $numRows == 0 ) && $endOfResult == false )// Beginn des Aufrufes: EoR = false $numRows=0{$result = mysql_query( $query ) or die( mysql_errno() . ": " .mysql_error() . "<hr>" . pre( $query, true ) . "<hr>" );$numRows = mysql_num_rows( $result );$endOfResult = false;}if ( $numRows > 0 ) // Mittendrinn: numRows > 0{if ( $numRows == 1 ){$endOfResult = true;} // letzter durchlauf mit Daten$numRows--; //return mysql_fetch_assoc( $result );}if ( ( $numRows == 0 ) && $endOfResult == true )// letzter durchlauf{$endOfResult = false; // Werte zurücksetzenreturn false; // Ende zurückliefern}return false;}/**** @param string Datum Filter* @param int ID des Shops; Default: alle Shops* @param int Debug-Modus; Default: 0** @return int Anzahl der Bestellungen*/function get_anz_bestellungen( $start, $ende, $shop_id = null, $debug =0, $bestellart = 0 ){$b_ges = 0;$start = date( "Y-m-d", $start );$ende = date( "Y-m-d", $ende );$sql = "SELECTCOUNT(*) AS anzFROMBestellung bWHEREb.erstellt_am >='$start' AND b.erstellt_am <'$ende'";$sql .= ( !empty( $shop_id ) ) ? " AND b.shops_ID=$shop_id" : "";$sql .= ( !empty( $bestellart ) ) ? " AND b.bestellart_id=$bestellart" :"";$res = mysql_query( $sql );if ( $debug ){echo "$sql==>$b_ges<br>";}$row = mysql_fetch_assoc( $res );if ( $row["anz"] ){$b_ges = $row["anz"];}else{//Bestellungen aus Hilfstabelle lesen$sql_ba = "SELECTSUM(best_anzahl) AS anzFROMbestellung_archiv baWHEREba.datum >='$start' AND ba.datum <'$ende'";$sql_ba .= ( !empty( $shop_id ) ) ? " AND ba.shops_id=$shop_id" :"";$sql_ba .= ( !empty( $bestellart ) ) ? " AND ba.bestellart_id=$bestellart" :"";$res_ba = mysql_query( $sql_ba );echo mysql_error();$row = mysql_fetch_assoc( $res_ba );if ( $row["anz"] ){$b_ges = $row["anz"];}if ( $debug ){echo "$sql_ba==>$b_ges<br>";}}return $b_ges;}/**** @param string Datum Filter* @param int ID des Shops; Default: alle Shops* @param int Debug-Modus; Default: 0** @return int Anzahl der Bestellungen*/function get_pos_artikel( $start, $ende, $shop_id = null, $debug = 0, $bestellart =0 ){$start = date( "Y-m-d", $start );$ende = date( "Y-m-d", $ende );$sql = "SELECTCOUNT(*) AS anzFROMartikel_to_Bestellung a,Bestellung bWHEREb.ID=a.BestellungANDb.erstellt_am >='$start' AND b.erstellt_am <'$ende'";$sql .= ( !empty( $shop_id ) ) ? " AND b.shops_ID=$shop_id" : "";$sql .= ( !empty( $bestellart ) ) ? " AND b.bestellart_id=$bestellart" :"";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );$b_ges = $row["anz"];if ( $debug ){echo mysql_error() . "<br>";echo "$sql==>$b_ges<br>";}return $b_ges;}/**** @param string Datum Filter* @param int ID des Shops; Default: alle Shops* @param int Debug-Modus; Default: 0** @return int Anzahl der Bestellungen*/function get_anz_artikel( $start, $ende, $shop_id = null, $debug = 0, $bestellart =0 ){$start = date( "Y-m-d", $start );$ende = date( "Y-m-d", $ende );$sql = "SELECTSUM(Menge) AS anzFROMartikel_to_Bestellung a,Bestellung bWHEREb.ID=a.BestellungANDb.erstellt_am >='$start' AND b.erstellt_am <'$ende'";$sql .= ( !empty( $shop_id ) ) ? " AND b.shops_ID=$shop_id" : "";$sql .= ( !empty( $bestellart ) ) ? " AND b.bestellart_id=$bestellart" :"";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );$b_ges = $row["anz"];if ( $debug ){echo mysql_error() . "<br>";echo "$sql==>$b_ges<br>";}return $b_ges;}/**** @param string Datum Filter* @param int ID des Shops; Default: alle Shops* @param int Debug-Modus; Default: 0** @return int Umsatz*/function get_umsatz( $start, $ende, $shop_id = null, $debug = 0, $bestellart =0 ){$start = date( "Y-m-d", $start );$ende = date( "Y-m-d", $ende );$sql = "SELECTsum(Preis_pro_Stueck * Menge) as UmsatzFROMartikel_to_Bestellung a,Bestellung bWHEREb.ID=a.BestellungANDb.erstellt_am >='$start' AND b.erstellt_am <'$ende'";$sql .= ( !empty( $shop_id ) ) ? " AND b.shops_ID=$shop_id" : "";$sql .= ( !empty( $bestellart ) ) ? " AND b.bestellart_id=$bestellart" :"";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );$umsatz = $row["Umsatz"];if ( $debug ){echo "$sql==>$umsatz<br>";}if ( !$row["Umsatz"] ){//Umsatz aus Hilfstabelle lesen$sql_ba = "SELECTSUM(umsatz) as UmsatzFROMbestellung_archiv baWHEREba.datum >='$start' AND ba.datum <'$ende'";$sql_ba .= ( !empty( $shop_id ) ) ? " AND ba.shops_id=$shop_id" :"";$sql .= ( !empty( $bestellart ) ) ? " AND ba.bestellart_id=$bestellart" :"";$res = mysql_query( $sql_ba );if ( $res ){if ( mysql_num_rows( $res ) ){$row = mysql_fetch_assoc( $res );$umsatz = $row["Umsatz"];}}if ( $debug ){echo "$sql_ba==>$umsatz<br>";}}return $umsatz;}?>