b2b827fee00d90de7efd34df97af26b89e4628c2
[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
25 function clear_fields()
26 {
27         unset($_POST['gl_code']);
28         unset($_POST['dimension_id']);
29         unset($_POST['dimension2_id']);
30         unset($_POST['amount']);
31         unset($_POST['memo_']);
32         unset($_POST['AcctSelection']);
33         unset($_POST['AddGLCodeToTrans']);
34 }
35
36 //------------------------------------------------------------------------------------------------
37
38 if (isset($_POST['AddGLCodeToTrans'])){
39
40         $input_error = false;
41         if (!isset($_POST['gl_code']))
42         {
43                 $_POST['gl_code'] = $_POST['AcctSelection'];
44         }
45
46         $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
47         $result = db_query($sql,"get account information");
48         if (db_num_rows($result) == 0)
49         {
50                 display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
51                 set_focus('gl_code');
52                 $input_error = true;
53         }
54         else
55         {
56                 $myrow = db_fetch_row($result);
57                 $gl_act_name = $myrow[1];
58                 if (!check_num('amount'))
59                 {
60                         display_error(_("The amount entered is not numeric. This line cannot be added to the transaction."));
61                         set_focus('amount');
62                         $input_error = true;
63                 }
64         }
65
66         if ($input_error == false)
67         {
68                 $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
69                         $_POST['dimension_id'], $_POST['dimension2_id'], 
70                         input_num('amount'), $_POST['memo_']);
71                 clear_fields();
72         }
73 }
74
75 //------------------------------------------------------------------------------------------------
76
77 if (isset($_GET['Delete']))
78 {
79         $_SESSION['supp_trans']->remove_gl_codes_from_trans($_GET['Delete']);
80         clear_fields();
81 }
82
83 //------------------------------------------------------------------------------------------------
84
85 display_heading($_SESSION['supp_trans']->supplier_name);
86
87 display_gl_items($_SESSION['supp_trans'], 1);
88
89 echo "<br>";
90
91 if ($_SESSION['supp_trans']->is_invoice == true)
92 {
93         hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
94 }
95 else
96 {
97         hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
98 }
99
100 echo "<hr>";
101
102 //------------------------------------------------------------------------------------------------
103
104 /*Set up a form to allow input of new GL entries */
105 start_form(false, true);
106
107 display_heading2(_("Enter a GL Line"));
108
109 start_table($table_style2);
110
111 $accs = get_supplier_accounts($_SESSION['supp_trans']->supplier_id);
112 $_POST['AcctSelection'] = $accs['purchase_account'];
113 gl_all_accounts_list_row(_("GL Account Selection:"), 'AcctSelection', $_POST['AcctSelection']);
114 $dim = get_company_pref('use_dimension');
115 if ($dim >= 1)
116         dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
117 if ($dim > 1)
118         dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
119 if ($dim < 1)
120         hidden('dimension_id', 0);
121 if ($dim < 2)
122         hidden('dimension2_id', 0);
123 amount_row( _("Amount:"), 'amount');
124
125 textarea_row(_("Memo:"), "memo_",  null, 40, 2);
126
127 end_table();;
128
129 submit_center('AddGLCodeToTrans', _("Add GL Line"));
130
131 end_form();
132
133 //------------------------------------------------------------------------------------------------
134
135 end_page();
136 ?>