foreach ($_POST as $k => $v) { // Trigger process only when matchin this if (!preg_match('/^(\\d+)_id$/', $k, $m)) { continue; // ignore others } $i = $m[1]; // Debit or Credit $dr = floatval(preg_replace('/[^\\d\\.]+/', null, $_POST["{$i}_dr"])); $cr = floatval(preg_replace('/[^\\d\\.]+/', null, $_POST["{$i}_cr"])); // Skip Empty if ($cr == 0 && $dr == 0) { continue; } $id = intval($_POST["{$i}_id"]); $ale = new AccountLedgerEntry($id); $ale['auth_user_id'] = $_SESSION['uid']; $ale['account_id'] = $_POST["{$i}_account_id"]; $ale['account_journal_id'] = $aje['id']; // $ale->note = $req->getPost($i . '_note'); $ale['amount'] = $dr > $cr ? abs($dr) * -1 : abs($cr); // Bind to an object $ale['link_id'] = $_POST["{$i}_link_id"]; $ale['link_to'] = $_POST["{$i}_link_to"]; // Save Ledger Entry $ale->save(); // $_SESSION['account-transaction-list'][] = $ale; // Save Ledger Entry to Wizard // $awj->addLedgerEntry($ale); if ($id) { Session::flash('info', 'Account Ledger Entry #' . $id . ' updated');
// Journal Entry $je = new AccountJournalEntry(); $je['auth_user_id'] = $_SESSION['uid']; $je['date'] = $_POST['date']; // $req->getPost('date'); $je['note'] = $_POST['note']; // $req->getPost('note'); $je['kind'] = 'N'; // $req->getPost('kind'); $je->save(); // Debit Side $dr = new AccountLedgerEntry(); $dr['auth_user_id'] = $_SESSION['uid']; $dr['account_journal_id'] = $je['id']; // Credit Side $cr = new AccountLedgerEntry(); $cr['auth_user_id'] = $_SESSION['uid']; $cr['account_journal_id'] = $je['id']; if (!empty($_POST['cr'])) { // Credit to the Upload Target Account $cr['account_id'] = $_ENV['upload_account_id']; $cr['amount'] = abs(preg_replace('/[^\\d\\.]+/', null, $_POST['cr'])); $dr['account_id'] = $_POST['offset_account_id']; $dr['amount'] = abs(preg_replace('/[^\\d\\.]+/', null, $_POST['cr'])) * -1; } elseif (!empty($_POST['dr'])) { // Debit to the Upload Target Account $cr['account_id'] = $_POST['offset_account_id']; $cr['amount'] = abs(preg_replace('/[^\\d\\.]+/', null, $_POST['dr'])); $dr['account_id'] = $_ENV['upload_account_id']; $dr['amount'] = abs(preg_replace('/[^\\d\\.]+/', null, $_POST['dr'])) * -1; }