예제 #1
0
 public function __construct($id = '')
 {
     $this->purchase_invoice_id = 'DP' . date('Ymd');
     $this->gl_acct_id = $_SESSION['admin_prefs']['def_cash_acct'] ? $_SESSION['admin_prefs']['def_cash_acct'] : AR_SALES_RECEIPTS_ACCOUNT;
     $this->store_id = isset($_SESSION['admin_prefs']['def_store_id']) ? $_SESSION['admin_prefs']['def_store_id'] : 0;
     parent::__construct($id);
 }
예제 #2
0
 function __construct($id = '')
 {
     global $db;
     switch ($this->journal_id) {
         case 19:
             $this->gl_acct_id = $_SESSION['admin_prefs']['def_cash_acct'] ? $_SESSION['admin_prefs']['def_cash_acct'] : AR_SALES_RECEIPTS_ACCOUNT;
             $this->gl_disc_acct_id = AR_DISCOUNT_SALES_ACCOUNT;
             $this->purchase_invoice_id = 'DP' . date('Ymd');
             break;
         case 21:
             $this->gl_acct_id = $_SESSION['admin_prefs']['def_cash_acct'] ? $_SESSION['admin_prefs']['def_cash_acct'] : AP_PURCHASE_INVOICE_ACCOUNT;
             $this->gl_disc_acct_id = AP_DISCOUNT_PURCHASE_ACCOUNT;
             $result = $db->Execute("select next_check_num from " . TABLE_CURRENT_STATUS);
             $this->purchase_invoice_id = $result->fields['next_check_num'];
             break;
         default:
             $this->fail_message = 'bad journal ID in phreepos/classes/phreepos.php!';
     }
     $this->bill_primary_name = GEN_PRIMARY_NAME;
     $this->bill_contact = GEN_CONTACT;
     $this->bill_address1 = GEN_ADDRESS1;
     $this->bill_address2 = GEN_ADDRESS2;
     $this->bill_city_town = GEN_CITY_TOWN;
     $this->bill_state_province = GEN_STATE_PROVINCE;
     $this->bill_postal_code = GEN_POSTAL_CODE;
     $this->bill_country_code = COMPANY_COUNTRY;
     parent::__construct($id = '');
 }
예제 #3
0
 public function __construct($id = '')
 {
     global $db;
     $result = $db->Execute("select next_check_num from " . TABLE_CURRENT_STATUS);
     $this->purchase_invoice_id = $result->fields['next_check_num'];
     $this->gl_acct_id = $_SESSION['admin_prefs']['def_cash_acct'] ? $_SESSION['admin_prefs']['def_cash_acct'] : AP_PURCHASE_INVOICE_ACCOUNT;
     parent::__construct($id);
 }
예제 #4
0
 public static function write_error_message($type, $error, $file, $line, $context)
 {
     $nameType = '';
     switch ($type) {
         case E_USER_ERROR:
             $nameType = 'PHP error :';
             break;
         case E_USER_WARNING:
             $nameType = 'Warning :';
             break;
         case E_USER_NOTICE:
             $nameType = 'Notice :';
             break;
         case journal::E_FRAMEWORK:
             $nameType = 'simPHPle error :';
             break;
         case journal::INFO:
             $nameType = 'Info :';
             break;
         default:
             $nameType = 'Unknown error :';
             break;
     }
     if (self::$store) {
         $file = journal::get_filename();
         if ($line >= 0) {
             $content = '[' . date('Y/m/d at H:i:s') . '] ' . $nameType . ' (line:' . $line . ', in file : ' . $file . ') ' . $error;
         } else {
             $content = '[' . date('Y/m/d at H:i:s') . '] ' . $nameType . ' ' . $error;
         }
         $lines = file($file);
         $lines[] = $content;
         $total = '';
         foreach ($lines as $text) {
             if ($text != "\n") {
                 $text = rtrim($text, "\n");
                 $total .= $text . "\n";
             }
         }
         file_put_contents($file, $total);
     } else {
         // meh
     }
 }
예제 #5
0
 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;
 }
예제 #6
0
<?php

