Ajax additions
[fa-stable.git] / purchasing / supplier_trans_gl.php
1 <?php
2
3 $page_security=5;
4 $path_to_root="..";
5
6 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
7 include_once($path_to_root . "/includes/session.inc");
8
9 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
10 $js = "";
11 if ($use_date_picker)
12         $js .= get_js_date_picker();
13 page(_("Add GL Items"), false, false, "", $js);
14
15
16 if (!isset($_SESSION['supp_trans']))
17 {
18         display_note(_("To enter a supplier invoice or credit note the supplier must first be selected."));
19         exit;
20         /*It all stops here if there aint no supplier selected and transaction initiated ie $_SESSION['supp_trans'] started off*/
21 }
22
23 //------------------------------------------------------------------------------------------------
24 function clear_fields()
25 {
26         global $Ajax;
27         
28         unset($_POST['gl_code']);
29         unset($_POST['dimension_id']);
30         unset($_POST['dimension2_id']);
31         unset($_POST['amount']);
32         unset($_POST['memo_']);
33         unset($_POST['AddGLCodeToTrans']);
34         $Ajax->activate('gl_ctrls');
35         set_focus('gl_code');
36 }
37 //------------------------------------------------------------------------------------------------
38 //      GL postings are often entered in the same form to two accounts
39 //  so fileds are cleared only on user demand.
40 //
41 if (isset($_POST['ClearFields']))
42 {
43         clear_fields();
44 }
45
46 if (isset($_POST['AddGLCodeToTrans'])){
47
48         $Ajax->activate('gl_items');
49         $input_error = false;
50
51         $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
52         $result = db_query($sql,"get account information");
53         if (db_num_rows($result) == 0)
54         {
55                 display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
56                 set_focus('gl_code');
57                 $input_error = true;
58         }
59         else
60         {
61                 $myrow = db_fetch_row($result);
62                 $gl_act_name = $myrow[1];
63                 if (!check_num('amount'))
64                 {
65                         display_error(_("The amount entered is not numeric. This line cannot be added to the transaction."));
66                         set_focus('amount');
67                         $input_error = true;
68                 }
69         }
70
71         if ($input_error == false)
72         {
73                 $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
74                         $_POST['dimension_id'], $_POST['dimension2_id'], 
75                         input_num('amount'), $_POST['memo_']);
76                 set_focus('gl_code');
77         }
78 }
79
80 //------------------------------------------------------------------------------------------------
81
82 $id = find_submit('Delete');
83 if ($id != -1)
84 {
85         $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
86         clear_fields();
87         $Ajax->activate('gl_items');
88 }
89
90 //------------------------------------------------------------------------------------------------
91
92 display_heading($_SESSION['supp_trans']->supplier_name);
93
94 display_gl_items($_SESSION['supp_trans'], 1);
95
96 echo "<br>";
97
98 if ($_SESSION['supp_trans']->is_invoice == true)
99 {
100         hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
101 }
102 else
103 {
104         hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
105 }
106
107 echo "<hr>";
108
109 //------------------------------------------------------------------------------------------------
110
111 /*Set up a form to allow input of new GL entries */
112 start_form(false, true);
113
114 display_heading2(_("Enter a GL Line"));
115
116 div_start('gl_ctrls');
117 start_table($table_style2);
118
119 $accs = get_supplier_accounts($_SESSION['supp_trans']->supplier_id);
120 $_POST['gl_code'] = $accs['purchase_account'];
121 gl_all_accounts_list_row(_("GL Account Selection:"), 'gl_code', null);
122 $dim = get_company_pref('use_dimension');
123 if ($dim >= 1)
124         dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
125 if ($dim > 1)
126         dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
127 if ($dim < 1)
128         hidden('dimension_id', 0);
129 if ($dim < 2)
130         hidden('dimension2_id', 0);
131 amount_row( _("Amount:"), 'amount');
132
133 textarea_row(_("Memo:"), "memo_",  null, 40, 2);
134
135 end_table();
136 div_end();
137 echo '<br>';
138 submit_center_first('AddGLCodeToTrans', _("Add GL Line"), '', true);
139 submit_center_last('ClearFields', _('Reset'), _("Clear all GL entry fields"), true);
140 end_form();
141
142 //------------------------------------------------------------------------------------------------
143 echo '<br>';
144 end_page(false, true);
145
146 ?>