This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/invoice/classes/Controller/Task/Invoice.php

94 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2011-08-16 02:27:19 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides OSB invoice task capabilities.
*
2013-03-19 22:35:19 +00:00
* @package Invoice
* @category Controllers
2011-08-16 02:27:19 +00:00
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
2011-08-16 02:27:19 +00:00
* @license http://dev.osbill.net/license.html
*/
class Controller_Task_Invoice extends Controller_Task {
2013-05-02 09:52:19 +00:00
public $auto_render = FALSE;
public function action_send() {
// Used to only process X invoices in a row.
2012-11-09 23:13:57 +00:00
$max = ORM::factory('Invoice')->config('EMAIL_INV_MAX');
2012-01-11 23:23:35 +00:00
2011-10-12 22:20:08 +00:00
$action = array();
$iid = $this->request->param('id');
$x = NULL;
if (preg_match('/:/',$iid))
list($iid,$x) = explode(':',$iid);
// Get our list of invoices to send
2012-11-09 23:13:57 +00:00
$i = $iid ? ORM::factory('Invoice')->where('id','=',$iid) : ORM::factory('Invoice')->list_tosend();
2011-10-12 22:20:08 +00:00
$key = 'send';
$max_count = 0;
2011-10-12 22:20:08 +00:00
foreach ($i->find_all() as $io) {
// If we have already sent a reminder or we dont email invoices we'll skip to the next one.
if (($io->remind($key) AND (is_null($x) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
2011-10-12 22:20:08 +00:00
continue;
// If we have issued the max number of invoices this round, finish.
if (++$max_count > $max)
break;
2011-10-12 22:20:08 +00:00
// Send our email
$et = Email_Template::instance('task_invoice_'.$key);
2012-11-09 23:13:57 +00:00
$token = ORM::factory('Module_Method_Token')
2011-10-12 22:20:08 +00:00
->method(array('invoice','user_download'))
->account($io->account)
->expire(time()+86400*21)
->uses(3)
->generate();
$et->to = array('account'=>array($io->account_id));
$et->variables = array(
'DUE'=>$io->due(TRUE),
'DUE_DATE'=>$io->display('due_date'),
2013-02-26 03:19:32 +00:00
'EMAIL'=>Company::instance()->email(),
2011-10-12 22:20:08 +00:00
'FIRST_NAME'=>$io->account->first_name,
'HTML_INVOICE'=>$io->html(),
'INV_NUM'=>$io->refnum(),
'INV_URL'=>URL::site(URL::link('user','invoice/view/'.$io->id),'http'),
'INV_URL_DOWNLOAD'=>URL::site(URL::link('user',sprintf('invoice/download/%s?token=%s',$io->id,$token)),'http'),
'SITE_NAME'=>Company::instance()->name(),
2011-10-12 22:20:08 +00:00
);
// @todo Record email log id if possible.
if ($et->send()) {
$io->print_status = 1;
$io->set_remind($key,time(),($x=='again' ? TRUE : FALSE));
2011-10-12 22:20:08 +00:00
array_push($action,(string)$io);
}
}
$this->response->body(_('Invoices Sent: ').join('|',$action));
}
/** END **/
public function action_audit_invoice_items() {
$output = '';
2012-11-09 23:13:57 +00:00
foreach (ORM::factory('Invoice_Item')->find_all() as $iio) {
if ($iio->product_name AND $iio->product_id) {
if (md5(strtoupper($iio->product_name)) == md5(strtoupper($iio->product->title()))) {
2012-07-05 03:06:17 +00:00
$iio->product_name = NULL;
$iio->save();
} else {
print_r(array("DIFF",'id'=>$iio->id,'pn'=>serialize($iio->product_name),'ppn'=>serialize($iio->product->title()),'pid'=>$iio->product_id,'test'=>strcasecmp($iio->product_name,$iio->product->title())));
}
}
}
$this->response->body($output);
}
2011-08-16 02:27:19 +00:00
}
?>