bug fixes

This commit is contained in:
Hillel Coren 2014-01-09 13:44:55 +00:00
parent 57544a771c
commit 9cec0dc33d
5 changed files with 36 additions and 12 deletions

View File

@ -23,14 +23,15 @@ class SendRecurringInvoices extends Command {
$this->info(date('Y-m-d') . ' Running SendRecurringInvoices...');
$today = new DateTime();
$invoices = Invoice::with('account', 'invoice_items')->whereRaw('is_recurring is true AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', array($today, $today))->get();
$this->info(count($invoices) . ' recurring invoice(s) found');
foreach ($invoices as $recurInvoice)
{
$this->info($recurInvoice->invoice_date);
$this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($recurInvoice->shouldSendToday() ? 'YES' : 'NO'));
if (!$recurInvoice->shouldSendToday())
{
continue;

View File

@ -18,13 +18,13 @@ class Utils
{
$count = Session::get('error_count', 0);
Session::put('error_count', ++$count);
if ($count > LOGGED_ERROR_LIMIT) return 'logged';
if ($count > 100) return 'logged';
$data = [
'context' => $context,
'user_id' => Auth::check() ? Auth::user()->id : 0,
'url' => Input::get('url'),
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => Request::getClientIp(),
'count' => Session::get('error_count', 0)
];

View File

@ -12,13 +12,18 @@ class EntityModel extends Eloquent
$className = get_called_class();
$entity = new $className();
if ($parent) {
if ($parent)
{
$entity->user_id = $parent->user_id;
$entity->account_id = $parent->account_id;
} else if (Auth::check()) {
}
else if (Auth::check())
{
$entity->user_id = Auth::user()->id;
$entity->account_id = Auth::user()->account_id;
} else {
}
else
{
Utils::fatalError();
}

View File

@ -89,27 +89,34 @@ class Invoice extends EntityModel
public function shouldSendToday()
{
//$dayOfWeekStart = strtotime($this->start_date);
return false;
$dayOfWeekToday = date('w');
$dayOfWeekStart = date('w', strtotime($this->start_date));
$dayOfMonthToday = date('j');
$dayOfMonthStart = date('j', strtotime($this->start_date));
if (!$this->last_sent_date) {
if (!$this->last_sent_date)
{
$daysSinceLastSent = 0;
$monthsSinceLastSent = 0;
} else {
}
else
{
$date1 = new DateTime($this->last_sent_date);
$date2 = new DateTime();
$diff = $date2->diff($date1);
$daysSinceLastSent = $diff->format("%a");
$monthsSinceLastSent = ($diff->format('%y') * 12) + $diff->format('%m');
if ($daysSinceLastSent == 0) {
if ($daysSinceLastSent == 0)
{
return false;
}
}
switch ($this->frequency_id)
{
case FREQUENCY_WEEKLY:

View File

@ -19,6 +19,9 @@
//dd(gethostname());
//Log::error('test');
/*
Event::listen('illuminate.query', function($query, $bindings, $time, $name)
{
@ -45,6 +48,14 @@ Event::listen('illuminate.query', function($query, $bindings, $time, $name)
});
*/
/*
Route::get('/test', function() {
foreach (Invoice::all() as $invoice) {
echo $invoice->id . ' ' . $invoice->shouldSendToday() . '<br/>';
}
dd(true);
});
*/
// TODO_FIX replace with cron
Route::get('/send_emails', function() {