d26ed61bf796ce02c4e51dbf09c0f11c22ea8bd1
[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 $page_security = 'SA_SUPPLIERALLOC';
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/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 ($SysPrefs->use_popup_windows)
25         $js .= get_js_open_window(900, 500);
26
27 add_js_file('allocate.js');
28
29 page(_($help_context = "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         global $systypes_array;
47
48         start_form();
49
50         $cart = $_SESSION['alloc'];
51
52     display_heading(_("Allocation of") . " " . $systypes_array[$cart->type] . " # " . $cart->trans_no);
53
54         display_heading($cart->person_name);
55
56     display_heading2(_("Date:") . " <b>" . $cart->date_ . "</b>");
57
58         display_heading2(_("Total:"). " <b>" . price_format(-$cart->bank_amount).' '.$cart->currency."</b>");
59
60         if (floatcmp($cart->bank_amount, $cart->amount))
61         {
62             $total = _("Amount ot be settled:") . " <b>" . price_format(-$cart->amount).' '.$cart->person_curr."</b>";
63                 if ($cart->currency != $cart->person_curr)
64                 $total .= sprintf(" (%s %s/%s)",  exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr);
65                 display_heading2($total);
66         }
67     echo "<br>";
68
69         div_start('alloc_tbl');
70     if (count($cart->allocs) > 0)
71     {
72                 show_allocatable(true);
73
74         submit_center_first('UpdateDisplay', _("Refresh"), _('Start again allocation of selected amount'), true);
75         submit('Process', _("Process"), true, _('Process allocations'), 'default');
76                 submit_center_last('Cancel', _("Back to Allocations"),
77                         _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
78         }
79         else
80         {
81         display_note(_("There are no unsettled transactions to allocate."), 0, 1);
82                 submit_center('Cancel', _("Back to Allocations"), true,
83                         _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
84     }
85
86         div_end();
87         end_form();
88 }
89 //--------------------------------------------------------------------------------
90
91 if (isset($_POST['Process']))
92 {
93         if (check_allocations())
94         {
95                 $_SESSION['alloc']->write();
96                 clear_allocations();
97                 $_POST['Cancel'] = 1;
98         }
99 }
100
101 //--------------------------------------------------------------------------------
102
103 if (isset($_POST['Cancel']))
104 {
105         clear_allocations();
106         meta_forward($path_to_root . "/purchasing/allocations/supplier_allocation_main.php");
107 }
108
109 //--------------------------------------------------------------------------------
110
111 if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
112 {
113         $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no'], @$_GET['supplier_id'], PT_SUPPLIER);
114 }
115
116 if (get_post('UpdateDisplay'))
117 {
118         $_SESSION['alloc']->read();
119         $Ajax->activate('alloc_tbl');
120 }
121
122 if (isset($_SESSION['alloc']))
123 {
124         edit_allocations_for_transaction($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
125 }
126
127 //--------------------------------------------------------------------------------
128
129 end_page();
130