From 33364d3d9c69d788f9a7db4e604f53a1091204ec Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 30 Jul 2015 20:48:59 +0300 Subject: [PATCH] Bug fixes --- app/Http/Controllers/InvoiceApiController.php | 8 ++++++-- app/Http/Controllers/QuoteApiController.php | 6 +++++- app/Models/Activity.php | 2 ++ app/Ninja/Repositories/InvoiceRepository.php | 2 +- database/seeds/PaymentLibrariesSeeder.php | 10 ++++++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 02fb8e19bf9a..4c13259aecb2 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -26,7 +26,11 @@ class InvoiceApiController extends Controller public function index() { - $invoices = Invoice::scope()->with('client', 'invitations.account')->where('invoices.is_quote', '=', false)->orderBy('created_at', 'desc')->get(); + $invoices = Invoice::scope() + ->with('client', 'invitations.account') + ->where('invoices.is_quote', '=', false) + ->orderBy('created_at', 'desc') + ->get(); // Add the first invitation link to the data foreach ($invoices as $key => $invoice) { @@ -100,7 +104,7 @@ class InvoiceApiController extends Controller } else { $data = self::prepareData($data); $data['client_id'] = $client->id; - $invoice = $this->invoiceRepo->save(isset($data['id']) ? $data['id'] : false, $data, false); + $invoice = $this->invoiceRepo->save(false, $data, false); if (!isset($data['id'])) { $invitation = Invitation::createNew(); diff --git a/app/Http/Controllers/QuoteApiController.php b/app/Http/Controllers/QuoteApiController.php index 70257644c544..83e5e8781179 100644 --- a/app/Http/Controllers/QuoteApiController.php +++ b/app/Http/Controllers/QuoteApiController.php @@ -16,7 +16,11 @@ class QuoteApiController extends Controller public function index() { - $invoices = Invoice::scope()->with('client', 'user')->where('invoices.is_quote', '=', true)->orderBy('created_at', 'desc')->get(); + $invoices = Invoice::scope() + ->with('client', 'user') + ->where('invoices.is_quote', '=', true) + ->orderBy('created_at', 'desc') + ->get(); $invoices = Utils::remapPublicIds($invoices); $response = json_encode($invoices, JSON_PRETTY_PRINT); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 5997412ebf2b..0dd5ec54bf37 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -214,6 +214,8 @@ class Activity extends Eloquent if ($invoice->isPaid() && $invoice->balance > 0) { $invoice->invoice_status_id = INVOICE_STATUS_PARTIAL; + } elseif ($invoice->invoice_status_id && $invoice->balance == 0) { + $invoice->invoice_status_id = INVOICE_STATUS_PAID; } } } diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 0d3b2e8ce565..e93ea47826bb 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -390,7 +390,7 @@ class InvoiceRepository $task->invoice_id = $invoice->id; $task->client_id = $invoice->client_id; $task->save(); - } else if ($item['product_key']) { + } else if ($item['product_key'] && !$invoice->has_tasks) { $product = Product::findProductByKey(trim($item['product_key'])); if (!$product) { diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index 73eb34c0e438..9e9af179cb2b 100644 --- a/database/seeds/PaymentLibrariesSeeder.php +++ b/database/seeds/PaymentLibrariesSeeder.php @@ -64,7 +64,7 @@ class PaymentLibrariesSeeder extends Seeder ['name' => 'US Dollar', 'code' => 'USD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Pound Sterling', 'code' => 'GBP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Euro', 'code' => 'EUR', 'symbol' => '€', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], - ['name' => 'Rand', 'code' => 'ZAR', 'symbol' => 'R', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['name' => 'South African Rand', 'code' => 'ZAR', 'symbol' => 'R', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Danish Krone', 'code' => 'DKK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Israeli Shekel', 'code' => 'ILS', 'symbol' => 'NIS ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Swedish Krona', 'code' => 'SEK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], @@ -82,10 +82,16 @@ class PaymentLibrariesSeeder extends Seeder ['name' => 'Malaysian Ringgit', 'code' => 'MYR', 'symbol' => 'RM', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Brazilian Real', 'code' => 'BRL', 'symbol' => 'R$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Thai baht', 'code' => 'THB', 'symbol' => 'THB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['name' => 'Nigerian Naira', 'code' => 'NGN', 'symbol' => 'NGN ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['name' => 'Argentine Peso', 'code' => 'ARS', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ]; foreach ($currencies as $currency) { - if (!DB::table('currencies')->whereName($currency['name'])->get()) { + $record = Currency::whereCode($currency['code'])->first(); + if ($record) { + $record->name = $currency['name']; + $record->save(); + } else { Currency::create($currency); } }