+$id = find_submit('create');
+if ($id != -1)
+{
+ $Ajax->activate('_page_body');
+ $date = Today();
+ $myrow = get_recurrent_invoice($id);
+ $from = calculate_from($myrow);
+ $to = add_months($from, $myrow['monthly']);
+ $to = add_days($to, $myrow['days']);
+
+ if (!is_date_in_fiscalyear($date))
+ display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
+ elseif (!date1_greater_date2(add_days(Today(), 1), $to))
+ display_error(_("Recurrent invoice cannot be generated before last day of covered period."));
+ elseif (check_recurrent_invoice_prices($id))
+ display_error(_("Recurrent invoices cannot be generated because some items have no price defined in customer currency."));
+ elseif (!check_sales_order_type($myrow['order_no']))
+ display_error(_("Recurrent invoices cannot be generated because selected sales order template uses prepayment sales terms. Change payment terms and try again."));
+ else {
+ $count = recurrent_invoice_count($id);
+
+ $_POST['trans_date'] = $to;
+ start_form();
+ start_table(TABLESTYLE, "width=50%");
+ label_row(_('Description:'), $myrow["description"]);
+ label_row(_('Template:'), get_customer_trans_view_str(ST_SALESORDER, $myrow["order_no"]));
+ label_row(_('Number of invoices:'), $count);
+ date_row(_('Invoice date:'), 'trans_date');
+ text_row(_('Invoice notice:'), 'memo', sprintf(_("Recurrent Invoice covers period %s - %s."), $from, add_days($to, -1)),
+ 100, 100);
+ end_table();
+ hidden('from', $from, true);
+ hidden('to', $to, true);
+ br();
+ submit_center_first('confirmed'.$id, _('Create'), _('Create recurrent invoices'), false, ICON_OK);
+ submit_center_last('cancel', _('Cancel'), _('Return to recurrent invoices'), false, ICON_ESCAPE);
+ submit_js_confirm("do_create".$id, sprintf(_("You are about to issue %s invoices.\n Do you want to continue?"), $count));
+ end_form();