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