function submitJournalEntry() { global $db, $currencies, $messageStack; $entry_count = 0; $row_cnt = 0; while ($row_cnt < count($this->records)) { $order = $this->records[$row_cnt]; $glEntry = new journal(); // determine if date is within a known period, if date is before period 1 use period = 0 (and enter beginning balances) $glEntry->period = gen_calculate_period($order['post_date'], $hide_error = true); // date format YYYY-MM-DD if (!$glEntry->period) { $glEntry->period = 1; } // if out of range default to first period (required to be valid period or it won't post) // build journal main entry $glEntry->journal_id = JOURNAL_ID; $glEntry->post_date = $order['post_date']; $glEntry->description = sprintf(TEXT_JID_ENTRY, constant('ORD_TEXT_' . JOURNAL_ID . '_WINDOW_TITLE')); $glEntry->short_name = $order['account_id']; $glEntry->ship_short_name = $order['account_id']; $glEntry->gl_acct_id = $order['gl_acct']; $glEntry->total_amount = $order['total_amount']; $glEntry->currencies_code = DEFAULT_CURRENCY; $glEntry->purchase_invoice_id = $order['order_id']; $glEntry->admin_id = $_SESSION['admin_id']; // set imported dept rep id to current logged in user if ($order['waiting']) { $glEntry->waiting = '1'; } $glEntry->bill_primary_name = $order['bill_primary_name']; $glEntry->bill_contact = $order['bill_contact']; $glEntry->bill_address1 = $order['bill_address1']; $glEntry->bill_address2 = $order['bill_address2']; $glEntry->bill_city_town = $order['bill_city_town']; $glEntry->bill_state_province = $order['bill_state_province']; $glEntry->bill_postal_code = $order['bill_postal_code']; $glEntry->bill_country_code = $order['bill_country_code']; $glEntry->bill_telephone1 = $order['telephone1']; $glEntry->bill_telephone2 = $order['telephone2']; $glEntry->bill_fax = $order['fax']; $glEntry->bill_email = $order['email']; $glEntry->bill_website = $order['website']; switch (JOURNAL_ID) { case 4: case 6: $glEntry->ship_primary_name = COMPANY_NAME; $glEntry->ship_address1 = COMPANY_ADDRESS1; $glEntry->ship_address2 = COMPANY_ADDRESS2; $glEntry->ship_city_town = COMPANY_CITY_TOWN; $glEntry->ship_state_province = COMPANY_ZONE; $glEntry->ship_postal_code = COMPANY_POSTAL_CODE; $glEntry->ship_country_code = COMPANY_COUNTRY; break; default: $glEntry->ship_primary_name = $order['ship_primary_name']; $glEntry->ship_contact = $order['ship_contact']; $glEntry->ship_address1 = $order['ship_address1']; $glEntry->ship_address2 = $order['ship_address2']; $glEntry->ship_city_town = $order['ship_city_town']; $glEntry->ship_state_province = $order['ship_state_province']; $glEntry->ship_postal_code = $order['ship_postal_code']; $glEntry->ship_country_code = $order['ship_country_code']; } $glEntry->journal_main_array = $glEntry->build_journal_main_array(); $glEntry->journal_main_array['purchase_invoice_id'] = $order['order_id']; // skip validating the invoice ID, just set it // Create the account (or update it) $glEntry->bill_acct_id = $glEntry->add_account(BB_ACCOUNT_TYPE . 'b', 0, 0, true); switch (JOURNAL_ID) { default: // update the shipping address $glEntry->ship_acct_id = $glEntry->add_account(BB_ACCOUNT_TYPE . 's', 0, 0, true); break; case 4: // skip for purchases (assume default company address) // skip for purchases (assume default company address) case 6: } // build journal row entries (2) one for the AP/AR account and the other for the beg bal equity account $glEntry->journal_rows = array(); $total_amount = 0; while (true) { $credit_debit = false; switch (JOURNAL_ID) { case 4: $credit_debit = 'debit_amount'; // for journal_id = 4 // for journal_id = 4 case 10: if (!$credit_debit) { $credit_debit = 'credit_amount'; } // for journal_id = 10 $glEntry->journal_rows[] = array('gl_type' => BB_GL_TYPE, 'qty' => $currencies->clean_value($order['quantity']), 'sku' => $order['sku'], 'description' => $order['description'], 'gl_account' => $order['inv_gl_acct'], 'taxable' => $order['taxable'] ? $order['taxable'] : 0, $credit_debit => $currencies->clean_value($order['total_cost']), 'post_date' => $order['post_date']); break; case 6: $credit_debit = 'debit_amount'; // for journal_id = 6 // for journal_id = 6 case 12: if (!$credit_debit) { $credit_debit = 'credit_amount'; } // for journal_id = 12 $glEntry->journal_rows[] = array('gl_type' => BB_GL_TYPE, 'qty' => '1', 'description' => constant('ORD_TEXT_' . JOURNAL_ID . '_WINDOW_TITLE') . '-' . TEXT_IMPORT, 'gl_account' => $order['inv_gl_acct'], 'taxable' => $order['taxable'] ? $order['taxable'] : 0, $credit_debit => $order['total_amount'], 'post_date' => $order['post_date']); break; } $total_amount += $currencies->clean_value($order['total_cost']); $next_order = $this->records[$row_cnt + 1]['order_id']; if ((JOURNAL_ID == 4 || JOURNAL_ID == 10) && $order['order_id'] == $next_order) { // more line items $row_cnt++; $order = $this->records[$row_cnt]; } else { // end of this order, break from while(true) loop break; } } // build the total journal_item row switch (JOURNAL_ID) { case 6: $total_amount = $order['total_amount']; // and continue // and continue case 4: $debit_credit = 'credit_amount'; break; case 12: $total_amount = $order['total_amount']; // and continue // and continue case 10: $debit_credit = 'debit_amount'; break; } $glEntry->journal_rows[] = array('gl_type' => 'ttl', 'description' => constant('ORD_TEXT_' . $glEntry->journal_id . '_WINDOW_TITLE') . '-' . TEXT_TOTAL, 'gl_account' => $order['gl_acct'], $debit_credit => $total_amount, 'post_date' => $order['post_date']); $glEntry->journal_main_array['total_amount'] = $total_amount; if (!$glEntry->Post('insert')) { return false; } $entry_count++; $row_cnt++; } $this->line_count = $entry_count; return true; }
switch ($transaction->type) { case 'cash_in': $credit_amount = ''; $debit_amount = $currencies->clean_value(db_prepare_input($_POST['ot_amount']), $order->currencies_code) / $order->currencies_value; $tills->adjust_balance($debit_amount); break; default: $debit_amount = ''; $credit_amount = $currencies->clean_value(db_prepare_input($_POST['ot_amount']), $order->currencies_code) / $order->currencies_value; $tills->adjust_balance(-$credit_amount); } $order->journal_rows[] = array('id' => '', 'qty' => '1', 'gl_type' => 'ttl', 'gl_account' => $tills->gl_acct_id, 'description' => db_prepare_input($_POST['ot_desc']) == '' ? $transaction->description : db_prepare_input($_POST['ot_desc']), 'debit_amount' => $debit_amount, 'credit_amount' => $credit_amount, 'post_date' => date('Y-m-d')); if ($transaction->type == 'expenses') { $tax = $currencies->clean_value(db_prepare_input($_POST['ot_tax']), $order->currencies_code) / $order->currencies_value; $tax_auths = gen_build_tax_auth_array(); $order->journal_rows[] = array('id' => '', 'qty' => '1', 'gl_type' => 'tax', 'gl_account' => $tax_auths[$_POST['ot_rate']]['account_id'], 'description' => $transaction->description, 'taxable' => db_prepare_input($_POST['ot_rate']), 'debit_amount' => $tax, 'credit_amount' => $debit_amount, 'post_date' => date('Y-m-d')); $order->journal_rows[] = array('id' => '', 'qty' => '1', 'gl_type' => 'sos', 'gl_account' => $transaction->gl_acct_id, 'description' => $transaction->description, 'debit_amount' => $credit_amount - $tax, 'credit_amount' => $debit_amount, 'post_date' => date('Y-m-d')); } else { $order->journal_rows[] = array('id' => '', 'qty' => '1', 'gl_type' => 'sos', 'gl_account' => $transaction->gl_acct_id, 'description' => $transaction->description, 'debit_amount' => $credit_amount, 'credit_amount' => $debit_amount, 'post_date' => date('Y-m-d')); } $error = $order->Post('insert', true); if (DEBUG) { $messageStack->write_debug(); } $xml .= "\t" . xmlEntry("action", $_REQUEST['action']); if ($error) { $xml .= "\t" . xmlEntry("error", $error); } //if ($order->errormsg) $xml .= "\t" . xmlEntry("error", $order->errormsg); echo createXmlHeader() . $xml . createXmlFooter(); die;
} 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'); gen_add_audit_log(GEN_ADM_TOOLS_AUDIT_LOG_RE_POST, "inventory owed"); }
} $sku = db_prepare_input($_POST['sku_' . $rowCnt]); $qty = db_prepare_input($_POST['qty_' . $rowCnt]); $serialize_number = db_prepare_input($_POST['serial_' . $rowCnt]); $desc = db_prepare_input($_POST['desc_' . $rowCnt]); // $acct = db_prepare_input($_POST['acct_'.$rowCnt]); $cost = db_prepare_input($_POST['total_' . $rowCnt]); if ($sku && $sku != TEXT_SEARCH) { $glEntry->journal_rows[] = array('sku' => $sku, 'qty' => $qty, 'gl_type' => 'adj', 'serialize_number' => $serialize_number, 'gl_account' => $_POST['acct_' . $rowCnt], 'description' => $desc, 'debit_amount' => $cost, 'credit_amount' => 0, 'post_date' => $post_date); $glEntry->journal_rows[] = array('sku' => '', 'qty' => '', 'gl_type' => 'ttl', 'gl_account' => $_POST['cogs_acct_' . $rowCnt], 'description' => BOX_INV_TRANSFER . ' - ' . $adj_reason, 'debit_amount' => 0, 'credit_amount' => $cost, 'post_date' => $post_date); $tot_amount += $cost; } $rowCnt++; } $glEntry->journal_main_array['total_amount'] = $tot_amount; if (!$glEntry->Post($glEntry->id ? 'edit' : 'insert')) { $error = true; } // Now, link first record to second record so edits can be made else will crash when entry is edited. $db->Execute("UPDATE " . TABLE_JOURNAL_MAIN . " SET so_po_ref_id={$glEntry->id} WHERE id={$first_id}"); if (!$error) { $db->transCommit(); } // post the chart of account values // *************** END TRANSACTION ************************* gen_add_audit_log(sprintf(INV_LOG_TRANSFER, $source_store_id, $dest_store_id), $sku, $qty); $messageStack->add(INV_POST_SUCCESS . $glEntry->purchase_invoice_id, 'success'); if (DEBUG) { $messageStack->write_debug(); } gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
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; } }
function processOrders($upload_name = 'file_name') { global $db, $messageStack; $period = gen_calculate_period(date('Y-m-d')); if (!defined('JOURNAL_ID')) { define('JOURNAL_ID', 12); } // load the amazon contact record info $result = $db->Execute("SELECT id FROM " . TABLE_CONTACTS . " WHERE short_name='" . MODULE_AMAZON_CUSTOMER_ID . "'"); $cID = $result->fields['id']; if (!$cID) { $messageStack->add("Contact could not be found in the Customer database. Please make sure the setting in the defaults.php file match your Customers value.", 'error'); return; } $result = $db->Execute("SELECT * FROM " . TABLE_ADDRESS_BOOK . " WHERE ref_id={$cID} AND type='cm'"); $commonMain = array('post_date' => date('Y-m-d'), 'period' => $period, 'journal_id' => JOURNAL_ID, 'currencies_code' => DEFAULT_CURRENCY, 'terminal_date' => date('Y-m-d'), 'store_id' => 0, 'admin_id' => $_SESSION['admin_id'], 'rep_id' => 0, 'gl_acct_id' => MODULE_AMAZON_DEFAULT_RECEIVABLES_GL_ACCT, 'bill_acct_id' => $result->fields['ref_id'], 'bill_address_id' => $result->fields['address_id'], 'bill_primary_name' => $result->fields['primary_name'], 'bill_contact' => $result->fields['contact'], 'bill_address1' => $result->fields['address1'], 'bill_address2' => $result->fields['address2'], 'bill_city_town' => $result->fields['city_town'], 'bill_state_province' => $result->fields['state_province'], 'bill_postal_code' => $result->fields['postal_code'], 'bill_country_code' => $result->fields['country_code'], 'bill_telephone1' => $result->fields['telephone1'], 'bill_email' => $result->fields['email'], 'drop_ship' => '1'); $bill_acct_id = $result->fields['ref_id']; // iterate through the map to set journal post variables, orders may be on more than 1 line // ***************************** START TRANSACTION ******************************* $db->transStart(); $itemCnt = 1; $items = array(); $totals = array(); $inStock = true; $orderCnt = 0; $skip = false; $runaway = 0; $rows = file($_FILES[$upload_name]['tmp_name']); $row = array_shift($rows); // heading $this->headings = explode("\t", $row); $row = array_shift($rows); // first order if (!$row) { $messageStack->add("There were no orders to process!", 'caution'); return; } $data = $this->processRow($row); while (true) { if (!$row) { break; } $main = $commonMain; $main['purch_order_id'] = $data['order-id']; $main['description'] = "Amazon Order # " . $data['order-id']; $main['shipper_code'] = MODULE_AMAZON_DEFAULT_SHIPPING_CARRIER; if (strlen($data['recipient-name']) > 32 || strlen($data['ship-address-1']) > 32 || strlen($data['ship-address-2']) > 32) { $messageStack->add(sprintf("Order # %s has a name or address that is too long for the PhreeBooks db and has been truncated: %s", $data['order-id'], $data['recipient-name']), 'caution'); } $main['ship_primary_name'] = $data['recipient-name']; $main['ship_address1'] = $data['ship-address-1']; $main['ship_address2'] = $data['ship-address-2']; $main['ship_contact'] = $data['ship-address-3']; $main['ship_city_town'] = $data['ship-city']; $main['ship_state_province'] = $data['ship-state']; $main['ship_postal_code'] = $data['ship-postal-code']; $main['ship_country_code'] = gen_get_country_iso_3_from_2($data['ship-country']); $main['ship_telephone1'] = $data['buyer-phone-number']; $main['ship_email'] = $data['buyer-email']; // build the item, check stock if auto_journal $inv = $db->Execute("SELECT * FROM " . TABLE_INVENTORY . " WHERE sku='{$data['sku']}'"); $messageStack->debug("\n Executing sql = " . "SELECT * FROM " . TABLE_INVENTORY . " WHERE sku='{$data['sku']}' resulting in:" . print_r($inv->fields, true)); if (!$inv->fields || sizeof($inv->fields) == 0) { $messageStack->add(sprintf("SKU: %s not found in the database, this import was skipped!", $data['sku'])); $skip = true; } else { if ($inv->fields['qty_stock'] < $data['quantity-purchased']) { $inStock = false; } } $items[] = array('item_cnt' => $itemCnt, 'gl_type' => 'sos', 'sku' => $data['sku'], 'qty' => $data['quantity-purchased'], 'description' => $data['product-name'], 'credit_amount' => $data['item-price'], 'gl_account' => $inv->fields['account_sales_income'] ? $inv->fields['account_sales_income'] : MODULE_AMAZON_DEFAULT_SALES_GL_ACCT, 'taxable' => 0, 'full_price' => $inv->fields['full_price'], 'post_date' => substr($data['purchase-date'], 0, 10)); // preset some totals to keep running balance if (!isset($totals['discount'])) { $totals['discount'] = 0; } if (!isset($totals['sales_tax'])) { $totals['sales_tax'] = 0; } if (!isset($totals['total_amount'])) { $totals['total_amount'] = 0; } if (!isset($totals['freight'])) { $totals['freight'] = 0; } // fill in order info $totals['discount'] += $data['item-promotion-discount'] + $data['ship-promotion-discount']; $totals['sales_tax'] += $data['item-tax']; $totals['total_amount'] += $data['item-price'] + $data['item-tax'] + $data['shipping-price'] + $data['shipping-tax']; // missing from file: $data['gift-wrap-price'] and $data['gift-wrap-tax'] $totals['freight'] += $data['shipping-price']; // check for continuation order $row = array_shift($rows); if ($runaway++ > 1000) { $messageStack->add("runaway reached, exiting!", 'error'); break; } if ($row) { // check for continuation order $nextData = $this->processRow($row); // $messageStack->debug("\nContinuing order check, Next order = {$nextData['order-id']} and this order = {$main['purch_order_id']}"); if ($nextData['order-id'] == $main['purch_order_id']) { $data = $nextData; $itemCnt++; continue; // more items for the same order } } // finish main and item to post $main['total_amount'] = $totals['total_amount']; // @todo add tax, shipping, gift wrap, and notes records (add to item array) $items[] = array('qty' => 1, 'gl_type' => 'frt', 'description' => "Shipping Amazon # " . $data['order-id'], 'credit_amount' => $totals['freight'], 'gl_account' => MODULE_AMAZON_DEFAULT_FREIGHT_GL_ACCT, 'taxable' => 0, 'post_date' => substr($data['purchase-date'], 0, 10)); $items[] = array('qty' => 1, 'gl_type' => 'ttl', 'description' => "Total Amazon # " . $data['order-id'], 'debit_amount' => $totals['total_amount'], 'gl_account' => MODULE_AMAZON_DEFAULT_RECEIVABLES_GL_ACCT, 'post_date' => substr($data['purchase-date'], 0, 10)); $dup = $db->Execute("SELECT id FROM " . TABLE_JOURNAL_MAIN . " WHERE purch_order_id='{$main['purch_order_id']}'"); if ($dup->fields['id']) { // $messageStack->debug("duplicate order id = ".$dup->fields['id']." and main = ".print_r($main, true)); $messageStack->add(sprintf("Order # %s has already been imported! It will be skipped.", $data['order-id']), 'caution'); continue; } $ledger = new journal(); $ledger->post_date = substr($data['purchase-date'], 0, 10); $ledger->period = $period; $ledger->closed = '0'; $ledger->journal_id = JOURNAL_ID; $ledger->bill_acct_id = $bill_acct_id; $ledger->journal_main_array = $main; $ledger->journal_rows = $items; if (!$skip) { if (!$ledger->validate_purchase_invoice_id()) { return false; } if (!$ledger->Post('insert')) { return; } $orderCnt++; } // prepare for next order. $data = $nextData; $itemCnt = 1; $items = array(); $totals = array(); $inStock = true; $skip = false; } if ($orderCnt) { if (!$ledger->update_chart_history_periods($period)) { return; } } $db->transCommit(); // finished successfully // ***************************** END TRANSACTION ******************************* $messageStack->add(sprintf("Successfully posted %s Amazon transactions.", $orderCnt), 'success'); if (DEBUG) { $messageStack->write_debug(); } return true; }
$glEntry->journal_id = JOURNAL_ID; $glEntry->post_date = date('Y-m-d'); $glEntry->period = gen_calculate_period($glEntry->post_date); if (!$glEntry->period) { break; } $glEntry->purchase_invoice_id = $wo_num; $glEntry->store_id = isset($_POST['store_id']) ? $_POST['store_id'] : 0; $glEntry->closed = '1'; // closes by default $glEntry->journal_main_array = $glEntry->build_journal_main_array(); // build journal entry based on adding or subtracting from inventory, debit/credit will be calculated by COGS $glEntry->journal_rows[] = array('gl_type' => 'asy', 'sku' => $sku, 'qty' => $qty, 'description' => $desc, 'gl_account' => $acct); // *************** START TRANSACTION ************************* $db->transStart(); if (!$glEntry->Post('insert')) { $db->transRollback(); $error = true; } else { $db->transCommit(); // post the chart of account values gen_add_audit_log(INV_LOG_ASSY . TEXT_SAVE, $sku, $qty); $messageStack->add(INV_POST_ASSEMBLY_SUCCESS . $sku, 'success'); if (DEBUG) { $messageStack->write_debug(); } // *************** END TRANSACTION ************************* } } if (!$error) { $db->Execute("update " . TABLE_WO_JOURNAL_ITEM . " set complete = '1', admin_id = " . $_SESSION['admin_id'] . " \n\t where ref_id = {$id} and step = {$step}");
$order->journal_rows[$i]['gl_type'] = GL_TYPE; } } // ***************************** START TRANSACTION ******************************* $db->transStart(); if ($purchase_invoice_id) { $order->journal_main_array['purchase_invoice_id'] = $purchase_invoice_id; $order->purchase_invoice_id = $purchase_invoice_id; } else { $order->purchase_invoice_id = ''; if (!$order->validate_purchase_invoice_id()) { $error = true; break; } } if (!$order->Post('insert')) { $error = true; } if ($order->purchase_invoice_id == '') { if (!$order->increment_purchase_invoice_id()) { $error = true; } } if (!$error) { gen_add_audit_log(constant('ORD_TEXT_' . JOURNAL_ID . '_WINDOW_TITLE') . ' - ' . TEXT_ADD, $order->purchase_invoice_id, $order->total_amount); // set the closed flag on the quote $result = $db->Execute("update " . TABLE_JOURNAL_MAIN . " set closed = '1' where id = " . $id); $db->transCommit(); // finished successfully // ***************************** END TRANSACTION ******************************* }
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; }