$sales->account_id = Account::from_code_name('sales')->id; $sales->amount = -$sales_amount; $sales->commit(); $till = new AccountTransactionContent(); $till->account_transaction_id = $transaction->id; $till->account_id = Account::from_code_name('till')->id; $till->amount = ClientData::post('till') - $old_till; $till->commit(); $diff = new AccountTransactionContent(); $diff->account_transaction_id = $transaction->id; $diff->account_id = Account::from_code_name('diff')->id; $diff->amount = -($till->amount + $sales->amount); $diff->commit(); $stock = new AccountTransactionContent(); $stock->account_transaction_id = $transaction->id; $stock->account_id = Account::from_code_name('stock')->id; $stock->amount = -$stock_amount; $stock->commit(); $stock_usage = new AccountTransactionContent(); $stock_usage->account_transaction_id = $transaction->id; $stock_usage->account_id = Account::from_code_name('stock_change')->id; $stock_usage->amount = $stock_amount; $stock_usage->commit(); $daily_count = new DailyCount(); $daily_count->time = $time; $daily_count->amount = ClientData::post('till'); $daily_count->account_transaction_id = $transaction->id; $daily_count->user = $_SESSION['login']; $daily_count->commit(); $db->commit(); kick("/account_transaction/{$transaction->id}");
<?php if (empty($_SESSION['login'])) { kick(); } $daily_count = DailyCount::last(); $old_till = TransactionContent::sum('amount', array('Transaction.timestamp:>' => $daily_count->time, 'Transaction.timestamp:<=' => date('Y-m-d H:i:s'))); $old_till += $daily_count->amount; $account_change = AccountTransactionContent::sum('amount', array('Account.code_name' => 'till', 'AccountTransaction.timestamp:>' => $daily_count->time, 'AccountTransaction.timestamp:<=' => date('Y-m-d H:i:s'))); $old_till += $account_change; $sales = Transaction::sum('amount', array('timestamp:>' => $daily_count->time)); $stock_amount = TransactionContent::sum('stock_usage', array('Transaction.timestamp:>' => $daily_count->time, 'Transaction.timestamp:<=' => date('Y-m-d H:i:s'))); ?> <script type="text/javascript"> <!-- function update_diff(value) { var calc = document.getElementById('calculated').innerHTML; var diff = document.getElementById('diff'); var html = '' if(value != '') { html = value - calc; } diff.innerHTML = html; } --> </script> <h1>Dagsavslut</h1> <table> <tr> <th>Senast dagsavslut:</th>
public static function last() { $ret = DailyCount::selection(array('@order' => 'time:desc', '@limit' => 1)); return array_shift($ret); }