diff --git a/app/commands/SendRecurringInvoices.php b/app/commands/SendRecurringInvoices.php index 29b0cc41b3bf..b9f0b9dc79fb 100755 --- a/app/commands/SendRecurringInvoices.php +++ b/app/commands/SendRecurringInvoices.php @@ -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; diff --git a/app/libraries/utils.php b/app/libraries/utils.php index 25f07a52068f..feb12d2eb61f 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -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) ]; diff --git a/app/models/EntityModel.php b/app/models/EntityModel.php index 3269f8a8ac4f..20c4d79f9091 100755 --- a/app/models/EntityModel.php +++ b/app/models/EntityModel.php @@ -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(); } diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 2bf16e81d876..535ae0a847ee 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -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: diff --git a/app/routes.php b/app/routes.php index 0792d74093b2..db41fc1449fd 100755 --- a/app/routes.php +++ b/app/routes.php @@ -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() . '
'; + } + dd(true); +}); +*/ // TODO_FIX replace with cron Route::get('/send_emails', function() {