Common ui code for allocations moved toallocation_cart.inc
[fa-stable.git] / purchasing / allocations / supplier_allocate.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $path_to_root="../..";
13 $page_security = 3;
14
15 include($path_to_root . "/includes/ui/allocation_cart.inc");
16 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/banking.inc");
20 include_once($path_to_root . "/sales/includes/sales_db.inc");
21 //include_once($path_to_root . "/purchasing/includes/ui/supp_alloc_ui.inc");
22
23 $js = "";
24 if ($use_popup_windows)
25         $js .= get_js_open_window(900, 500);
26
27 add_js_file('allocate.js');
28
29 page(_("Allocate Supplier Payment or Credit Note"), false, false, "", $js);
30
31 //--------------------------------------------------------------------------------
32
33 function clear_allocations()
34 {
35         if (isset($_SESSION['alloc']))
36         {
37                 unset($_SESSION['alloc']->allocs);
38                 unset($_SESSION['alloc']);
39         }
40         session_register("alloc");
41 }
42 //--------------------------------------------------------------------------------
43
44 function edit_allocations_for_transaction($type, $trans_no)
45 {
46         start_form();
47
48     display_heading(_("Allocation of") . " " . systypes::name($_SESSION['alloc']->type) . " # " . $_SESSION['alloc']->trans_no);
49
50         display_heading($_SESSION['alloc']->person_name);
51
52     display_heading2(_("Date:") . " <b>" . $_SESSION['alloc']->date_ . "</b>");
53     display_heading2(_("Total:") . " <b>" . price_format(-$_SESSION['alloc']->amount) . "</b>");
54
55     echo "<br>";
56
57         div_start('alloc_tbl');
58     if (count($_SESSION['alloc']->allocs) > 0)
59     {
60                 show_allocatable(true);
61
62         submit_center_first('UpdateDisplay', _("Refresh"), _('Start again allocation of selected amount'), true);
63         submit('Process', _("Process"), true, _('Process allocations'), 'default');
64                 submit_center_last('Cancel', _("Back to Allocations"),
65                         _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
66         }
67         else
68         {
69         display_note(_("There are no unsettled transactions to allocate."), 0, 1);
70                 submit_center('Cancel', _("Back to Allocations"), true,
71                         _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
72     }
73
74         div_end();
75         end_form();
76 }
77 //--------------------------------------------------------------------------------
78
79 if (isset($_POST['Process']))
80 {
81         if (check_allocations())
82         {
83                 handle_allocate();
84                 clear_allocations();
85                 $_POST['Cancel'] = 1;
86         }
87 }
88
89 //--------------------------------------------------------------------------------
90
91 if (isset($_POST['Cancel']))
92 {
93         clear_allocations();
94         meta_forward($path_to_root . "/purchasing/allocations/supplier_allocation_main.php");
95 }
96
97 //--------------------------------------------------------------------------------
98
99 if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
100 {
101         clear_allocations();
102         get_allocations_for_transaction($_GET['trans_type'], $_GET['trans_no']);
103 }
104 if(get_post('UpdateDisplay'))
105 {
106         $trans_no = $_SESSION['alloc']->trans_no;
107         $type = $_SESSION['alloc']->type;
108         clear_allocations();
109         get_allocations_for_transaction($type, $trans_no);
110         $Ajax->activate('alloc_tbl');
111 }
112
113 if (isset($_SESSION['alloc']))
114 {
115         edit_allocations_for_transaction($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
116 }
117
118 //--------------------------------------------------------------------------------
119
120 end_page();
121
122 ?>