4 include($path_to_root . "/includes/ui/allocation_cart.inc");
7 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/date_functions.inc");
11 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/includes/banking.inc");
14 include_once($path_to_root . "/sales/includes/sales_db.inc");
16 if ($use_popup_windows)
17 $js .= get_js_open_window(900, 500);
21 page(_("Allocate Supplier Payment or Credit Note"), false, false, "", $js);
24 //--------------------------------------------------------------------------------
26 function clear_allocations()
28 if (isset($_SESSION['alloc']))
30 unset($_SESSION['alloc']->allocs);
31 unset($_SESSION['alloc']);
34 session_register("alloc");
37 //--------------------------------------------------------------------------------
43 for ($counter=0; $counter < $_POST["TotalNumberOfAllocs"]; $counter++)
46 if (!check_num('amount' . $counter, 0))
48 display_error(_("The entry for one or more amounts is invalid or negative."));
53 /*Now check to see that the AllocAmt is no greater than the
54 amount left to be allocated against the transaction under review */
55 if (input_num('amount' . $counter) > $_POST['un_allocated' . $counter])
57 //$_POST['amount' . $counter] = $_POST['un_allocated' . $counter];
60 $_SESSION['alloc']->allocs[$counter]->current_allocated = input_num('amount' . $counter);
62 $total_allocated += input_num('amount' . $counter);
65 if ($total_allocated + $_SESSION['alloc']->amount > sys_prefs::allocation_settled_allowance())
67 display_error(_("These allocations cannot be processed because the amount allocated is more than the total amount left to allocate."));
68 //echo _("Total allocated:") . " " . $total_allocated ;
69 //echo " " . _("Total amount that can be allocated:") . " " . -$_SESSION['alloc']->TransAmt . "<BR>";
76 //-----------------------------------------------------------------------------------
78 function handle_process()
82 // clear all the allocations for this payment/credit
83 clear_supp_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
85 // now add the new allocations
87 foreach ($_SESSION['alloc']->allocs as $alloc_item)
89 if ($alloc_item->current_allocated > 0)
91 add_supp_allocation($alloc_item->current_allocated,
92 $_SESSION['alloc']->type, $_SESSION['alloc']->trans_no,
93 $alloc_item->type, $alloc_item->type_no, $_SESSION['alloc']->date_);
95 update_supp_trans_allocation($alloc_item->type, $alloc_item->type_no,
96 $alloc_item->current_allocated);
97 $total_allocated += $alloc_item->current_allocated;
100 } /*end of the loop through the array of allocations made */
101 update_supp_trans_allocation($_SESSION['alloc']->type,
102 $_SESSION['alloc']->trans_no, $total_allocated);
104 commit_transaction();
109 //--------------------------------------------------------------------------------
111 if (isset($_POST['Process']))
116 $_POST['Cancel'] = 1;
120 //--------------------------------------------------------------------------------
122 if (isset($_POST['Cancel']))
125 meta_forward($path_to_root . "/purchasing/allocations/supplier_allocation_main.php");
129 //--------------------------------------------------------------------------------
131 function get_allocations_for_transaction($type, $trans_no)
135 $supptrans = get_supp_trans($trans_no, $type);
137 $_SESSION['alloc'] = new allocation($trans_no, $type,
138 $supptrans["supplier_id"], $supptrans["supplier_name"],
139 $supptrans["Total"], sql2date($supptrans["tran_date"]));
141 /* Now populate the array of possible (and previous actual) allocations for this supplier */
142 /*First get the transactions that have outstanding balances ie Total-alloc >0 */
144 $trans_items = get_allocatable_to_supp_transactions($_SESSION['alloc']->person_id);
146 while ($myrow = db_fetch($trans_items))
148 $_SESSION['alloc']->add_item($myrow["type"], $myrow["trans_no"],
149 sql2date($myrow["tran_date"]),
150 sql2date($myrow["due_date"]),
151 $myrow["Total"], // trans total
152 $myrow["alloc"], // trans total allocated
153 0); // this allocation
157 /* Now get trans that might have previously been allocated to by this trans
158 NB existing entries where still some of the trans outstanding entered from
159 above logic will be overwritten with the prev alloc detail below */
161 $trans_items = get_allocatable_to_supp_transactions($_SESSION['alloc']->person_id, $trans_no, $type);
163 while ($myrow = db_fetch($trans_items))
165 $_SESSION['alloc']->add_or_update_item ($myrow["type"], $myrow["trans_no"],
166 sql2date($myrow["tran_date"]),
167 sql2date($myrow["due_date"]),
169 $myrow["alloc"] - $myrow["amt"], $myrow["amt"]);
173 //--------------------------------------------------------------------------------
175 function edit_allocations_for_transaction($type, $trans_no)
179 start_form(false, true);
181 display_heading(_("Allocation of") . " " . systypes::name($_SESSION['alloc']->type) . " # " . $_SESSION['alloc']->trans_no);
183 display_heading($_SESSION['alloc']->person_name);
185 display_heading2(_("Date:") . " <b>" . $_SESSION['alloc']->date_ . "</b>");
186 display_heading2(_("Total:") . " <b>" . price_format(-$_SESSION['alloc']->amount) . "</b>");
190 if (count($_SESSION['alloc']->allocs) > 0)
192 start_table($table_style);
193 $th = array(_("Transaction Type"), _("#"), _("Date"), _("Due Date"), _("Amount"),
194 _("Other Allocations"), _("This Allocation"), _("Left to Allocate"),'');
197 $k = $counter = $total_allocated = 0;
199 foreach ($_SESSION['alloc']->allocs as $alloc_item)
201 alt_table_row_color($k);
203 label_cell(systypes::name($alloc_item->type));
204 label_cell(get_trans_view_str($alloc_item->type, $alloc_item->type_no));
205 label_cell($alloc_item->date_, "align=right");
206 label_cell($alloc_item->due_date, "align=right");
207 amount_cell($alloc_item->amount);
208 amount_cell($alloc_item->amount_allocated);
210 if (!isset($_POST['amount' . $counter]) || $_POST['amount' . $counter] == "")
211 $_POST['amount' . $counter] = price_format($alloc_item->current_allocated);
212 amount_cells(null, "amount" . $counter, price_format('amount' . $counter));
214 $un_allocated = round($alloc_item->amount - $alloc_item->amount_allocated, 6);
215 hidden("un_allocated" . $counter, $un_allocated);
216 amount_cell($un_allocated);
217 label_cell("<a href='#' name=Alloc$counter onclick='allocate_all(this.name.substr(5));return true;'>"
218 . _("All") . "</a>");
219 label_cell("<a href='#' name=DeAll$counter onclick='allocate_none(this.name.substr(5));return true;'>"
220 . _("None") . "</a>");
222 // label_cell("<a href='#' onclick='forms[0].amount$counter.value=forms[0].un_allocated$counter.value; return true;'>" . _("All") . "</a>");
223 // label_cell("<a href='#' onclick='forms[0].amount$counter.value=0; return true;'>" . _("None") . "</a>");
226 $total_allocated += input_num('amount' . $counter);
230 label_row(_("Total Allocated"), number_format2($total_allocated,user_price_dec()),
231 "colspan=6 align=right", "align=right id='total_allocated'");
232 if (-$_SESSION['alloc']->amount - $total_allocated < 0)
234 $font1 = "<font color=red>";
238 $font1 = $font2 = "";
239 $left_to_allocate = price_format(-$_SESSION['alloc']->amount - $total_allocated);
240 label_row(_("Left to Allocate"), $font1 . $left_to_allocate . $font2, "colspan=6 align=right",
241 "nowrap align=right id='left_to_allocate'");
244 hidden('TotalNumberOfAllocs', $counter);
245 // hidden('left_to_allocate', $left_to_allocate);
247 submit('UpdateDisplay', _("Update"));
249 submit('Process', _("Process"));
254 display_note(_("There are no unsettled transactions to allocate."), 0, 1);
258 submit('Cancel', _("Back to Allocations"));
259 echo "</center><br><br>";
264 //--------------------------------------------------------------------------------
266 if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
268 get_allocations_for_transaction($_GET['trans_type'], $_GET['trans_no']);
271 if (isset($_SESSION['alloc']))
273 edit_allocations_for_transaction($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
276 //--------------------------------------------------------------------------------