$attachments = array(); $Invoice = new Facture(); // Define French locale in order to generate French dates setlocale(LC_TIME, "fr_FR.UTF8"); // Fetch periodic invoices where the deadline is over $result = mysql_query('SELECT id_facture ' . 'FROM webfinance_invoices ' . "WHERE period!='none' AND " . 'periodic_next_deadline<=NOW() AND ' . "type_doc = 'facture'") or die(mysql_error()); if (mysql_num_rows($result) == 0) { exit; } while (list($id_invoice) = mysql_fetch_row($result)) { // Fetch info from invoice $invoice = $Invoice->getInfos($id_invoice); // Calculate next deadline $next_deadline = $Invoice->nextDeadline($invoice->periodic_next_deadline, $invoice->period); // Duplicate the invoice $id_new_invoice = $Invoice->duplicate($id_invoice); // Delete setup fees that only have to be paid once $query = 'DELETE FROM webfinance_invoice_rows ' . "WHERE (description LIKE '%Frais d\\'accès au service%' " . "OR description LIKE '%Frais d\\'installation%' " . "OR description LIKE '%rais de migration%') " . "AND id_facture={$id_new_invoice}"; mysql_query($query) or die("{$query}:" . mysql_error()); // Add dynamic start date and deadline in invoice details $query = 'SELECT id_facture_ligne, description ' . 'FROM webfinance_invoice_rows ' . "WHERE id_facture={$id_new_invoice}"; $res = mysql_query($query) or die("{$query}:" . mysql_error()); // Update dates in invoices description while ($invoice_row = mysql_fetch_array($res)) { if (!preg_match('/ du \\d{4}-\\d{2}-\\d{2} au \\d{4}-\\d{2}-\\d{2}/', $invoice_row['description'])) { continue; } $invoice_row['description'] = mysql_real_escape_string(preg_replace('/ du (\\d{4}-\\d{2}-\\d{2}) au (\\d{4}-\\d{2}-\\d{2})/', " du {$invoice->periodic_next_deadline} au {$next_deadline}", $invoice_row['description'])); // Update invoice date $query = 'UPDATE webfinance_invoice_rows ' . "SET description='{$invoice_row['description']}'" . "WHERE id_facture_ligne={$invoice_row['id_facture_ligne']}"; mysql_query($query) or die("{$query}:" . mysql_error());
$facture = $Facture->getInfos($_GET['id_facture']); logmessage(_("Delete invoice") . " #{$facture->num_facture} for client:{$facture->id_client}", $facture->id_client); $id_client = $facture->id_client; mysql_query("DELETE FROM webfinance_invoices WHERE id_facture=" . $_GET['id_facture']) or wf_mysqldie(); $_SESSION['message'] = _('Invoice deleted'); //mysql_query("DELETE FROM webfinance_invoice_rows WHERE id_facture=".$_GET['id_facture']); <- ON DELETE CASCADE mysql_query("DELETE FROM webfinance_transactions WHERE id_invoice=" . $_GET['id_facture'] . " AND type<>'real'") or wf_mysqldie(); $_SESSION['message'] .= "<br/>" . _('Transaction deleted'); } header("Location: fiche_prospect.php?onglet=billing&tab=billing&id={$id_client}"); exit; } if ($action == "duplicate") { extract($_GET); $Invoice = new Facture(); $id_new_facture = $Invoice->duplicate($id); if ($id_new_facture) { logmessage("New invoice fa:{$id_new_facture} duplicated of fa:{$id} ", 'NULL', $id); $Invoice->updateTransaction($id_new_facture); /* $_SESSION['message'] = _("Invoice duplicated"); */ header("Location: edit_facture.php?id_facture={$id_new_facture}"); die; } else { //Error; die("duplicate action failed"); } die; } if ($action == "send") { extract($_POST); require "/usr/share/php/libphp-phpmailer/class.phpmailer.php";