$js .= get_js_date_picker();
page(_("Fiscal Years"), false, false, "", $js);
-//---------------------------------------------------------------------------------------------
-
-if (isset($_GET['selected_id']))
-{
- $selected_id = $_GET['selected_id'];
-}
-elseif (isset($_POST['selected_id']))
-{
- $selected_id = $_POST['selected_id'];
-}
-else
- $selected_id = null;
-
+simple_page_mode(true);
//---------------------------------------------------------------------------------------------
function check_data()
{
- if (!isset($selected_id))
- $from = $_POST['from_date'];
- else
- $from = $selected_id;
- if (!is_date($from) || get_fiscalyear($from) !== false)
+ if (!is_date($_POST['from_date']))
{
display_error( _("Invalid BEGIN date in fiscal year."));
set_focus('from_date');
set_focus('to_date');
return false;
}
- if (date1_greater_date2($from, $_POST['to_date']))
+ if (date1_greater_date2($_POST['from_date'], $_POST['to_date']))
{
display_error( _("BEGIN date bigger than END date."));
set_focus('from_date');
function handle_submit()
{
- global $selected_id;
+ global $selected_id, $Mode;
if (!check_data())
return false;
- if (isset($selected_id))
+ if ($selected_id != -1)
{
update_fiscalyear($_POST['from_date'], $_POST['closed']);
+ display_notification(_('Selected fiscal year has been updated'));
}
else
{
add_fiscalyear($_POST['from_date'], $_POST['to_date'], $_POST['closed']);
+ display_notification(_('New fiscal year has been added'));
}
-
- return true;
+ $Mode = 'RESET';
}
//---------------------------------------------------------------------------------------------
-function check_can_delete($todate)
+function check_can_delete($selected_id)
{
- global $selected_id;
-
+ $myrow = get_fiscalyear($selected_id);
// PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
- $from = date2sql($selected_id);
- $to = date2sql($todate);
+ $from = $myrow['begin'];
+ $to = $myrow['end'];
$sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'";
$result = db_query($sql, "could not query gl_trans master");
$myrow = db_fetch_row($result);
//---------------------------------------------------------------------------------------------
-function handle_delete($todate)
+function handle_delete()
{
- global $selected_id;
+ global $selected_id, $Mode;
- if (!check_can_delete($todate))
+ if (!check_can_delete($selected_id))
return;
//only delete if used in neither customer or supplier, comp prefs, bank trans accounts
delete_fiscalyear($selected_id);
-
- meta_forward($_SERVER['PHP_SELF']);
+ display_notification(_('Selected fiscal year has been deleted'));
+ $Mode = 'RESET';
}
//---------------------------------------------------------------------------------------------
$company_year = get_company_pref('f_year');
$result = get_all_fiscalyears();
-
+ start_form();
start_table($table_style);
$th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
label_cell($from);
label_cell($to);
label_cell($closed_text);
- edit_link_cell("selected_id=" . urlencode($from));
+ edit_button_cell("Edit".$myrow['id'], _("Edit"));
if ($myrow["id"] != $company_year)
- delete_link_cell("selected_id=" . urlencode($from) . "&to_date=" . urlencode($to) . "&delete=1");
+ edit_button_cell("Delete".$myrow['id'], _("Delete"));
end_row();
}
- end_table();;
+ end_table();
+ end_form();
display_note(_("The marked fiscal year is the current fiscal year which cannot be deleted."), 0, 0, "class='currentfg'");
}
function display_fiscalyear_edit($selected_id)
{
- global $table_style2;
+ global $table_style2, $Mode;
start_form();
start_table($table_style2);
- if ($selected_id)
+ if ($selected_id != -1)
{
- $myrow = get_fiscalyear($selected_id);
-
- $_POST['from_date'] = sql2date($myrow["begin"]);
- $_POST['to_date'] = sql2date($myrow["end"]);
- $_POST['closed'] = $myrow["closed"];
- hidden('selected_id', $selected_id);
- hidden('from_date', $_POST['from_date']);
- hidden('to_date', $_POST['to_date']);
- label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
- label_row(_("Fiscal Year End:"), $_POST['to_date']);
+ if($Mode =='Edit')
+ {
+ $myrow = get_fiscalyear($selected_id);
+
+ $_POST['from_date'] = sql2date($myrow["begin"]);
+ $_POST['to_date'] = sql2date($myrow["end"]);
+ $_POST['closed'] = $myrow["closed"];
+ }
+ hidden('from_date');
+ hidden('to_date');
+ label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
+ label_row(_("Fiscal Year End:"), $_POST['to_date']);
}
else
{
date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001);
date_row(_("Fiscal Year End:"), 'to_date', '', null, 0, 0, 1001);
}
+ hidden('selected_id', $selected_id);
yesno_list_row(_("Is Closed:"), 'closed', null, "", "", false);
end_table(1);
- submit_add_or_update_center(!isset($selected_id));
+ submit_add_or_update_center($selected_id == -1, '', true);
end_form();
}
//---------------------------------------------------------------------------------------------
-if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
{
- if (handle_submit())
- {
- meta_forward($_SERVER['PHP_SELF']);
- }
+ handle_submit();
}
//---------------------------------------------------------------------------------------------
-if (isset($_GET['delete']))
+if ($Mode == 'Delete')
{
- handle_delete($_GET['to_date']);
+ global $selected_id;
+ handle_delete($selected_id);
}
+if ($Mode == 'RESET')
+{
+ $selected_id = -1;
+}
//---------------------------------------------------------------------------------------------
display_fiscalyears();
-hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Fiscal Year"));
+echo '<br>';
display_fiscalyear_edit($selected_id);
<?php
-
-
$page_security = 4;
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
check_db_has_suppliers(_("There are no suppliers defined in the system."));
-if (isset($_GET['supplier_id']))
-{
- $supplier_id = strtoupper($_GET['supplier_id']);
-}
-elseif (isset($_POST['supplier_id']))
-{
- $supplier_id = strtoupper($_POST['supplier_id']);
-}
-
-if (isset($_GET['stock_id']))
-{
- $_POST['stock_id'] = $_GET['stock_id'];
-}
-
+simple_page_mode(true);
//--------------------------------------------------------------------------------------------------
-if ((isset($_POST['AddRecord']) || isset($_POST['UpdateRecord'])) && isset($supplier_id))
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
{
$input_error = 0;
{
$input_error = 1;
display_error( _("The conversion factor entered was not numeric. The conversion factor is the number by which the price must be divided by to get the unit price in our unit of measure."));
- set_focus('conversion_factor');
+ set_focus('conversion_factor');
}
if ($input_error == 0)
{
- if (isset($_POST['AddRecord']))
+ if ($Mode == 'ADD_ITEM')
{
$sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
conversion_factor, supplier_description) VALUES (";
- $sql .= "'$supplier_id', '" . $_POST['stock_id'] . "', " .
+ $sql .= "'".$_POST['supplier_id']."', '" . $_POST['stock_id'] . "', " .
input_num('price') . ", '" . $_POST['suppliers_uom'] . "', " .
input_num('conversion_factor') . ", '" . $_POST['supplier_description'] . "')";
db_query($sql,"The supplier purchasing details could not be added");
display_notification(_("This supplier purchasing data has been added."));
- }
-
- if (isset($_POST['UpdateRecord']))
+ } else
{
$sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price') . ",
suppliers_uom='" . $_POST['suppliers_uom'] . "',
conversion_factor=" . input_num('conversion_factor') . ",
supplier_description='" . $_POST['supplier_description'] . "'
WHERE stock_id='" . $_POST['stock_id'] . "' AND
- supplier_id='$supplier_id'";
+ supplier_id='$selected_id'";
db_query($sql,"The supplier purchasing details could not be updated");
display_notification(_("Supplier purchasing data has been updated."));
}
-
- if (isset($_POST['UpdateRecord']) || isset($_POST['AddRecord']))
- {
- //update or insert took place and need to clear the form
- unset($supplier_id);
- unset($_POST['price']);
- unset($_POST['suppliers_uom']);
- unset($_POST['conversion_factor']);
- unset($_POST['supplier_description']);
- }
+ $Mode = 'RESET';
}
}
//--------------------------------------------------------------------------------------------------
-if (isset($_GET['Delete']))
+if ($Mode == 'Delete')
{
- $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id='$supplier_id'
+ $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id='$selected_id'
AND stock_id='" . $_POST['stock_id'] . "'";
db_query($sql,"could not delete purchasing data");
- display_note(_("The purchasing data item has been sucessfully deleted."));
- unset ($supplier_id);
+ display_notification(_("The purchasing data item has been sucessfully deleted."));
+ $Mode = 'RESET';
+}
+
+if ($Mode == 'RESET')
+{
+ $selected_id = -1;
+}
+
+if (isset($_POST['_selected_id_update']) )
+{
+ $selected_id = $_POST['selected_id'];
+ $Ajax->activate('_page_body');
}
+
if (isset($_POST['_stock_id_update']))
$Ajax->activate('price_table');
//--------------------------------------------------------------------------------------------------
label_cell($myrow["curr_code"]);
label_cell($myrow["suppliers_uom"]);
label_cell($myrow["supplier_description"]);
- edit_link_cell("stock_id=" . $_POST['stock_id']. "&supplier_id=" . $myrow["supplier_id"] . "&Edit=1");
- delete_link_cell("stock_id=" . $_POST['stock_id']. "&supplier_id=" . $myrow["supplier_id"] . "&Delete=1");
+ edit_button_cell("Edit".$myrow['supplier_id'], _("Edit"));
+ edit_button_cell("Delete".$myrow['supplier_id'], _("Delete"));
end_row();
$j++;
div_end();
}
-//------------------------------------------------------------------------------------------------
+//-----------------------------------------------------------------------------------------------
-if (isset($_GET['Edit']))
+if ($Mode =='Edit')
{
$sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name FROM ".TB_PREF."purch_data
INNER JOIN ".TB_PREF."suppliers ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
- WHERE ".TB_PREF."purch_data.supplier_id='$supplier_id'
+ WHERE ".TB_PREF."purch_data.supplier_id='$selected_id'
AND ".TB_PREF."purch_data.stock_id='" . $_POST['stock_id'] . "'";
$result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
}
echo "<br>";
+hidden('selected_id', $selected_id);
start_table($table_style2);
-if (isset($_GET['Edit']))
+if ($Mode == 'Edit')
{
- hidden('supplier_id', $supplier_id);
+ hidden('supplier_id');
label_row(_("Supplier:"), $supp_name);
}
else
{
supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true);
- $supplier_id = $_POST['supplier_id'];
}
-amount_row(_("Price:"), 'price', null,'', get_supplier_currency($supplier_id));
+amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id));
text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51);
if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "")
end_table(1);
-if (isset($_GET['Edit']))
-{
- submit_center('UpdateRecord', _("Update Purchasing Data"));
-}
-else
-{
- submit_center('AddRecord', _("Add Purchasing Data"));
-}
+submit_add_or_update_center($selected_id == -1, '', true);
end_form();
end_page();