require 'journal.php';
$journal = new journal();
if (isset($_GET['entryID']) && is_numeric($_GET['entryID']) && $_GET['entryID'] > 0) {
    echo json_encode($journal->getJournalEntry($_GET['entryID']));
} else {
    echo json_encode($journal->getJournalHeadlines());
}
예제 #7
0
                 $messageStack->add(sprintf(GEN_ADM_TOOLS_REPAIR_BALANCE_ERROR_MSG, $period, $acct, $currencies->format($history[$acct][$period + 1]['beg_bal']), $currencies->format($next_beg_bal)), 'caution');
             }
             $bad_accounts[$acct][$period + 1]['beginning_balance'] = $next_beg_bal;
             $history[$acct][$period + 1]['beg_bal'] = $next_beg_bal;
             $first_error_period = min($first_error_period, $period);
         }
         /*		$totals[$period]['beg_bal'] += $history[$acct][$period]['beg_bal'];
         		$totals[$period]['debit']   += $history[$acct][$period]['debit'];
         		$totals[$period]['credit']  += $history[$acct][$period]['credit'];
         		// read and check history db values*/
     }
 }
 if ($_REQUEST['action'] == 'coa_hist_fix' && sizeof($bad_accounts) > 0) {
     // *************** START TRANSACTION *************************
     $db->transStart();
     $glEntry = new journal();
     foreach ($bad_accounts as $gl_acct => $acct_array) {
         $glEntry->affected_accounts[$gl_acct] = 1;
         foreach ($acct_array as $period => $sql_data_array) {
             db_perform(TABLE_CHART_OF_ACCOUNTS_HISTORY, $sql_data_array, 'update', "account_id='" . $gl_acct . "' and period=" . $period);
         }
     }
     $min_period = max($first_error_period, 2);
     // avoid a crash if min_period is the first period
     if ($glEntry->update_chart_history_periods($min_period - 1)) {
         // from prior period than the error account
         $db->transCommit();
         $messageStack->add(GEN_ADM_TOOLS_REPAIR_COMPLETE, 'success');
         gen_add_audit_log(GEN_ADM_TOOLS_REPAIR_LOG_ENTRY);
     }
 }
예제 #8
0
$jr_work = get_request_variable('jr_work', 2);
$jr_state = get_request_variable('jr_state', '');
$date = get_request_variable('date', '');
$date2 = get_request_variable('date2', '');
$start_time = get_request_variable('start_time', '');
$stop_time = get_request_variable('stop_time', '');
$date = parse_date('{Y}-{m}-{d}', $date, false);
$date2 = parse_date('{Y}-{m}-{d}', $date2, false);
$description = get_request_variable('description', '');
if ($id == 0) {
    $jr_state = 1;
}
$save = get_request_variable('save', '');
$_REQUEST['callback'] = get_request_variable('callback', '');
$db = db_class::get_instance();
$journal = new journal();
$journal->id = $id;
if ($id > 0) {
    if (!$journal->Load()) {
        $journal->id = 0;
    }
}
for ($i = 0; $i < count($STORAGE['menu']); $i++) {
    if (strpos($STORAGE['menu'][$i]['path'], 'journal') !== false) {
        $menulevel = $STORAGE['menu'][$i];
        break;
    }
}
$STORAGE['site_path'][] = array('name' => $menulevel['name'], 'path' => $menulevel['path']);
$menulevel = $menulevel['childs'][0];
$STORAGE['site_path'][] = array('name' => $menulevel['name'], 'path' => $menulevel['path']);
예제 #9
0
                 $messageStack->write_debug();
             }
             gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
         }
         // *************** END TRANSACTION *************************
     } else {
         $messageStack->add(INV_ADJ_QTY_ZERO, 'error');
     }
     $error = $messageStack->add(GL_ERROR_NO_POST, 'error');
     $cInfo = new objectInfo($_POST);
     break;
 case 'delete':
     validate_security($security_level, 4);
     // security check
     if ($glEntry->id) {
         $delOrd = new journal();
         $delOrd->journal($glEntry->id);
         // load the posted record based on the id submitted
         // *************** START TRANSACTION *************************
         $db->transStart();
         if ($delOrd->unPost('delete')) {
             $db->transCommit();
             // if not successful rollback will already have been performed
             gen_add_audit_log(INV_LOG_ADJ . TEXT_DELETE, $delOrd->journal_rows[0]['sku'], $delOrd->journal_rows[0]['qty']);
             if (DEBUG) {
                 $messageStack->write_debug();
             }
             gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
             break;
         }
     }
