示例#1
0
 /**
  * Method to send the email
  * @param $idinvoice -- INT
  * @param $idcontact -- INT
  * @param $iduser -- INT
  * @param $recurrent -- Boolean
  */
 function sendInvoiceByEmail($idinvoice, $idcontact, $iduser, $recurrent = false)
 {
     $do_contact = new Contact();
     $do_user_rel = new UserRelations();
     $this->getId($idinvoice);
     if ($recurrent === true) {
         $this->sessionPersistent("do_invoice", "index.php", OFUZ_TTL);
     }
     $do_contact->getId($idcontact);
     $contact_name = $do_contact->firstname . ' ' . $do_contact->lastname;
     $do_contact_email = $do_contact->getChildContactEmail();
     $contact_email = $do_contact_email->getDefaultEmail();
     $do_user_detail = new User();
     $do_user_detail->getId($iduser);
     if ($contact_email) {
         $total_due = $this->amt_due;
         $total_due = $this->viewAmount($total_due);
         if ($recurrent) {
             $do_rec_invoice = new RecurrentInvoice();
             $idrec = $do_rec_invoice->checkIfInvoiceIsInRecurrent($idinvoice);
             if ($idrec) {
                 $email_template = new EmailTemplate("ofuz_send_recurrent_invoice");
                 $do_rec_invoice->getId($idrec);
                 $next_due_date = $do_rec_invoice->nextdate;
                 $recurrence = $do_rec_invoice->recurrence;
                 $recurrence_type = $do_rec_invoice->recurrence_type;
             } else {
                 $email_template = new EmailTemplate("ofuz_send_invoice");
             }
         } else {
             $email_template = new EmailTemplate("ofuz_send_invoice");
         }
         if ($this->status == 'Quote') {
             $email_template = new EmailTemplate("ofuz_send_quote");
         }
         $email_template->setSenderName($do_user_detail->getFullName());
         $email_template->setSenderEmail($do_user_detail->email);
         $signature = $do_user_detail->company . '<br />' . $do_user_detail->getFullName();
         $description = $this->description;
         $invoice_url = $GLOBALS['cfg_ofuz_site_https_base'] . 'inv/' . $do_user_rel->encrypt($idinvoice) . '/' . $do_user_rel->encrypt($idcontact);
         $email_data = array('name' => $contact_name, 'sender' => $do_user_detail->getFullName(), 'company' => $do_user_detail->company, 'description' => $description, 'invoice_url' => $invoice_url, 'num' => $this->num, 'signature' => $signature, 'amount' => $total_due, 'recurrence' => $recurrence, 'recurrence_type' => $recurrence_type, 'next_due_date' => $next_due_date);
         $emailer = new Radria_Emailer();
         $emailer->setEmailTemplate($email_template);
         $emailer->mergeArray($email_data);
         $emailer->addTo($contact_email);
         //attachment starts
         // Some bug in the PDF part it does not send the correct PDF as it says due amt is 0. Happens for the cron to send recurrent inv
         //echo '<br />Calling Method generatePDFInvoice().....<br />';
         // This is fixed
         $this->generatePDFInvoice($invoice_url);
         $fpdf_file_name = $this->getEncryptedFileName("pdf");
         $pdfFilePath = "invoice_pdf/{$fpdf_file_name}";
         $pdfFile = file_get_contents($pdfFilePath);
         $at = $emailer->createAttachment($pdfFile);
         $at->type = 'image/pdf';
         $at->disposition = Zend_Mime::DISPOSITION_INLINE;
         $at->encoding = Zend_Mime::ENCODING_BASE64;
         $at->filename = $fpdf_file_name;
         //attachment ends
         $emailer->send();
         if ($this->status == 'New') {
             $this->status = 'Sent';
             $this->update();
         }
         if ($recurrent) {
             $q = new sqlQuery($this->getDbCon());
             $q->query("update invoice set status = 'Sent' where idinvoice = " . $idinvoice . " Limit 1");
             $q->free();
         }
         $_SESSION['in_page_message'] = "client_invoice_sent";
         $_SESSION['in_page_message_data']['contact_email'] = $contact_email;
     } else {
         $_SESSION['in_page_message'] = "invoice_client_email_not_found";
     }
     $do_user_detail->free();
 }
            $do_inv_line->description = $inv_line->description;
            $do_inv_line->price = $inv_line->price;
            $do_inv_line->qty = $inv_line->qty;
            $do_inv_line->total = $inv_line->total;
            $do_inv_line->item = $inv_line->item;
            $do_inv_line->add();
        }
        $do_invoice->setInvoiceCalculations($idinvoice);
        // Call this method for other calculations
        //update callback
        $do_inv_callbak = new InvoiceCallback();
        $do_inv_callbak->updateCallBack($do_recurrent->idcontact, $idinvoice);
        // Process RegistrationInvoiceLog will update only if the invoice is from registration Part of Ofuz.com
        $do_RegistrationInvoiceLog = new RegistrationInvoiceLog();
        // @params old invoiceid,new invoice id and the iduser
        $do_RegistrationInvoiceLog->process_reg_invoice_log($do_recurrent->idinvoice, $idinvoice, $do_recurrent->iduser);
        // Update Recurrent
        $do_recurrent_update = new RecurrentInvoice();
        $next_date = $do_recurrent_update->getNextDate($do_recurrent->recurrence, $do_recurrent->recurrencetype, $do_recurrent->nextdate);
        $do_recurrent_update->getId($do_recurrent->idrecurrentinvoice);
        $do_recurrent_update->nextdate = $next_date;
        $do_recurrent_update->idinvoice = $idinvoice;
        $do_recurrent_update->update();
        $do_recurrent_update->free();
        //Sending Email to the customer
        //echo 'Calling method sendInvoiceByEmail()..........<br />';
        $do_inv_add->sendInvoiceByEmail($idinvoice, $do_inv_add->idcontact, $do_inv_add->iduser, true);
        $do_inv_add->free();
        //}
    }
}