X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb%2Fsql_functions.inc;h=aead5d376e8c2f415925324f39dae6848dee46ce;hb=c164d1f25c5258939976042fa8796b71ac54c188;hp=febc3af824e4f1246be0f9659a7a6aced26616ab;hpb=d17c1c555babe58c33e854fafb9667d5e57ac8d9;p=fa-stable.git diff --git a/includes/db/sql_functions.inc b/includes/db/sql_functions.inc index febc3af8..aead5d37 100644 --- a/includes/db/sql_functions.inc +++ b/includes/db/sql_functions.inc @@ -59,4 +59,21 @@ function update_record_status($id, $status, $table, $key) { db_query($sql, "Can't update record status"); } -?> +//----------------------------------------------------------------------------- +// +// Helper for sql subquery returning running totals from delta tables like stock_moves or bank_trans +// +// $table - table name with optional WHERE clause +// $column - delta column +// $index - comma delimited list of columns for total grouping and order +// Returns running totals with respective index column +// +function running_total_sql($table, $column, $index) +{ + + return "SELECT daily.$index, daily.$column, (@total:=@total+daily.$column) total + FROM + (SELECT $index, sum($column) $column FROM $table GROUP BY $index ORDER BY $index) daily, + (SELECT @total:=0) total_var"; +} +