Hi,
habe das bei mir mal ausprobiert. Ein bisschen verändert. Aber irgendwie mach ich was falsch.
Bei dieser Abfrage werden außer bei total völlig falsche Werte ausgegeben:
$turnover_query = xtc_db_query('select
round(coalesce(sum(if(date(o.date_purchased) = current_date - interval 0 day and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) today,
round(coalesce(sum(if(date(o.date_purchased) = current_date - interval 1 day and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) yesterday,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2 and o.orders_status <> 11 and o.orders_status <> 12 and o.orders_status <> 6 and o.orders_status <> 15 and o.orders_status <> 1, ot.value, null)), 0), 2) this_month,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) this_month_paid,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status <> 17, ot.value, null)), 0), 2) this_month_back,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status <> 9 and o.orders_status <> 7 and o.orders_status <> 13 and o.orders_status <> 4 and o.orders_status <> 16, ot.value, null)), 0), 2) this_month_storno,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2 and o.orders_status <> 11 and o.orders_status <> 12 and o.orders_status <> 6 and o.orders_status <> 15 and o.orders_status <> 1, ot.value, null)), 0), 2) last_month,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) last_month_paid,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status <> 17, ot.value, null)), 0), 2) last_month_back,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status <> 9 and o.orders_status <> 7 and o.orders_status <> 13 and o.orders_status <> 4 and o.orders_status <> 16, ot.value, null)), 0), 2) last_month_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2 and o.orders_status <> 11 and o.orders_status <> 12 and o.orders_status <> 6 and o.orders_status <> 15 and o.orders_status <> 1, ot.value, null)), 0), 2) this_year,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) this_year_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status <> 17, ot.value, null)), 0), 2) this_year_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status <> 9 and o.orders_status <> 7 and o.orders_status <> 13 and o.orders_status <> 4 and o.orders_status <> 16, ot.value, null)), 0), 2) this_year_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2 and o.orders_status <> 11 and o.orders_status <> 12 and o.orders_status <> 6 and o.orders_status <> 15 and o.orders_status <> 1, ot.value, null)), 0), 2) last_year,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) last_year_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status <> 17, ot.value, null)), 0), 2) last_year_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status <> 9 and o.orders_status <> 7 and o.orders_status <> 13 and o.orders_status <> 4 and o.orders_status <> 16, ot.value, null)), 0), 2) last_year_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2 and o.orders_status <> 11 and o.orders_status <> 12 and o.orders_status <> 6 and o.orders_status <> 15 and o.orders_status <> 1, ot.value, null)), 0), 2) total_all,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status <> 14 and o.orders_status <> 5 and o.orders_status <> 3 and o.orders_status <> 2, ot.value, null)), 0), 2) total_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) and o.orders_status <> 17, ot.value, null)), 0), 2) total_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status <> 9 and o.orders_status <> 7 and o.orders_status <> 13 and o.orders_status <> 4 and o.orders_status <> 16, ot.value, null)), 0), 2) total_storno,
round(coalesce(sum(ot.value), 0), 2) total
from ' . TABLE_ORDERS . ' o
join ' . TABLE_ORDERS_TOTAL . ' ot on ot.orders_id = o.orders_id
where ot.class = \'ot_total\'');
$turnover = xtc_db_fetch_array($turnover_query);
Und bei dieser Abfrage stimmen nur total, last_month_back, last_month_back, this_year_back, last__year_back. Und bei total_back nur ein falscher Wert.
$turnover_query = xtc_db_query('select
round(coalesce(sum(if(date(o.date_purchased) = current_date - interval 0 day and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) today,
round(coalesce(sum(if(date(o.date_purchased) = current_date - interval 1 day and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) yesterday,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2 and o.orders_status = 11 and o.orders_status = 12 and o.orders_status = 6 and o.orders_status = 15 and o.orders_status = 1, ot.value, null)), 0), 2) this_month,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) this_month_paid,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status = 17, ot.value, null)), 0), 2) this_month_back,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 0 month) and o.orders_status = 9 and o.orders_status = 7 and o.orders_status = 13 and o.orders_status = 4 and o.orders_status = 16, ot.value, null)), 0), 2) this_month_storno,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2 and o.orders_status = 11 and o.orders_status = 12 and o.orders_status = 6 and o.orders_status = 15 and o.orders_status = 1, ot.value, null)), 0), 2) last_month,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) last_month_paid,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status = 17, ot.value, null)), 0), 2) last_month_back,
round(coalesce(sum(if(extract(year_month from o.date_purchased) = extract(year_month from current_date - interval 1 year_month) and o.orders_status = 9 and o.orders_status = 7 and o.orders_status = 13 and o.orders_status = 4 and o.orders_status = 16, ot.value, null)), 0), 2) last_month_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2 and o.orders_status = 11 and o.orders_status = 12 and o.orders_status = 6 and o.orders_status = 15 and o.orders_status = 1, ot.value, null)), 0), 2) this_year,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) this_year_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status = 17, ot.value, null)), 0), 2) this_year_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 0 year) and o.orders_status = 9 and o.orders_status = 7 and o.orders_status = 13 and o.orders_status = 4 and o.orders_status = 16, ot.value, null)), 0), 2) this_year_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2 and o.orders_status = 11 and o.orders_status = 12 and o.orders_status = 6 and o.orders_status = 15 and o.orders_status = 1, ot.value, null)), 0), 2) last_year,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) last_year_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status = 17, ot.value, null)), 0), 2) last_year_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date - interval 1 year) and o.orders_status = 9 and o.orders_status = 7 and o.orders_status = 13 and o.orders_status = 4 and o.orders_status = 16, ot.value, null)), 0), 2) last_year_storno,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2 and o.orders_status = 11 and o.orders_status = 12 and o.orders_status = 6 and o.orders_status = 15 and o.orders_status = 1, ot.value, null)), 0), 2) total_all,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status = 14 and o.orders_status = 5 and o.orders_status = 3 and o.orders_status = 2, ot.value, null)), 0), 2) total_paid,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) and o.orders_status = 17, ot.value, null)), 0), 2) total_back,
round(coalesce(sum(if(extract(year from o.date_purchased) = extract(year from current_date) - o.orders_status = 9 and o.orders_status = 7 and o.orders_status = 13 and o.orders_status = 4 and o.orders_status = 16, ot.value, null)), 0), 2) total_storno,
round(coalesce(sum(ot.value), 0), 2) total
from ' . TABLE_ORDERS . ' o
join ' . TABLE_ORDERS_TOTAL . ' ot on ot.orders_id = o.orders_id
where ot.class = \'ot_total\'');
$turnover = xtc_db_fetch_array($turnover_query);
Das HTML Template ist bei beiden gleich:
<td width="25%" valign="top">
<table width="100%" border="0">
<tr>
<td style="background:#eee" align="right"> </td>
<td style="background:#eee; color:#000" align="right"><strong><?php echo TURNOVER_TOTAL; ?></td>
<td style="background:#eee; color:#008000" align="right"><strong><?php echo TURNOVER_PAID; ?></strong></td>
<td style="background:#eee; color:#0600ff" align="right"><strong><?php echo TURNOVER_BACK; ?></td>
<td style="background:#eee; color:#ff0000" align="right"><strong><?php echo TURNOVER_STORNO; ?></td>
</tr>
<tr>
<td style="background:#eee"><strong><?php echo TURNOVER_TODAY; ?>:</strong></td>
<td style="background:#eee" align="right"><?php echo $currencies->format($turnover['today']); ?></td>
<td style="background:#eee" align="right"> </td>
<td style="background:#eee" align="right"> </td>
<td style="background:#eee" align="right"> </td>
</tr>
<tr>
<td style="background:#fff"><strong><?php echo TURNOVER_YESTERDAY; ?>:</strong></td>
<td style="background:#fff" align="right"><?php echo $currencies->format($turnover['yesterday']); ?></td>
<td style="background:#fff" align="right"> </td>
<td style="background:#fff" align="right"> </td>
<td style="background:#fff" align="right"> </td>
</tr>
<tr>
<td style="background:#eee"><strong><?php echo TURNOVER_THIS_MONTH; ?>:</strong></td>
<td style="background:#eee" align="right"><?php echo $currencies->format($turnover['this_month']); ?></td>
<td style="background:#eee" align="right"><?php echo $currencies->format($turnover['this_month_paid']); ?></td>
<td style="background:#eee" align="right"><?php echo $currencies->format($turnover['this_month_back']); ?></td>
<td style="background:#eee" align="right"><?php echo $currencies->format($turnover['this_month_storno']); ?></td>
</tr>
<tr>
<td style="background:#ccc"><strong><?php echo TURNOVER_LAST_MONTH; ?>:</strong></td>
<td style="background:#ccc" align="right"><?php echo $currencies->format($turnover['last_month']); ?></td>
<td style="background:#ccc" align="right"><?php echo $currencies->format($turnover['last_month_paid']); ?></td>
<td style="background:#ccc" align="right"><?php echo $currencies->format($turnover['last_month_back']); ?></td>
<td style="background:#ccc" align="right"><?php echo $currencies->format($turnover['last_month_storno']); ?></td>
</tr>
<tr>
<td style="background:#a7a7a7"><strong><?php echo TURNOVER_THIS_YEAR; ?>:</strong></td>
<td style="background:#a7a7a7" align="right"><?php echo $currencies->format($turnover['this_year']); ?></td>
<td style="background:#a7a7a7" align="right"><?php echo $currencies->format($turnover['this_year_paid']); ?></td>
<td style="background:#a7a7a7" align="right"><?php echo $currencies->format($turnover['this_year_back']); ?></td>
<td style="background:#a7a7a7" align="right"><?php echo $currencies->format($turnover['this_year_storno']); ?></td>
</tr>
<tr>
<td style="background:#6c6c6c"><strong><?php echo TURNOVER_LAST_YEAR; ?>:</strong></td>
<td style="background:#6c6c6c" align="right"><?php echo $currencies->format($turnover['last_year']); ?></td>
<td style="background:#6c6c6c" align="right"><?php echo $currencies->format($turnover['last_year_paid']); ?></td>
<td style="background:#6c6c6c" align="right"><?php echo $currencies->format($turnover['last_year_back']); ?></td>
<td style="background:#6c6c6c" align="right"><?php echo $currencies->format($turnover['last_year_storno']); ?></td>
</tr>
<tr>
<td style="background:#343434; color:#FFF"><strong><?php echo TURNOVER_TOTAL; ?>:</strong></td>
<td style="background:#343434; color:#FFF" align="right"><?php echo $currencies->format($turnover['total']); ?></td>
<td style="background:#343434; color:#FFF" align="right"><?php echo $currencies->format($turnover['total_paid']); ?></td>
<td style="background:#343434; color:#FFF" align="right"><?php echo $currencies->format($turnover['total_back']); ?></td>
<td style="background:#343434; color:#FFF" align="right"><?php echo $currencies->format($turnover['total_storno']); ?></td>
</tr>
</table>
</td>
Vielleicht weiß ja jemand was ich falsch mache.
Gruß Olly