Merged changes from main trunk 2.2.1-2.2.2
[fa-stable.git] / sales / allocations / customer_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 $page_security = 'SA_SALESALLOC';
13 $path_to_root = "../..";
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/data_checks.inc");
18 include_once($path_to_root . "/sales/includes/sales_ui.inc");
19 include_once($path_to_root . "/sales/includes/sales_db.inc");
20 //include_once($path_to_root . "/sales/includes/ui/cust_alloc_ui.inc");
21
22 $js = "";
23 if ($use_popup_windows)
24         $js .= get_js_open_window(900, 500);
25
26 add_js_file('allocate.js');
27
28 page(_($help_context = "Allocate Customer Payment or Credit Note"), false, false, "", $js);
29
30 //--------------------------------------------------------------------------------
31
32 function clear_allocations()
33 {
34         if (isset($_SESSION['alloc']))
35         {
36                 unset($_SESSION['alloc']->allocs);
37                 unset($_SESSION['alloc']);
38         }
39         //session_register('alloc');
40 }
41
42
43 //--------------------------------------------------------------------------------
44
45 if (isset($_POST['Process']))
46 {
47         if (check_allocations())
48         {
49                 $_SESSION['alloc']->write();
50                 clear_allocations();
51                 $_POST['Cancel'] = 1;
52         }
53 }
54 //--------------------------------------------------------------------------------
55
56 if (isset($_POST['Cancel']))
57 {
58         clear_allocations();
59         meta_forward($path_to_root . "/sales/allocations/customer_allocation_main.php");
60 }
61 //--------------------------------------------------------------------------------
62
63 function edit_allocations_for_transaction($type, $trans_no)
64 {
65         global $systypes_array;
66
67     display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$_SESSION['alloc']->type],
68         $_SESSION['alloc']->trans_no));
69
70     display_heading($_SESSION['alloc']->person_name);
71
72     display_heading2(_("Date:") . " <b>" . $_SESSION['alloc']->date_ . "</b>");
73     display_heading2(_("Total:") . " <b>" . price_format($_SESSION['alloc']->amount) . "</b>");
74
75     echo "<br>";
76
77         start_form();
78         div_start('alloc_tbl');
79     if (count($_SESSION['alloc']->allocs) > 0)
80     {
81                 show_allocatable(true);
82         submit_center_first('UpdateDisplay', _("Refresh"), _('Start again allocation of selected amount'), true);
83         submit('Process', _("Process"), true, _('Process allocations'), 'default');
84                 submit_center_last('Cancel', _("Back to Allocations"),_('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
85         }
86         else
87         {
88         display_note(_("There are no unsettled transactions to allocate."), 0, 1);
89
90                 submit_center('Cancel', _("Back to Allocations"), true,
91                         _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
92     }
93         div_end();
94         end_form();
95 }
96
97 //--------------------------------------------------------------------------------
98
99 if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
100 {
101         clear_allocations();
102         $_SESSION['alloc'] = new allocation($_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 ?>