diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 72f060ad0870..4d10f4cb3cc1 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -41,7 +41,7 @@ class DashboardController extends \BaseController { ->orderBy('due_date', 'asc')->take(6)->get(); $upcoming = Invoice::scope() - ->where('due_date', '>', date('Y-m-d')) + ->where('due_date', '>=', date('Y-m-d')) ->where('balance', '>', 0) ->where('is_recurring', '=', false) ->where('is_quote', '=', false) diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 0a1718e3a27c..34a71dab38e5 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -186,8 +186,15 @@ class InvoiceController extends \BaseController { $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); - $invoice->is_pro = $client->account->isPro(); - + $invoice->is_pro = $client->account->isPro(); + + $contact = $invitation->contact; + $contact->setVisible([ + 'first_name', + 'last_name', + 'email', + 'phone']); + $data = array( 'showClientHeader' => true, 'showBreadcrumbs' => false, @@ -195,6 +202,7 @@ class InvoiceController extends \BaseController { 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation, 'invoiceLabels' => $client->account->getInvoiceLabels(), + 'contact' => $contact ); return View::make('invoices.view', $data); @@ -347,7 +355,6 @@ class InvoiceController extends \BaseController { } $input = json_decode(Input::get('data')); - $invoice = $input->invoice; if ($errors = $this->invoiceRepo->getErrors($invoice)) diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 2a34c5e83172..3c64639de21d 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -498,7 +498,7 @@ class PaymentController extends \BaseController { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage); - Utils::logError($e->getMessage()); + Utils::logError(Utils::getErrorString($e)); return Redirect::to('license')->withInput(); } } @@ -653,7 +653,7 @@ class PaymentController extends \BaseController { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage); - Utils::logError($e->getMessage()); + Utils::logError(Utils::getErrorString($e)); return Redirect::to('payment/' . $invitationKey) ->withInput(); } diff --git a/app/database/migrations/2014_12_03_154119_add_discount_type.php b/app/database/migrations/2014_12_03_154119_add_discount_type.php new file mode 100644 index 000000000000..50b9e0787129 --- /dev/null +++ b/app/database/migrations/2014_12_03_154119_add_discount_type.php @@ -0,0 +1,34 @@ +boolean('is_amount_discount')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoices', function($table) + { + $table->dropColumn('is_amount_discount'); + }); + } + +} diff --git a/app/lang/da/texts.php b/app/lang/da/texts.php index fc118f6445f1..a178594d9bbb 100644 --- a/app/lang/da/texts.php +++ b/app/lang/da/texts.php @@ -490,6 +490,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', ); diff --git a/app/lang/de/texts.php b/app/lang/de/texts.php index 33bd01fdf10e..32b01db0002e 100644 --- a/app/lang/de/texts.php +++ b/app/lang/de/texts.php @@ -479,6 +479,9 @@ return array( 'restored_payment' => 'Successfully restored payment', 'restored_credit' => 'Successfully restored credit', + 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php index 325876dd1af6..1be03bccc3ad 100644 --- a/app/lang/en/texts.php +++ b/app/lang/en/texts.php @@ -488,6 +488,7 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', - + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', ); diff --git a/app/lang/es/texts.php b/app/lang/es/texts.php index a8684e0b918a..c325342adb4b 100644 --- a/app/lang/es/texts.php +++ b/app/lang/es/texts.php @@ -460,6 +460,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', ); \ No newline at end of file diff --git a/app/lang/fr/texts.php b/app/lang/fr/texts.php index 0f831aab8e1d..c8f64dd9443b 100644 --- a/app/lang/fr/texts.php +++ b/app/lang/fr/texts.php @@ -481,6 +481,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', ); \ No newline at end of file diff --git a/app/lang/it/texts.php b/app/lang/it/texts.php index 4e2b94caa7c8..f0f0e900909c 100644 --- a/app/lang/it/texts.php +++ b/app/lang/it/texts.php @@ -483,6 +483,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', diff --git a/app/lang/lt/texts.php b/app/lang/lt/texts.php index 8dddbaf91858..c3d3cbf1a8b6 100644 --- a/app/lang/lt/texts.php +++ b/app/lang/lt/texts.php @@ -491,6 +491,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', ); diff --git a/app/lang/nb_NO/texts.php b/app/lang/nb_NO/texts.php index 129896e3b830..06e5c1d28c4c 100644 --- a/app/lang/nb_NO/texts.php +++ b/app/lang/nb_NO/texts.php @@ -489,6 +489,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', diff --git a/app/lang/nl/texts.php b/app/lang/nl/texts.php index 96e0d9215e3f..c3a2d6873de9 100644 --- a/app/lang/nl/texts.php +++ b/app/lang/nl/texts.php @@ -484,7 +484,9 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', -); +); \ No newline at end of file diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/texts.php index 6e2ea4703a9f..3b8db1cbd54a 100644 --- a/app/lang/pt_BR/texts.php +++ b/app/lang/pt_BR/texts.php @@ -471,6 +471,8 @@ return array( 'restored_credit' => 'Successfully restored credit', 'reason_for_canceling' => 'Help us improve our site by telling us why you\'re leaving.', + 'discount_percent' => 'Percent', + 'discount_amount' => 'Amount', diff --git a/app/libraries/utils.php b/app/libraries/utils.php index ad0bc6fe0ff5..1884713ee1ff 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -140,6 +140,11 @@ class Utils return View::make('error', $data)->with('error', $message); } + public static function getErrorString($exception) + { + return "{$exception->getFile()} [Line {$exception->getLine()}] => {$exception->getMessage()}"; + } + public static function logError($error, $context = 'PHP') { $count = Session::get('error_count', 0); diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 2c3d08bae9f0..fdd53dbfb6b1 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -34,7 +34,7 @@ class Invoice extends EntityModel public function invitations() { - return $this->hasMany('Invitation'); + return $this->hasMany('Invitation')->orderBy('invitations.contact_id'); } public function getName() @@ -72,6 +72,7 @@ class Invoice extends EntityModel $this->setVisible([ 'invoice_number', 'discount', + 'is_amount_discount', 'po_number', 'invoice_date', 'due_date', @@ -95,8 +96,8 @@ class Invoice extends EntityModel $this->client->setVisible([ 'name', - 'id_number', - 'vat_number', + 'id_number', + 'vat_number', 'address1', 'address2', 'city', @@ -112,8 +113,8 @@ class Invoice extends EntityModel $this->account->setVisible([ 'name', - 'id_number', - 'vat_number', + 'id_number', + 'vat_number', 'address1', 'address2', 'city', diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index a3b303881147..7a8a17520c95 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -214,7 +214,10 @@ class InvoiceRepository $invoice = (array) $input; $invoiceId = isset($invoice['public_id']) && $invoice['public_id'] ? Invoice::getPrivateId($invoice['public_id']) : null; - $rules = ['invoice_number' => 'required|unique:invoices,invoice_number,' . $invoiceId . ',id,account_id,' . \Auth::user()->account_id]; + $rules = [ + 'invoice_number' => 'required|unique:invoices,invoice_number,' . $invoiceId . ',id,account_id,' . \Auth::user()->account_id, + 'discount' => 'positive' + ]; if ($invoice['is_recurring'] && $invoice['start_date'] && $invoice['end_date']) { @@ -248,7 +251,8 @@ class InvoiceRepository } $invoice->client_id = $data['client_id']; - $invoice->discount = Utils::parseFloat($data['discount']); + $invoice->discount = round(Utils::parseFloat($data['discount']), 2); + $invoice->is_amount_discount = $data['is_amount_discount'] ? true : false; $invoice->invoice_number = trim($data['invoice_number']); $invoice->is_recurring = $data['is_recurring'] && !Utils::isDemo() ? true : false; $invoice->invoice_date = Utils::toSqlDate($data['invoice_date']); @@ -309,7 +313,14 @@ class InvoiceRepository if ($invoice->discount > 0) { - $total *= (100 - $invoice->discount) / 100; + if ($invoice->is_amount_discount) + { + $total -= $invoice->discount; + } + else + { + $total *= (100 - $invoice->discount) / 100; + } } $invoice->custom_value1 = round($data['custom_value1'], 2); @@ -430,6 +441,7 @@ class InvoiceRepository foreach ([ 'client_id', 'discount', + 'is_amount_discount', 'invoice_date', 'po_number', 'due_date', diff --git a/app/ninja/repositories/PaymentRepository.php b/app/ninja/repositories/PaymentRepository.php index 585174bbfa6c..5305ac176bc4 100755 --- a/app/ninja/repositories/PaymentRepository.php +++ b/app/ninja/repositories/PaymentRepository.php @@ -56,7 +56,7 @@ class PaymentRepository ->where('clients.is_deleted', '=', false) ->where('payments.is_deleted', '=', false) ->where('invitations.deleted_at', '=', null) - ->where('contacts.id', '=', $contactId) + ->where('invitations.contact_id', '=', $contactId) ->select('invitations.invitation_key', 'payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email', 'payment_types.name as payment_type', 'payments.account_gateway_id'); if ($filter) diff --git a/app/routes.php b/app/routes.php index 656077a8f125..f3dd2b23bc4d 100755 --- a/app/routes.php +++ b/app/routes.php @@ -395,7 +395,7 @@ function otrans($text) Validator::extend('positive', function($attribute, $value, $parameters) { - return Utils::parseFloat($value) > 0; + return Utils::parseFloat($value) >= 0; }); Validator::extend('has_credit', function($attribute, $value, $parameters) diff --git a/app/start/global.php b/app/start/global.php index a8c2e5ff7d4b..cdc28d501857 100755 --- a/app/start/global.php +++ b/app/start/global.php @@ -60,7 +60,7 @@ App::error(function(Exception $exception, $code) { if (Utils::isNinjaProd()) { - Utils::logError("{$code} {$exception->getFile()} [Line {$exception->getLine()}] => {$exception->getMessage()}"); + Utils::logError($code . ' ' . Utils::getErrorString($exception)); return Response::view('error', ['hideHeader' => true, 'error' => "A {$code} error occurred."], $code); } else diff --git a/app/views/header.blade.php b/app/views/header.blade.php index eb4932197104..f1a0c638a0cc 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -361,7 +361,7 @@ Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice
-

{{ trans('texts.white_label_text')}}

+

{{ trans('texts.white_label_text')}}