$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()); } // Manage invoice delivery switch ($invoice->delivery) { // Send invoice by email to the client case 'email': $Invoice->sendByEmail($id_new_invoice) or die("Unable to send email for invoice ID {$id_facture}"); break; // Send the invoice to me in order to print and send it to the client // Send the invoice to me in order to print and send it to the client case 'postal': $send_mail_print_invoice = true; $attachments[] = $Invoice->generatePDF($id_new_invoice, true); $Invoice->setSent($id_new_invoice); break; } // Process direct debit invoices if ($invoice->payment_method == 'direct_debit') { $new_invoice = $Invoice->getInfos($id_new_invoice); $send_mail_direct_debit = true; $url = "https://webfinance.isvtec.com/prospection/edit_facture.php?id_facture={$new_invoice->id_facture}"; # Set invoice as paid
function createAndSendInvoice($id_client, $prix_ht, $quantity, $description, $delivery_method) { # No invoice if amount is zero if ($prix_ht * $quantity <= 0) { return true; } $Facture = new Facture(); $invoice = array('client_id' => $id_client, 'rows' => array()); $id_facture = $Facture->create($invoice); // Get invoice payment $res = mysql_query("SELECT payment_method\n FROM webfinance_invoices i\n WHERE id_client = {$id_client}\n AND type_doc = 'facture'\n AND is_envoye = 1\n AND payment_method IS NOT NULL\n AND is_abandoned = 0\n ORDER BY id_facture DESC\n LIMIT 1") or die(mysql_error()); # Default values $payment_method = 'unknown'; if (mysql_num_rows($res) > 0) { $type_payment_res = mysql_fetch_array($res); $payment_method = $type_payment_res['payment_method']; } // Get id_compte $result = mysql_query('SELECT id_pref,value ' . 'FROM webfinance_pref ' . "WHERE type_pref='rib' " . 'LIMIT 1') or die(mysql_error()); $cpt = mysql_fetch_object($result); $id_compte = $cpt->id_pref; // Get id_type_presta $result = mysql_query("SELECT id_type_presta\n FROM webfinance_type_presta\n WHERE nom = 'Support mensuel'\n LIMIT 1") or die(mysql_error()); list($id_type_presta) = mysql_fetch_row($result); // Input facture parameters mysql_query("UPDATE webfinance_invoices SET\n\t\t is_paye = 0,\n\t\t is_envoye = 0,\n\t\t ref_contrat = 'Support professionnel',\n\t\t payment_method = '{$payment_method}',\n\t\t id_compte = {$id_compte},\n\t\t id_type_presta = {$id_type_presta}\n\t\t WHERE id_facture = {$id_facture}") or die(mysql_error()); // Add service rows to invoice $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", $id_facture, mysql_real_escape_string($description), $prix_ht, $quantity, $id_facture); $result = mysql_query($q) or die(mysql_error()); mysql_query("UPDATE webfinance_invoices SET date_generated=NULL WHERE id_facture=" . $id_facture) or die(mysql_error()); if ($payment_method == 'direct_debit') { // Plan the invoice to be debited mysql_query("INSERT INTO direct_debit_row " . "SET invoice_id = {$id_facture}, " . " state='todo'") or die(mysql_error()); // Flag invoice as paid $Facture->setPaid($id_facture); } // Manage invoice delivery and send by email to client switch ($delivery_method) { case 'email': $Facture->sendByEmail($id_facture) or die("Unable to send email for invoice ID {$id_facture}"); break; case 'postal': $send_mail_print_invoice = true; $attachments[] = $Facture->generatePDF($id_facture, true); $Facture->setSent($id_facture); break; } return true; }
echo _("Please add mail address!"); exit; } $from = ''; if (preg_match('/^[A-z0-9][\\w.-]*@[A-z0-9][\\w\\-\\.]+\\.[A-Za-z]{2,4}$/', $_POST['from'])) { $from = $_POST['from']; } $fromname = $_POST['from_name']; $subject = stripslashes($_POST['subject']); $body = stripslashes($_POST['body']); $docs = false; $invoice = new Facture(); if ($_POST['docs'] == 1) { $docs = true; } if (!$invoice->sendByEmail($id_invoice, $mails, $from, $fromname, $subject, $body, false, $docs)) { $_SESSION['message'] = _('Invoice was not sent'); $_SESSION['error'] = 1; echo _("Invoice was not sent"); die; } /* $_SESSION['message'] = _('Invoice sent'); */ //mettre à jour l'état de la facture, update sql mysql_query("UPDATE webfinance_invoices " . "SET is_envoye=1 " . "WHERE id_facture={$id_invoice}") or wf_mysqldie(); /* $_SESSION['message'] .= "<br/>"._('Invoice updated'); */ $facture = $invoice->getInfos($id_invoice); logmessage(_("Send invoice") . " #{$facture->num_facture} fa:{$id_invoice} " . "client:{$facture->id_client}"); header("Location: edit_facture.php?id_facture={$id_invoice}"); die; } $title = _("Send Invoice");
mail($paypal_params['email'], 'PAYPAL WARNING - IPN PROCESSING ERROR', $error . "\n\nDEBUG: \n\n" . $listener->getTextReport()); error_log($listener->getTextReport()); //Transaction OK } else { //Update invoice $req_update_invoice = "UPDATE webfinance_invoices SET \n\t\tpayment_method\t= 'paypal', \n\t\tis_paye\t\t\t= 1, \n\t\tdate_paiement\t= NOW() \n\t\tWHERE id_facture = " . $paypal_return[id_invoice]; mysql_query($req_update_invoice) or die(error_log($req_update_invoice . ' ' . mysql_error())); //Send email to staff mail($paypal_params['email'], "FA: #{$facture->num_facture} / {$facture->nom_client} has been paid with Paypal by {$paypal_return['email']}", "FYI:\n\n" . $listener->getTextReport()); //Send email to client $mails = array(); $from = ''; $fromname = ''; $subject = ''; $body = "Bonjour,\nVeuillez trouver ci-joint la facture numéro #{$facture->num_facture} de {$facture->nice_total_ttc} Euro payée par Paypal, transaction numéro : {$_POST['txn_id']}.\n\t\t\nPour visualiser et imprimer cette facture (au format PDF) vous pouvez utiliser \"Adobe Acrobat Reader\" disponible à l'adresse suivante :\nhttp://www.adobe.com/products/acrobat/readstep2.html\n\nCordialement,\nL'équipe {$societe->raison_sociale}."; if (!$Facture->sendByEmail($paypal_return['id_invoice'], $mails, $from, $fromname, $subject, $body)) { mail($paypal_params['email'], 'PAYPAL WARNING - Invoice was not sent to client after payment', $listener->getTextReport()); error_log('Invoice was not sent to client ' . $listener->getTextReport()); } //Debug if ($paypal_params['debug']) { mail($paypal_params['email'], 'Verified IPN', $listener->getTextReport()); } if ($paypal_params['debug']) { error_log($listener->getTextReport()); } $tnx_state = 'ok'; } //update transaction $req_update_payment = "UPDATE webfinance_payment SET \n\tstate\t\t\t= '" . $tnx_state . "',\n\ttransaction_id\t= '" . $_POST[txn_id] . "',\n\tpayment_fee\t\t= {$_POST['mc_fee']}, \t\n\tpayment_date\t= NOW()\n\tWHERE reference = '" . $_POST['custom'] . "'"; mysql_query($req_update_payment) or die(error_log(mysql_error()));
function SendPaymentRequest($id_invoice, $mode = 'paypal') { $Invoice = new Facture(); $invoice = $Invoice->getInfos($id_invoice); $client = new Client($invoice->id_client); $societe = GetCompanyInfo(); $q = "SELECT value FROM webfinance_pref WHERE type_pref='mail_paypal_" . $invoice->language . "'"; $result = mysql_query($q) or die(mysql_error()); list($data) = mysql_fetch_array($result); $pref = unserialize(base64_decode($data)); $varlink = $id_invoice . '|' . $invoice->id_client; $converter = new Encryption(); $encoded_varlink = $converter->encode($varlink); $link = $societe->wf_url . "/payment/?id={$encoded_varlink}"; $mails = array(); $from = ''; $fromname = ''; $subject = ''; $patterns = array('/%%NUM_INVOICE%%/', '/%%CLIENT_NAME%%/', '/%%URL_PAYPAL%%/', '/%%AMOUNT%%/', '/%%COMPANY%%/'); $replacements = array($invoice->num_facture, $invoice->nom_client, $link, $invoice->nice_total_ttc, $societe->raison_sociale); $body = stripslashes(preg_replace($patterns, $replacements, stripslashes(utf8_decode($pref->body)))); if (!$Invoice->sendByEmail($id_invoice, $mails, $from, $fromname, $subject, $body)) { die(_('Invoice was not sent')); } return $link; }