Exemplo n.º 1
0
            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
        $Invoice->setPaid($id_new_invoice);
        # Plan the invoice to be debited
        mysql_query('INSERT INTO direct_debit_row ' . "SET invoice_id = {$id_new_invoice}, " . "    state='todo'") or die(mysql_error());
    }
    // Process paypal invoices
    if ($invoice->payment_method == 'paypal') {
        $Invoice->SendPaymentRequest($id_new_invoice);
    }
    // Update deadline
    mysql_query('UPDATE webfinance_invoices ' . "SET periodic_next_deadline='{$next_deadline}' " . "WHERE id_facture = {$id_invoice}") or die(mysql_error());
}
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
if ($send_mail_print_invoice) {
    $mail->From = '*****@*****.**';
    $mail->FromName = 'ISVTEC invoices';
Exemplo n.º 2
0
   (at your option) any later version.

    Webfinance is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Webfinance; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
include "../inc/main.php";
must_login();
$roles = 'manager,employee';
include "nav.php";
$Invoice = new Facture();
if (!isset($_GET['id']) or !is_numeric($_GET['id']) or !$Invoice->exists($_GET['id'])) {
    echo "Invalid invoice id";
    exit(1);
}
$facture = $Invoice->getInfos($_GET['id']);
if ($facture->is_paye) {
    echo "Invoice has already been paid";
    exit(1);
}
// Plan the invoice to be debited
mysql_query("INSERT INTO direct_debit_row " . "SET invoice_id = {$_GET['id']}, " . "    state='todo'") or die(mysql_error());
// Flag invoice as paid
$Invoice->setPaid($_GET['id']);
header("Location: ../prospection/edit_facture.php?id_facture={$_GET['id']}");
exit;
Exemplo n.º 3
0
 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;
 }