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 = "../..";
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");
23 if ($SysPrefs->use_popup_windows)
24 $js .= get_js_open_window(900, 500);
26 add_js_file('allocate.js');
28 page(_($help_context = "Allocate Customer Payment or Credit Note"), false, false, "", $js);
30 //--------------------------------------------------------------------------------
32 function clear_allocations()
34 if (isset($_SESSION['alloc']))
36 unset($_SESSION['alloc']->allocs);
37 unset($_SESSION['alloc']);
39 //session_register('alloc');
42 //--------------------------------------------------------------------------------
44 function edit_allocations_for_transaction($type, $trans_no)
46 global $systypes_array;
48 $cart = $_SESSION['alloc'];
50 if ($cart->type == ST_JOURNAL && $cart->bank_amount < 0)
52 $cart->bank_amount = -$cart->bank_amount;
53 $cart->amount = -$cart->amount;
55 display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$cart->type], $cart->trans_no));
57 display_heading($cart->person_name);
59 display_heading2(_("Date:") . " <b>" . $cart->date_ . "</b>");
60 display_heading2(_("Total:"). " <b>" . price_format($cart->bank_amount).' '.$cart->currency."</b>");
62 if (floatcmp($cart->bank_amount, $cart->amount))
64 $total = _("Amount to be settled:") . " <b>" . price_format($cart->amount).' '.$cart->person_curr."</b>";
65 if ($cart->currency != $cart->person_curr)
66 $total .= sprintf(" (%s %s/%s)", exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr);
67 display_heading2($total);
73 div_start('alloc_tbl');
74 if (count($cart->allocs) > 0)
76 show_allocatable(true);
77 submit_center_first('UpdateDisplay', _("Refresh"), _('Start again allocation of selected amount'), true);
78 submit('Process', _("Process"), true, _('Process allocations'), 'default');
79 submit_center_last('Cancel', _("Back to Allocations"),_('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
83 display_note(_("There are no unsettled transactions to allocate."), 0, 1);
85 submit_center('Cancel', _("Back to Allocations"), true,
86 _('Abandon allocations and return to selection of allocatable amounts'), 'cancel');
92 //--------------------------------------------------------------------------------
94 if (isset($_POST['Process']))
96 if (check_allocations())
98 $_SESSION['alloc']->write();
100 $_POST['Cancel'] = 1;
103 //--------------------------------------------------------------------------------
105 if (isset($_POST['Cancel']))
108 meta_forward($path_to_root . "/sales/allocations/customer_allocation_main.php");
111 //--------------------------------------------------------------------------------
113 if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
116 $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no'], @$_GET['debtor_no'], PT_CUSTOMER);
119 if(get_post('UpdateDisplay'))
121 $_SESSION['alloc']->read();
122 $Ajax->activate('alloc_tbl');
125 if (isset($_SESSION['alloc']))
127 edit_allocations_for_transaction($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
130 //--------------------------------------------------------------------------------