X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Fgl_budget.php;h=949d7fd56db7871890c47f1257a99107eb88ec61;hb=128be63f9ae68744f37eae8072f95d0f524f86b4;hp=6c4db5270eb023b5168c676915747c84b0b1c66a;hpb=d567a10b7925c8bb97c734e213d6651a979af29d;p=fa-stable.git diff --git a/gl/gl_budget.php b/gl/gl_budget.php index 6c4db527..949d7fd5 100644 --- a/gl/gl_budget.php +++ b/gl/gl_budget.php @@ -9,95 +9,47 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -$page_security = 10; -$path_to_root=".."; -include($path_to_root . "/includes/session.inc"); +$page_security = 'SA_BUDGETENTRY'; +$path_to_root = ".."; +include_once($path_to_root . "/includes/session.inc"); add_js_file('budget.js'); -page(_("Budget Entry")); +page(_($help_context = "Budget Entry")); -include($path_to_root . "/includes/ui.inc"); -include($path_to_root . "/gl/includes/gl_db.inc"); +include_once($path_to_root . "/includes/ui.inc"); +include_once($path_to_root . "/gl/includes/gl_db.inc"); include_once($path_to_root . "/includes/data_checks.inc"); +include_once($path_to_root . "/admin/db/fiscalyears_db.inc"); -check_db_has_gl_account_groups(_("There are no account groups defined. Please define at least one account group before entering accounts.")); - -//------------------------------------------------------------------------------------- - -function exists_gl_budget($date_, $account, $dimension, $dimension2) -{ - $sql = "SELECT account FROM ".TB_PREF."budget_trans WHERE account='$account' AND tran_date='$date_' AND - dimension_id=$dimension AND dimension2_id=$dimension2"; - $result = db_query($sql, "Cannot retreive a gl transaction"); - - return (db_num_rows($result) > 0); -} - -function add_update_gl_budget_trans($date_, $account, $dimension, $dimension2, $amount) -{ - $date = date2sql($date_); - - if (exists_gl_budget($date, $account, $dimension, $dimension2)) - $sql = "UPDATE ".TB_PREF."budget_trans SET amount=$amount WHERE account='$account' AND - dimension_id=$dimension AND dimension2_id=$dimension2 AND tran_date='$date'"; - else - $sql = "INSERT INTO ".TB_PREF."budget_trans (tran_date, - account, dimension_id, dimension2_id, amount, memo_) VALUES ('$date', - '$account', $dimension, $dimension2, $amount, '')"; - - db_query($sql, "The GL budget transaction could not be saved"); -} - -function delete_gl_budget_trans($date_, $account, $dimension, $dimension2) -{ - $date = date2sql($date_); - $sql = "DELETE FROM ".TB_PREF."budget_trans WHERE account='$account' AND - dimension_id=$dimension AND dimension2_id=$dimension2 AND tran_date='$date'"; - db_query($sql, "The GL budget transaction could not be deleted"); -} - -function get_only_budget_trans_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0) -{ - - $from = date2sql($from_date); - $to = date2sql($to_date); - - $sql = "SELECT SUM(amount) FROM ".TB_PREF."budget_trans - WHERE account='$account' AND tran_date >= '$from' AND tran_date <= '$to' - AND dimension_id = $dimension AND dimension2_id = $dimension2"; - $result = db_query($sql,"No budget accounts were returned"); - - $row = db_fetch_row($result); - return $row[0]; -} +check_db_has_gl_account_groups(_("There are no account groups defined. Please define at least one account group before entering accounts.")); //------------------------------------------------------------------------------------- if (isset($_POST['add']) || isset($_POST['delete'])) { - begin_transaction(); - for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++) - { - if (isset($_POST['add'])) - add_update_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2'], input_num('amount'.$i)); - else - delete_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2']); + $amounts = array(); + for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++) { + $amounts[$da] = input_num('amount'.$i); $da = add_months($da, 1); } - commit_transaction(); + if (isset($_POST['add'])) { - if (isset($_POST['add'])) + add_budget($_POST['account'], $_POST['dim1'], $_POST['dim2'], $amounts); display_notification_centered(_("The Budget has been saved.")); - else + + } else { + + delete_budget($_POST['account'], $_POST['dim1'], $_POST['dim2'], array_keys($amounts)); display_notification_centered(_("The Budget has been deleted.")); - //meta_forward($_SERVER['PHP_SELF']); + } + $Ajax->activate('budget_tbl'); } -if (isset($_POST['submit']) || isset($_POST['update'])) +if (isset($_POST['submit']) || isset($_POST['update']) || list_updated('fyear') || list_updated('account')) $Ajax->activate('budget_tbl'); //------------------------------------------------------------------------------------- @@ -107,21 +59,21 @@ start_form(); if (db_has_gl_accounts()) { $dim = get_company_pref('use_dimension'); - start_table($table_style2); - fiscalyears_list_row(_("Fiscal Year:"), 'fyear', null); - gl_all_accounts_list_row(_("Account Code:"), 'account', null); + start_table(TABLESTYLE2); + fiscalyears_list_row(_("Fiscal Year:"), 'fyear', null, true); + gl_all_accounts_list_row(_("Account Code:"), 'account', null, true, false, false, true); if (!isset($_POST['dim1'])) $_POST['dim1'] = 0; if (!isset($_POST['dim2'])) $_POST['dim2'] = 0; if ($dim == 2) { - dimensions_list_row(_("Dimension")." 1", 'dim1', $_POST['dim1'], true, null, false, 1); - dimensions_list_row(_("Dimension")." 2", 'dim2', $_POST['dim2'], true, null, false, 2); + dimensions_list_row(_("Dimension")." 1", 'dim1', $_POST['dim1'], true, null, false, 1, true); + dimensions_list_row(_("Dimension")." 2", 'dim2', $_POST['dim2'], true, null, false, 2, true); } - else if ($dim == 1) + elseif ($dim == 1) { - dimensions_list_row(_("Dimension"), 'dim1', $_POST['dim1'], true, null, false, 1); + dimensions_list_row(_("Dimension"), 'dim1', $_POST['dim1'], true, null, false, 1, true); hidden('dim2', 0); } else @@ -132,7 +84,7 @@ if (db_has_gl_accounts()) submit_row('submit', _("Get"), true, '', '', true); end_table(1); div_start('budget_tbl'); - start_table($table_style2); + start_table(TABLESTYLE2); $showdims = (($dim == 1 && $_POST['dim1'] == 0) || ($dim == 2 && $_POST['dim1'] == 0 && $_POST['dim2'] == 0)); if ($showdims) @@ -142,11 +94,7 @@ if (db_has_gl_accounts()) table_header($th); $year = $_POST['fyear']; if (get_post('update') == '') { - $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year"; - - $result = db_query($sql, "could not get current fiscal year"); - - $fyear = db_fetch($result); + $fyear = get_fiscalyear($year); $_POST['begin'] = sql2date($fyear['begin']); $_POST['end'] = sql2date($fyear['end']); } @@ -185,11 +133,10 @@ if (db_has_gl_accounts()) end_table(1); div_end(); submit_center_first('update', _("Update"), '', null); - submit('add', _("Save"), true, '', true); + submit('add', _("Save"), true, '', 'default'); submit_center_last('delete', _("Delete"), '', true); } end_form(); end_page(); -?>