+} elseif (isset($_GET['AllocationNumber']) || isset($_GET['InvoicePrepayments'])) {
+
+ check_deferred_income_act(_("You have to set Deferred Income Account in GL Setup to entry prepayment invoices."));
+
+ if (isset($_GET['AllocationNumber']))
+ {
+ $payments = array(get_cust_allocation($_GET['AllocationNumber']));
+
+ if (!$payments || ($payments[0]['trans_type_to'] != ST_SALESORDER))
+ {
+ display_error(_("Please select correct Sales Order Prepayment to be invoiced and try again."));
+ display_footer_exit();
+ }
+ $order_no = $payments[0]['trans_no_to'];
+ }
+ else {
+ $order_no = $_GET['InvoicePrepayments'];
+ $payments = get_payments_for($_GET['InvoicePrepayments'], ST_SALESORDER);
+ }
+ processing_start();
+
+ $_SESSION['Items'] = new Cart(ST_SALESORDER, $order_no, ST_SALESINVOICE);
+ $_SESSION['Items']->order_no = $order_no;
+ $_SESSION['Items']->src_docs = array($order_no);
+ $_SESSION['Items']->trans_no = 0;
+ $_SESSION['Items']->trans_type = ST_SALESINVOICE;
+ $_SESSION['Items']->prepayments = $payments;
+ // prepayment invoice has all line quantities as stated on order.
+// foreach($_SESSION['Items']->line_items as &$line)
+// {
+// $line->src_id = $line_id;
+// $line->qty_dispatched = $line->quantity;
+// }
+// unset($line);
+ $_SESSION['Items']->update_payments();
+
+// $_SESSION['Items']->alloc = $this_amount;
+ copy_from_cart();
+}
+ elseif (!processing_active()) {