page(_($help_context = "Create and Print Recurrent Invoices"), false, false, "", $js);
page(_($help_context = "Create and Print Recurrent Invoices"), false, false, "", $js);
-function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no)
+function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no, $date, $from, $to)
- $doc->reference = $Refs->get_next($doc->trans_type);
- //$doc->Comments='';
+ $doc->reference = $Refs->get_next($doc->trans_type, null, array('customer' => $customer_id, 'branch' => $branch_id,
+ 'date' => $date));
+ if ($doc->Comments != "")
+ $doc->Comments .= "\n";
+ $doc->Comments .= sprintf(_("Recurrent Invoice covers period %s - %s."), $from, add_days($to, -1));
+function calculate_from($myrow)
+{
+ if ($myrow["last_sent"] == '0000-00-00')
+ $from = sql2date($myrow["begin"]);
+ else
+ $from = sql2date($myrow["last_sent"]);
+ return $from;
+}
+
+if (!isset($_POST['date'])) {
+ $_POST['date'] = Today();
+}
+
if ($myrow['debtor_no'] == 0)
{
$cust = get_cust_branches_from_group($myrow['group_no']);
while ($row = db_fetch($cust))
{
if ($myrow['debtor_no'] == 0)
{
$cust = get_cust_branches_from_group($myrow['group_no']);
while ($row = db_fetch($cust))
{
- $invs[] = create_recurrent_invoices($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id']);
+ $invs[] = create_recurrent_invoices($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id'],
+ $date, $from, $to);
- $invs[] = create_recurrent_invoices($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id']);
+ $invs[] = create_recurrent_invoices($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id'],
+ $date, $from, $to);
if (count($invs) > 0)
{
$ar = array('PARAM_0' => $min."-".ST_SALESINVOICE, 'PARAM_1' => $max."-".ST_SALESINVOICE, 'PARAM_2' => "",
if (count($invs) > 0)
{
$ar = array('PARAM_0' => $min."-".ST_SALESINVOICE, 'PARAM_1' => $max."-".ST_SALESINVOICE, 'PARAM_2' => "",
- 'PARAM_3' => 0, 'PARAM_4' => 0, 'PARAM_5' => "", 'PARAM_6' => ST_SALESINVOICE);
+ 'PARAM_3' => 0, 'PARAM_4' => 0, 'PARAM_5' => "", 'PARAM_6' => user_def_print_orientation());
display_note(print_link(sprintf(_("&Print Recurrent Invoices # %s - # %s"), $min, $max), 107, $ar), 0, 1);
$ar['PARAM_3'] = 1; // email
display_note(print_link(sprintf(_("&Email Recurrent Invoices # %s - # %s"), $min, $max), 107, $ar), 0, 1);
}
}
else
display_note(print_link(sprintf(_("&Print Recurrent Invoices # %s - # %s"), $min, $max), 107, $ar), 0, 1);
$ar['PARAM_3'] = 1; // email
display_note(print_link(sprintf(_("&Email Recurrent Invoices # %s - # %s"), $min, $max), 107, $ar), 0, 1);
}
}
else
-start_table(TABLESTYLE, "width=70%");
+start_table(TABLESTYLE_NOBORDER);
+start_row();
+date_cells(_("Invoice date:"), 'date', '');
+end_row();
+end_table();
+
+start_table(TABLESTYLE, "width='70%'");
$th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"");
table_header($th);
$k = 0;
$th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"");
table_header($th);
$k = 0;
$due = false;
while ($myrow = db_fetch($result))
{
$begin = sql2date($myrow["begin"]);
$end = sql2date($myrow["end"]);
$due = false;
while ($myrow = db_fetch($result))
{
$begin = sql2date($myrow["begin"]);
$end = sql2date($myrow["end"]);
-
- if ($myrow["last_sent"] == '0000-00-00')
- {
- $last_sent = '';
- $due_date = $myrow["begin"];
- } else {
- $last_sent = sql2date($myrow["last_sent"]);
- if ($myrow['monthly'] > 0)
- $due_date = begin_month($last_sent);
- else
- $due_date = $last_sent;
- }
- $due_date = add_months($due_date, $myrow['monthly']);
+ $last_sent = calculate_from($myrow);
+ $due_date = add_months($last_sent, $myrow['monthly']);
$overdue = date1_greater_date2($today, $due_date) && date1_greater_date2($today, $begin)
&& date1_greater_date2($end, $today);
if ($overdue)
$overdue = date1_greater_date2($today, $due_date) && date1_greater_date2($today, $begin)
&& date1_greater_date2($end, $today);
if ($overdue)
if ($overdue)
button_cell("create".$myrow["id"], _("Create Invoices"), "", ICON_DOC);
else
if ($overdue)
button_cell("create".$myrow["id"], _("Create Invoices"), "", ICON_DOC);
else