Ejemplo n.º 1
0
$send_mail_print_invoice = false;
$send_mail_direct_debit = false;
$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
Ejemplo n.º 2
0
     $result = mysql_query("SELECT count(*) FROM webfinance_invoices\n                           WHERE num_facture!=''\n                           AND year(date_facture)=year('" . $facture->date_facture . "')") or wf_mysqldie();
     list($nb) = mysql_fetch_array($result);
     mysql_free_result($result);
     $nb++;
     $nb = sprintf("%04d", $nb);
     $num_facture = strftime("%y-{$nb}", $facture->timestamp_date_facture);
 }
 //date prev
 //   $date_prev=$facture->timestamp_date_facture+($_POST['type_prev'] * 86400 );
 //   $date_prev=date("Y-m-d",$date_prev);
 $res = mysql_query("SELECT count(*) FROM webfinance_invoices WHERE num_facture='{$num_facture}' AND id_facture<>{$id_facture} ") or wf_mysqldie();
 list($dup_num_inv) = mysql_fetch_array($res);
 mysql_free_result($res);
 // Generate periodic_next_deadline if needed
 if ($periodic_next_deadline == '0000-00-00' and $period != 'none') {
     $periodic_next_deadline = $Facture->nextDeadline(date('Y-m-d'), $period);
 }
 $q = sprintf("UPDATE webfinance_invoices SET " . "id_client=%d, " . "type_paiement='%s', " . "is_paye=%d, " . "%s  " . "is_envoye=%d, " . "%s  " . "ref_contrat='%s', " . "extra_top='%s', " . "extra_bottom='%s', " . "accompte='%s', " . "date_facture='%s', " . "type_doc='%s', " . "commentaire='%s', " . "id_type_presta=%d, " . "is_abandoned=%d, " . "id_compte=%d, " . "is_envoye=%d, " . "tax='%s', " . "exchange_rate='%s', " . "period='%s', " . "periodic_next_deadline='%s', " . "payment_method='%s', " . "delivery='%s' " . "%s " . "WHERE id_facture=%d", $id_client, $type_paiement, $is_paye == "on" ? 1 : 0, empty($date_paiement) ? 'date_paiement=NULL,' : "date_paiement='{$date_paiement}',", $is_envoye == "on" ? 1 : 0, empty($date_sent) ? 'date_sent=NULL,' : "date_sent='{$date_sent}',", $ref_contrat, mysql_real_escape_string($extra_top), mysql_real_escape_string($extra_bottom), WFO::stripMonetaryFormat($accompte), $date_facture, $type_doc, $commentaire, $id_type_presta, $is_abandoned == "on" ? 1 : 0, $id_compte, $is_envoye == "on" ? 1 : 0, $tax, empty($exchange_rate) ? 1 : $exchange_rate, $period, $periodic_next_deadline, $payment_method, $delivery, $dup_num_inv == 0 ? ",num_facture='{$num_facture}' " : "", $id_facture);
 mysql_query($q) or die(mysql_error() . "<br/> {$q}");
 logmessage(_("Save invoice") . " (#{$num_facture}) fa:" . $_POST['id_facture'] . " client:{$facture->id_client}", $facture->id_client, $_POST['id_facture']);
 if (empty($_POST['prix_ht_new'])) {
     $_POST['prix_ht_new'] = '0.0';
 }
 if (is_numeric($_POST['prix_ht_new']) && is_numeric($_POST['qtt_new']) && !empty($_POST['prix_ht_new']) && !empty($_POST['line_new'])) {
     // Enregistrement d'une nouvelle ligne de facturation pour une facture.
     $q = sprintf("INSERT INTO webfinance_invoice_rows (id_facture,description,prix_ht,qtt,ordre) " . "SELECT %d, '%s', %s, %s, if(max(ordre) is NULL, 1, max(ordre) + 1) " . "FROM webfinance_invoice_rows " . "WHERE id_facture=%d", $_POST['id_facture'], mysql_real_escape_string($_POST['line_new']), $_POST['prix_ht_new'], $_POST['qtt_new'], $_POST['id_facture']);
     $result = mysql_query($q) or wf_mysqldie();
     mysql_query("UPDATE webfinance_invoices SET date_generated=NULL WHERE id_facture=" . $_POST['id_facture']) or wf_mysqldie();
 }
 // Enregistrement des lignes existantes
 foreach ($_POST as $k => $v) {