64dc49aa561d4d143c7dc83cf3f46dde155d61c2
[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 start_form(false,true);
95 display_gl_items($_SESSION['supp_trans'], 1);
96 end_form();
97 echo "<br>";
98
99 if ($_SESSION['supp_trans']->is_invoice == true)
100 {
101         hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
102 }
103 else
104 {
105         hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
106 }
107
108 echo "<hr>";
109
110 //------------------------------------------------------------------------------------------------
111
112 /*Set up a form to allow input of new GL entries */
113 start_form(false, true);
114
115 display_heading2(_("Enter a GL Line"));
116
117 div_start('gl_ctrls');
118 start_table($table_style2);
119
120 $accs = get_supplier_accounts($_SESSION['supp_trans']->supplier_id);
121 $_POST['gl_code'] = $accs['purchase_account'];
122 gl_all_accounts_list_row(_("GL Account Selection:"), 'gl_code', null);
123 $dim = get_company_pref('use_dimension');
124 if ($dim >= 1)
125         dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
126 if ($dim > 1)
127         dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
128 if ($dim < 1)
129         hidden('dimension_id', 0);
130 if ($dim < 2)
131         hidden('dimension2_id', 0);
132 amount_row( _("Amount:"), 'amount');
133
134 textarea_row(_("Memo:"), "memo_",  null, 40, 2);
135
136 end_table();
137 div_end();
138 echo '<br>';
139 submit_center_first('AddGLCodeToTrans', _("Add GL Line"), '', true);
140 submit_center_last('ClearFields', _('Reset'), _("Clear all GL entry fields"), true);
141 end_form();
142
143 //------------------------------------------------------------------------------------------------
144 echo '<br>';
145 end_page(false, true);
146
147 ?>