예제 #10
0
/***************   hook for custom actions  ***************************/
$custom_path = DIR_FS_MY_FILES . 'custom/orders/popup_convert_po/extra_actions.php';
if (file_exists($custom_path)) {
    include $custom_path;
}
/***************   Act on the action request   *************************/
switch ($action) {
    case 'save':
        $purchase_invoice_id = $_POST['po_num'];
        $drop_ship = isset($_POST['drop_ship']) ? '1' : '0';
        require_once DIR_FS_MODULES . 'gen_ledger/language/' . $_SESSION['language'] . '/language.php';
        require_once DIR_FS_MODULES . 'gen_ledger/classes/gen_ledger.php';
        define('JOURNAL_ID', 4);
        define('GL_TYPE', 'poo');
        // Load the existing sales order
        $order = new journal($id);
        // replace some settings with the new values and re-post
        $order->id = '';
        $order->journal_id = JOURNAL_ID;
        $order->post_date = date('Y-m-d', time());
        // make post date today
        $order->period = gen_calculate_period($order->post_date);
        $order->closed = '0';
        $order->gl_acct_id = AP_DEFAULT_PURCHASE_ACCOUNT;
        $order->purchase_invoice_id = $purchase_invoice_id;
        $order->admin_id = $_SESSION['admin_id'];
        $order->terminal_date = $order->post_date;
        // make ship date the same as post date
        $order->description = constant('GENERAL_JOURNAL_' . JOURNAL_ID . '_DESC');
        $order->drop_ship = $drop_ship;
        $temp_rows = $order->journal_rows;
예제 #11
0
gen_pull_language('phreebooks');
require_once DIR_FS_WORKING . 'classes/tills.php';
require_once DIR_FS_MODULES . 'phreebooks/functions/phreebooks.php';
require_once DIR_FS_MODULES . 'phreebooks/classes/gen_ledger.php';
require_once DIR_FS_MODULES . 'phreebooks/classes/banking.php';
/**************   page specific initialization  *************************/
$error = false;
$till_known = false;
$cleared_items = array();
$current_cleard_items = unserialize($_POST['current_cleard_items']);
$all_items = array();
$gl_types = array('pmt', 'ttl', 'tpm');
$post_date = $_POST['post_date'] ? gen_db_date($_POST['post_date']) : '';
$payment_modules = load_all_methods('payment');
$tills = new tills();
$glEntry = new journal();
if (isset($_GET['till_id'])) {
    $tills->get_till_info(db_prepare_input($_GET['till_id']));
    $post_date = gen_db_date(gen_locale_date(date('Y-m-d')));
} else {
    if (isset($_POST['till_id'])) {
        $tills->get_till_info(db_prepare_input($_POST['till_id']));
    } else {
        if ($tills->showDropDown() == false) {
            $tills->get_default_till_info();
        } else {
            $post_date = '';
            $_REQUEST['action'] = '';
        }
    }
}
예제 #12
0
     gen_add_audit_log(GL_LOG_FY_UPDATE . TEXT_UPDATE);
     break;
 case 'new':
     if ($security_level < 2) {
         $messageStack->add_session(ERROR_NO_PERMISSION, 'error');
         gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
         break;
     }
     $result = $db->Execute("select * from " . TABLE_ACCOUNTING_PERIODS . " where period = " . $highest_period);
     $next_fy = $result->fields['fiscal_year'] + 1;
     $next_period = $result->fields['period'] + 1;
     $next_start_date = date('Y-m-d', strtotime($result->fields['end_date']) + 60 * 60 * 24);
     $highest_period = validate_fiscal_year($next_fy, $next_period, $next_start_date);
     build_and_check_account_history_records();
     // *************** roll account balances into next fiscal year *************************
     $glEntry = new journal();
     $result = $db->Execute("select id from " . TABLE_CHART_OF_ACCOUNTS);
     while (!$result->EOF) {
         $glEntry->affected_accounts[$result->fields['id']] = 1;
         $result->MoveNext();
     }
     $glEntry->update_chart_history_periods(CURRENT_ACCOUNTING_PERIOD);
     // from current period through new fiscal year
     $fy = $next_fy;
     // set the pointer to open the fiscal year added
     gen_add_audit_log(GL_LOG_FY_UPDATE . TEXT_ADD);
     break;
 case "change":
     // retrieve the desired period and update the system default values.
     if ($security_level < 3) {
         $messageStack->add_session(ERROR_NO_PERMISSION, 'error');
예제 #13
0
 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;
 }
예제 #14
0
<?php

$page_title = 'Удаление записи журнала';
$errors = array();
$id = intval(get_request_variable('id', 0));
$_REQUEST['callback'] = get_request_variable('callback', '');
$journal = new journal();
$journal->id = $id;
if ($id > 0) {
    if ($journal->Load()) {
        $errors = $journal->IsValidData();
        if (!$errors) {
            $journal->Delete();
        }
    }
}
include SITE_FILE_ROOT . 'template/simple_header.php';
include SITE_FILE_ROOT . 'template/' . $STORAGE['module'] . '/' . $STORAGE['action'] . '.php';
include SITE_FILE_ROOT . 'template/simple_footer.php';
예제 #15
0
function repost_journals($journals, $start_date, $end_date)
{
    global $db, $messageStack;
    if (sizeof($journals) > 0) {
        $sql = "SELECT id FROM " . TABLE_JOURNAL_MAIN . " WHERE journal_id IN (" . implode(',', $journals) . ") \n\t\tAND post_date>= '{$start_date}' AND post_date<'" . gen_specific_date($end_date, 1) . "' ORDER BY post_date, 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;
    }
}
예제 #16
0
     $db->transRollback();
     $messageStack->add(GL_ERROR_NO_POST, 'error');
     if (DEBUG) {
         $messageStack->write_debug();
     }
     $cInfo = new objectInfo($_POST);
     // if we are here, there was an error, reload page
     $cInfo->post_date = gen_db_date($_POST['post_date']);
     break;
 case 'delete':
     validate_security($security_level, 4);
     // check for errors and prepare extra values
     if (!$glEntry->id) {
         $error = true;
     } else {
         $delGL = new journal();
         $delGL->journal($glEntry->id);
         // load the posted record based on the id submitted
         $recur_id = db_prepare_input($_POST['recur_id']);
         $recur_frequency = db_prepare_input($_POST['recur_frequency']);
         // *************** START TRANSACTION *************************
         $db->transStart();
         if ($recur_id > 0) {
             // will contain recur_id
             $affected_ids = $delGL->get_recur_ids($recur_id, $delGL->id);
             for ($i = 0; $i < count($affected_ids); $i++) {
                 $delGL->id = $affected_ids[$i]['id'];
                 $delGL->journal($delGL->id);
                 // load the posted record based on the id submitted
                 if (!$delGL->unPost('delete')) {
                     $error = true;
예제 #17
0
파일: edit.php 프로젝트: YuriyRusinov/reper
$from_id = get_request_variable('from_id', 0);
$jr_state = get_request_variable('jr_state', '');
$date = get_request_variable('date', '');
$date2 = get_request_variable('date2', '');
$start_time = get_request_variable('start_time', '');
$stop_time = get_request_variable('stop_time', '');
$date = parse_date('{Y}-{m}-{d}', $date, false);
$date2 = parse_date('{Y}-{m}-{d}', $date2, false);
$description = get_request_variable('description', '');
if ($id == 0) {
    $jr_state = 1;
}
$save = get_request_variable('save', '');
$_REQUEST['callback'] = get_request_variable('callback', '');
$db = db_class::get_instance();
$journal = new journal();
$journal->id = $id;
if ($id > 0) {
    if (!$journal->Load()) {
        $journal->id = 0;
    }
} else {
    $from_id = $_SESSION['PST'];
}
if ($save && $kio_id > 0) {
    $journal->id_dl_from = $ika_id;
    //ика
    $journal->id_dl_executor = $exec_id;
    //ответственный
    $journal->id_dl_to = $from_id;
    //исполнитель
예제 #18
0
function validate_gl_balances($action)
{
    global $db, $currencies, $messageStack;
    $fiscal_years = array();
    $sql = "select distinct fiscal_year, min(period) as first_period, max(period) as last_period\r\n\t  from " . TABLE_ACCOUNTING_PERIODS . " group by fiscal_year order by fiscal_year ASC";
    $result = $db->Execute($sql);
    while (!$result->EOF) {
        $fiscal_years[] = array('fiscal_year' => $result->fields['fiscal_year'], 'first_period' => $result->fields['first_period'], 'last_period' => $result->fields['last_period']);
        $result->MoveNext();
    }
    $beg_bal = array();
    $bad_accounts = array();
    foreach ($fiscal_years as $fiscal_year) {
        $sql = "select account_id, period, beginning_balance, (beginning_balance + debit_amount - credit_amount) as next_beg_bal\r\n\t\tfrom " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " \r\n\t\twhere period >= " . $fiscal_year['first_period'] . " and period <= " . $fiscal_year['last_period'] . " \r\n\t\torder by period, account_id";
        $result = $db->Execute($sql);
        while (!$result->EOF) {
            $period = $result->fields['period'];
            $next_period = $period + 1;
            $gl_account = $result->fields['account_id'];
            $beg_balance = $currencies->format($result->fields['beginning_balance']);
            $next_beg_bal = $currencies->format($result->fields['next_beg_bal']);
            $beg_bal[$next_period][$gl_account] = $next_beg_bal;
            if ($period != 1 && $beg_bal[$period][$gl_account] != $beg_balance) {
                if ($action != 'coa_hist_fix') {
                    $messageStack->add(sprintf(GEN_ADM_TOOLS_REPAIR_ERROR_MSG, $period, $gl_account, $beg_bal[$period][$gl_account], $beg_balance), 'caution');
                }
                $bad_accounts[$period][$gl_account] = array('sync' => '1');
            }
            // check posted transactions to account to see if they match
            $posted = $db->Execute("select sum(debit_amount) as debit, sum(credit_amount) as credit \r\n\t\t  from " . TABLE_JOURNAL_MAIN . " m join " . TABLE_JOURNAL_ITEM . " i on m.id = i.ref_id\r\n\t\t  where period = " . $period . " and gl_account = '" . $gl_account . "' \r\n\t\t  and journal_id in (2, 6, 7, 12, 13, 14, 16, 18, 19, 20, 21)");
            $posted_bal = $currencies->format($result->fields['beginning_balance'] + $posted->fields['debit'] - $posted->fields['credit']);
            if ($posted_bal != $next_beg_bal) {
                if ($action != 'coa_hist_fix') {
                    $messageStack->add(sprintf(GEN_ADM_TOOLS_REPAIR_ERROR_MSG, $period, $gl_account, $posted_bal, $next_beg_bal), 'caution');
                }
                $bad_accounts[$period][$gl_account] = array('sync' => '1', 'debit' => $posted->fields['debit'], 'credit' => $posted->fields['credit']);
            }
            $result->MoveNext();
        }
        // roll the fiscal year balances
        $result = $db->Execute("select id from " . TABLE_CHART_OF_ACCOUNTS . " where account_type = 44");
        $retained_earnings_acct = $result->fields['id'];
        // select list of accounts that need to be closed, adjusted
        $sql = "select id from " . TABLE_CHART_OF_ACCOUNTS . " where account_type in (30, 32, 34, 42, 44)";
        $result = $db->Execute($sql);
        $acct_list = array();
        while (!$result->EOF) {
            $beg_bal[$next_period][$result->fields['id']] = 0;
            $acct_list[] = $result->fields['id'];
            $result->MoveNext();
        }
        // fetch the totals for the closed accounts
        $sql = "select sum(beginning_balance + debit_amount - credit_amount) as retained_earnings \r\n\t\tfrom " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " \r\n\t\twhere account_id in ('" . implode("','", $acct_list) . "') and period = " . $period;
        $result = $db->Execute($sql);
        $beg_bal[$next_period][$retained_earnings_acct] = $currencies->format($result->fields['retained_earnings']);
    }
    if ($action == 'coa_hist_fix') {
        // find the affected accounts
        if (sizeof($bad_accounts) > 0) {
            // *************** START TRANSACTION *************************
            $db->transStart();
            $glEntry = new journal();
            $min_period = 999999;
            foreach ($bad_accounts as $period => $acct_array) {
                foreach ($acct_array as $gl_acct => $value) {
                    $min_period = min($period, $min_period);
                    // find first period that has an error
                    $glEntry->affected_accounts[$gl_acct] = 1;
                    if (isset($value['debit'])) {
                        // the history doesn't match posted data, repair
                        $db->Execute("update " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " \r\n\t\t\t    set debit_amount = " . $value['debit'] . ", credit_amount = " . $value['credit'] . " \r\n\t\t\t    where period = " . $period . " and account_id = '" . $gl_acct . "'");
                    }
                }
            }
            $debug = true;
            if ($glEntry->update_chart_history_periods($min_period - 1)) {
                // from prior period than the error account
                $db->transCommit();
                $messageStack->add_session(GEN_ADM_TOOLS_REPAIR_COMPLETE, 'success');
                gen_add_audit_log(GEN_ADM_TOOLS_REPAIR_LOG_ENTRY);
                gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')) . 'action=coa_hist_test', 'SSL'));
            }
        }
    }
    if (sizeof($bad_accounts) == 0) {
        $messageStack->add(GEN_ADM_TOOLS_REPAIR_SUCCESS, 'success');
    } else {
        $messageStack->add(GEN_ADM_TOOLS_REPAIR_ERROR, 'error');
    }
}
예제 #19
0
require_once DIR_FS_WORKING . 'classes/gen_ledger.php';
/**************   page specific initialization  *************************/
$id = isset($_GET['oID']) ? $_GET['oID'] : $_POST['id'];
$error = false;
/***************   hook for custom actions  ***************************/
$custom_path = DIR_FS_WORKING . 'custom/pages/popup_convert/extra_actions.php';
if (file_exists($custom_path)) {
    include $custom_path;
}
/***************   Act on the action request   *************************/
switch ($_REQUEST['action']) {
    case 'save':
        $selection = $_POST['conv_type'];
        $so_num = $_POST['so_num'];
        $inv_num = $_POST['inv_num'];
        $order = new journal($id);
        switch ($order->journal_id) {
            case 3:
                define('JOURNAL_ID', 4);
                define('GL_TYPE', 'poo');
                $search_gl_type = 'poo';
                $purchase_invoice_id = $so_num;
                break;
            default:
            case 9:
                if ($selection == 'inv') {
                    // invoice
                    define('JOURNAL_ID', 12);
                    define('GL_TYPE', 'sos');
                    $search_gl_type = 'soo';
                    $purchase_invoice_id = $inv_num;
예제 #20
0
         $db->transCommit();
         // post the chart of account values
         gen_add_audit_log(INV_LOG_ASSY . ($_REQUEST['action'] == 'save' ? TEXT_SAVE : TEXT_EDIT), $sku, $qty);
         $messageStack->add(INV_POST_ASSEMBLY_SUCCESS . $sku, 'success');
         if (DEBUG) {
             $messageStack->write_debug();
         }
         gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
         // *************** END TRANSACTION *************************
     }
     break;
 case 'delete':
     validate_security($security_level, 4);
     // security check
     if (!$error && $glEntry->id) {
         $delAssy = new journal($glEntry->id);
         // load the posted record based on the id submitted
         // *************** START TRANSACTION *************************
         $db->transStart();
         if ($delAssy->unPost('delete')) {
             // unpost the prior assembly
             $db->transCommit();
             // if not successful rollback will already have been performed
             gen_add_audit_log(INV_LOG_ASSY . TEXT_DELETE, $delAssy->journal_rows[0]['sku'], $delAssy->journal_rows[0]['qty']);
             if (DEBUG) {
                 $messageStack->write_debug();
             }
             gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
             break;
             // *************** END TRANSACTION *************************
         }
예제 #21
0
/**************   Check user security   *****************************/
$security_level = $_SESSION['admin_security'][SECURITY_ID_GL_UTILITIES];
if ($security_level == 0) {
    // no permission to enter page, error and redirect to home page
    $messageStack->add_session(ERROR_NO_PERMISSION, 'error');
    gen_redirect(html_href_link(FILENAME_DEFAULT, '', 'SSL'));
}
/**************  include page specific files    *********************/
require DIR_FS_WORKING . 'language/' . $_SESSION['language'] . '/language.php';
require DIR_FS_WORKING . 'functions/gen_ledger.php';
require DIR_FS_WORKING . 'classes/gen_ledger.php';
/**************   page specific initialization  *************************/
define('JOURNAL_ID', 2);
// General Journal
$coa_types = load_coa_types();
$glEntry = new journal();
$glEntry->journal_id = JOURNAL_ID;
// retrieve the original beginning_balances
$sql = "select c.id, beginning_balance, c.description, c.account_type\r\n\tfrom " . TABLE_CHART_OF_ACCOUNTS . " c inner join " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " h on c.id = h.account_id\r\n\twhere h.period = 1 order by c.id";
$result = $db->Execute($sql);
$glEntry->beg_bal = array();
while (!$result->EOF) {
    $glEntry->beg_bal[$result->fields['id']] = array('desc' => $result->fields['description'], 'type' => $result->fields['account_type'], 'type_desc' => $coa_types[$result->fields['account_type']]['text'], 'beg_bal' => $currencies->clean_value($result->fields['beginning_balance']));
    $glEntry->affected_accounts[$result->fields['id']] = true;
    // build list of affected accounts to update chart history
    $result->MoveNext();
}
$action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
/***************   hook for custom actions  ***************************/
$custom_path = DIR_FS_MY_FILES . 'custom/gen_ledger/beg_bal/extra_actions.php';
if (file_exists($custom_path)) {
예제 #22
0
 case 'delete':
     validate_security($security_level, 4);
     // security check
     if ($id = $_POST['id']) {
         $delOrd = new journal($id);
         $result = $db->Execute("SELECT id FROM " . TABLE_JOURNAL_MAIN . " WHERE so_po_ref_id = {$delOrd->id}");
         $xfer_to_id = $result->fields['id'];
         // save the matching adjust ID
         if (!$xfer_to_id) {
             $error = $messageStack('cannot deltete there is no offsetting record to delete!', 'error');
         }
         if (!$error) {
             // *************** START TRANSACTION *************************
             $db->transStart();
             if ($delOrd->unPost('delete')) {
                 $delOrd = new journal($xfer_to_id);
                 if ($delOrd->unPost('delete')) {
                     $db->transCommit();
                     // if not successful rollback will already have been performed
                     gen_add_audit_log(INV_LOG_ADJ . TEXT_DELETE, $delOrd->journal_rows[0]['sku'], $delOrd->journal_rows[0]['qty']);
                     if (DEBUG) {
                         $messageStack->write_debug();
                     }
                     gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
                     break;
                 } else {
                     $db->transRollback();
                 }
             } else {
                 $db->transRollback();
             }
예제 #23
0
 function handle_object($object_id)
 {
     $journal = new journal();
     return $journal->get_content($object_id);
 }
예제 #24
0
 function processInventory($upload_name)
 {
     global $coa, $db, $currencies, $messageStack;
     if (!$this->cyberParse($upload_name)) {
         return false;
     }
     $post_date = gen_specific_date(date('Y-m-d'), $day_offset = -1);
     $glEntry = new journal();
     $sku_list = array();
     $coa_list = array();
     $affected_accounts = array();
     for ($row_id = 0, $j = 2; $row_id < count($this->records); $row_id++, $j++) {
         $row = $this->records[$row_id];
         $total_amount = $currencies->clean_value($row['total_amount']);
         $qty = $currencies->clean_value($row['quantity']);
         // check for errors and report/exit if error found
         if (!gen_validate_sku($row['sku'])) {
             $messageStack->add(GL_ERROR_UPDATING_INVENTORY_STATUS . $row['sku'] . GL_BEG_BAL_ERROR_0 . $j, 'error');
             return false;
         }
         if (!in_array($row['inv_gl_acct'], $coa) || !in_array($row['gl_acct'], $coa)) {
             $messageStack->add(GL_BEG_BAL_ERROR_6 . $j, 'error');
             return false;
         }
         if ($qty == 0) {
             $messageStack->add(GL_BEG_BAL_ERROR_7 . $j, 'caution');
         } else {
             $affected_accounts[$row['inv_gl_acct']] = true;
             // need list of accounts to update history
             $affected_accounts[$row['gl_acct']] = true;
             // both credit and debit
             $sku_list[$row['sku']]['qty'] += $qty;
             // load quantity indexed by sku
             $sku_list[$row['sku']]['total'] += $total_amount;
             // load total_value indexed by sku
             $coa_list[$row['inv_gl_acct']] += $total_amount;
             // add to debit total by coa
             $coa_list[$row['gl_acct']] -= $total_amount;
             // add to credit total by coa
         }
     }
     if (is_array($sku_list)) {
         $glEntry->affected_accounts = $affected_accounts;
         // *************** START TRANSACTION *************************
         $db->transStart();
         // update inventory balances on hand
         foreach ($sku_list as $sku => $details) {
             $sql = "update " . TABLE_INVENTORY . " set quantity_on_hand = quantity_on_hand + {$details['qty']} where sku = '{$sku}'";
             $result = $db->Execute($sql);
             if ($result->AffectedRows() != 1) {
                 $messageStack->add(sprintf(GL_BEG_BAL_ERROR_8, $sku), 'error');
                 $db->transRollback();
                 return false;
             }
             $history_array = array('ref_id' => 0, 'sku' => $sku, 'qty' => $details['qty'], 'remaining' => $details['qty'], 'unit_cost' => $details['total'] / $details['qty'], 'avg_cost' => $details['total'] / $details['qty'], 'post_date' => $post_date);
             $result = db_perform(TABLE_INVENTORY_HISTORY, $history_array, 'insert');
         }
         // update chart of account beginning balances for period 1
         foreach ($coa_list as $account => $amount) {
             $sql = "update " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " set beginning_balance = beginning_balance + {$amount}\n\t\t\twhere account_id = '{$account}' and period = 1";
             $result = $db->Execute($sql);
             if ($result->AffectedRows() != 1) {
                 $messageStack->add(sprintf(GL_BEG_BAL_ERROR_9, $account), 'error');
                 $db->transRollback();
                 return false;
             }
         }
         // update the chart of accounts history through the existing periods
         if (!$glEntry->update_chart_history_periods($period = 1)) {
             if (DEBUG) {
                 $messageStack->write_debug();
             }
             return $glEntry->fail_message(GL_ERROR_UPDATE_COA_HISTORY);
         }
         $db->transCommit();
         // post the chart of account values
         if (DEBUG) {
             $messageStack->write_debug();
         }
         // *************** END TRANSACTION *************************
     }
     $this->line_count = $row_id;
     return true;
 }
예제 #25
0
 $result = $db->Execute("select wo_num, sku_id, qty from " . TABLE_WO_JOURNAL_MAIN . " where id = " . $id);
 $wo_num = $result->fields['wo_num'];
 $qty = $result->fields['qty'];
 $sku_id = $result->fields['sku_id'];
 $result = $db->Execute("select sku, description_short, account_inventory_wage from " . TABLE_INVENTORY . " where id = '" . $sku_id . "'");
 $sku = $result->fields['sku'];
 $desc = $result->fields['description_short'];
 $acct = $result->fields['account_inventory_wage'];
 gen_pull_language('inventory');
 gen_pull_language('phreebooks');
 require_once DIR_FS_MODULES . 'inventory/functions/inventory.php';
 require_once DIR_FS_MODULES . 'phreebooks/classes/gen_ledger.php';
 define('JOURNAL_ID', 14);
 // Inventory Assemblies Journal
 define('GL_TYPE', '');
 $glEntry = new journal();
 $glEntry->id = '';
 $glEntry->admin_id = $_SESSION['admin_id'];
 $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);
예제 #26
0
require_once DIR_FS_MODULES . 'inventory/defaults.php';
require_once DIR_FS_MODULES . 'phreeform/defaults.php';
require_once DIR_FS_MODULES . 'phreebooks/functions/phreebooks.php';
require_once DIR_FS_MODULES . 'phreebooks/classes/gen_ledger.php';
require_once DIR_FS_MODULES . 'phreepos/classes/tills.php';
require_once DIR_FS_MODULES . 'phreepos/classes/other_transactions.php';
/**************   page specific initialization  *************************/
define('ORD_ACCT_ID', GEN_CUSTOMER_ID);
define('GL_TYPE', 'sos');
define('DEF_INV_GL_ACCT', AR_DEF_GL_SALES_ACCT);
define('DEF_GL_ACCT', AR_DEFAULT_GL_ACCT);
define('DEF_GL_ACCT_TITLE', ORD_AR_ACCOUNT);
define('POPUP_FORM_TYPE', 'pos:rcpt');
$error = false;
$account_type = 'c';
$order = new journal();
$transaction = new other_transactions();
$tills = new tills();
/***************   hook for custom actions  ***************************/
$custom_path = DIR_FS_MODULES . 'phreepos/custom/ajax/other_transactions.php';
if (file_exists($custom_path)) {
    include $custom_path;
}
/***************   Act on the action request   *************************/
if ($security_level < 2) {
    $error .= ERROR_NO_PERMISSION;
}
$transaction->get_transaction_info($_POST['Other_trans_type']);
$tills->get_till_info($_POST['ot_till_id']);
// currency values (convert to DEFAULT_CURRENCY to store in db)
$order->currencies_code = db_prepare_input($_POST['ot_currencies_code']);
예제 #27
0
     // start repair
     $precision = 1 / pow(10, $currencies->currencies[DEFAULT_CURRENCY]['decimal_precise'] + 1);
     $result = $db->Execute("UPDATE " . TABLE_INVENTORY_HISTORY . " SET remaining = 0 WHERE remaining < " . $precision);
     // remove rounding errors
     if (sizeof($repair) > 0) {
         foreach ($repair as $key => $value) {
             $db->Execute("UPDATE " . TABLE_INVENTORY . " SET quantity_on_hand = {$value} WHERE sku = '{$key}'");
             $messageStack->add(sprintf(INV_TOOLS_BALANCE_CORRECTED, $key, $value), 'success');
         }
     }
     if (sizeof($journal_repost) > 0) {
         foreach ($journal_repost as $key => $value) {
             $result = $db->Execute("SELECT m.id FROM journal_main m join journal_item i ON m.id = i.ref_id WHERE i.sku = '{$value}' ORDER BY m.post_date, m.id");
             $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');
                     break;
                 }
                 $result->MoveNext();
             }
             $db->transCommit();
         }
     }
 }
 if ($cnt == 0) {
     $messageStack->add(INV_TOOLS_IN_BALANCE, 'success');