function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no, $date, $from, $to)
{
    global $Refs;
    $doc = new Cart(ST_SALESORDER, array($order_no));
    get_customer_details_to_order($doc, $customer_id, $branch_id);
    $doc->trans_type = ST_SALESORDER;
    $doc->trans_no = 0;
    $doc->document_date = $date;
    $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
    $doc->reference = $Refs->get_next($doc->trans_type);
    if ($doc->Comments != "") {
        $doc->Comments .= "\n";
    }
    $doc->Comments .= sprintf(_("Recurrent Invoice covers period %s - %s."), $from, add_days($to, -1));
    foreach ($doc->line_items as $line_no => $item) {
        $line =& $doc->line_items[$line_no];
        $line->price = get_price($line->stock_id, $doc->customer_currency, $doc->sales_type, $doc->price_factor, $doc->document_date);
    }
    $cart = $doc;
    $cart->trans_type = ST_SALESINVOICE;
    $cart->reference = $Refs->get_next($cart->trans_type);
    $invno = $cart->write(1);
    if ($invno == -1) {
        display_error(_("The entered reference is already in use."));
        display_footer_exit();
    }
    update_last_sent_recurrent_invoice($tmpl_no, $to);
    return $invno;
}
Exemplo n.º 2
0
    }
    if (!is_date($_POST['end'])) {
        $input_error = 1;
        display_error(_("The entered date is invalid."));
        set_focus('end');
    }
    if (isset($_POST['last_sent']) && !is_date($_POST['last_sent'])) {
        $input_error = 1;
        display_error(_("The entered date is invalid."));
        set_focus('last_sent');
    }
    if ($input_error != 1) {
        if ($selected_id != -1) {
            update_recurrent_invoice($selected_id, $_POST['description'], $_POST['order_no'], input_num('debtor_no'), input_num('group_no'), input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
            if (isset($_POST['last_sent'])) {
                update_last_sent_recurrent_invoice($selected_id, $_POST['last_sent']);
            }
            $note = _('Selected recurrent invoice has been updated');
        } else {
            add_recurrent_invoice($_POST['description'], $_POST['order_no'], input_num('debtor_no'), input_num('group_no'), input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
            $note = _('New recurrent invoice has been added');
        }
        display_notification($note);
        $Mode = 'RESET';
    }
}
if ($Mode == 'Delete') {
    $cancel_delete = 0;
    if ($cancel_delete == 0) {
        delete_recurrent_invoice($selected_id);
        display_notification(_('Selected recurrent invoice has been deleted'));