function repost_journals($journals, $start_date, $end_date) { global $db, $messageStack; if (sizeof($journals) > 0) { $sql = "select id from " . TABLE_JOURNAL_MAIN . " \r\n\t\twhere journal_id in (" . implode(',', $journals) . ") \r\n\t\tand post_date >= '" . $start_date . "' and post_date < '" . gen_specific_date($end_date, 1) . "' \r\n\t\torder by id"; $result = $db->Execute($sql); $cnt = 0; $db->transStart(); while (!$result->EOF) { $gl_entry = new journal($result->fields['id']); $gl_entry->remove_cogs_rows(); // they will be regenerated during the re-post if (!$gl_entry->Post('edit', true)) { $db->transRollback(); $messageStack->add('<br /><br />Failed Re-posting the journals, try a smaller range. The record that failed was # ' . $gl_entry->id, 'error'); return false; } $cnt++; $result->MoveNext(); } $db->transCommit(); return $cnt; } }
$messageStack->add(sprintf(GEN_ADM_TOOLS_RE_POST_SUCCESS, $repost_cnt), 'success'); gen_add_audit_log(GEN_ADM_TOOLS_AUDIT_LOG_RE_POST, implode(',', $journals)); } if (DEBUG) { $messageStack->write_debug(); } break; case 'inv_owed_fix': validate_security($security_level, 3); $error = false; $result = $db->Execute("SELECT journal_main_id FROM " . TABLE_INVENTORY_COGS_OWED); $cnt = 0; $db->transStart(); while (!$result->EOF) { $gl_entry = new journal($result->fields['journal_main_id']); $gl_entry->remove_cogs_rows(); // they will be regenerated during the re-post if (!$gl_entry->Post('edit', true)) { $db->transRollback(); $messageStack->add('<br /><br />Failed Re-posting the inventory owed. The record that failed was # ' . $gl_entry->id, 'error'); $error = true; break; } $cnt++; $result->MoveNext(); } $db->transCommit(); if ($error) { $messageStack->add(GEN_ADM_TOOLS_RE_POST_FAILED, 'caution'); } else { $messageStack->add(sprintf(GEN_ADM_TOOLS_RE_POST_SUCCESS, $cnt), 'success');
function unPost($action = 'delete', $skip_balance = false) { global $db, $messageStack; $messageStack->debug("\n\nunPosting Journal... id = " . $this->id . " and action = " . $action . " and journal_id = " . $this->journal_id); if (!$this->check_for_re_post()) { return false; } // check for dependent records that will need to be re-posted if (!$this->unPost_account_sales_purchases()) { return false; } // unPost the customer/vendor history // unPost_chart_balances needs to be unPosted before inventory because inventory may remove journal rows (COGS) if (!$this->unPost_chart_balances()) { return false; } // unPost the chart of account values if (!$this->unPost_inventory()) { return false; } $messageStack->debug("\n Deleting Journal main and rows as part of unPost ..."); $result = $db->Execute("delete from " . TABLE_JOURNAL_MAIN . " where id = " . $this->id); if ($result->AffectedRows() != 1) { return $this->fail_message(GL_ERROR_CANNOT_DELETE_MAIN); } $result = $db->Execute("delete from " . TABLE_JOURNAL_ITEM . " where ref_id = " . $this->id); if ($result->AffectedRows() == 0) { return $this->fail_message(printf(GL_ERROR_CANNOT_DELETE_ITEM, $this->id)); } if ($action != 'edit') { // re-post affected entries unless edited (which is after the entry is reposted) if (is_array($this->repost_ids)) { // rePost any journal entries unPosted to rollback COGS calculation while ($id = array_shift($this->repost_ids)) { $messageStack->debug("\n\nRe-posting as part of unPost - Journal main id = " . $id); $gl_entry = $this->unPost_entry[$id]; if (!is_object($gl_entry)) { // for the delete case, the affected journal objects have not been created $gl_entry = new journal($id); $gl_entry->remove_cogs_rows(); // they will be regenerated during the re-post if (!$gl_entry->Post('edit', true)) { return false; } } else { $gl_entry->remove_cogs_rows(); // they will be regenerated during the re-post if (!$gl_entry->Post('insert', true)) { return false; } } $this->affected_accounts = gen_array_key_merge($this->affected_accounts, $gl_entry->affected_accounts); $this->first_period = min($gl_entry->period, $this->first_period); } } } if (!$skip_balance) { if (!$this->update_chart_history_periods($this->period)) { return false; } } if (!$this->check_for_closed_po_so('unPost')) { return false; } // check to re-open predecessor entry $messageStack->debug("\nend unPosting Journal.\n"); return true; }