diff --git a/.env.example b/.env.example index 4ca1bb2d3422..c955b9de3a71 100644 --- a/.env.example +++ b/.env.example @@ -21,5 +21,8 @@ MAIL_FROM_NAME MAIL_PASSWORD PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address' +LOG=single -LOG=single \ No newline at end of file +GOOGLE_CLIENT_ID +GOOGLE_CLIENT_SECRET +GOOGLE_OAUTH_REDIRECT=http://ninja.dev/auth/google \ No newline at end of file diff --git a/app/Commands/Command.php b/app/Commands/Command.php index 018bc2192435..5bc48501167e 100644 --- a/app/Commands/Command.php +++ b/app/Commands/Command.php @@ -1,7 +1,6 @@ -where('client_id', '=', $client->id) ->orderBy('activities.id') - ->get(['activities.id', 'activities.created_at', 'activities.activity_type_id', 'activities.message', 'activities.adjustment', 'activities.balance', 'activities.invoice_id']); + ->get(['activities.id', 'activities.created_at', 'activities.activity_type_id', 'activities.adjustment', 'activities.balance', 'activities.invoice_id']); //$this->info(var_dump($activities)); foreach ($activities as $activity) { @@ -235,7 +235,6 @@ class CheckData extends Command { 'updated_at' => new Carbon, 'account_id' => $client->account_id, 'client_id' => $client->id, - 'message' => 'Corrected client balance', 'adjustment' => $client->actual_balance - $activity->balance, 'balance' => $client->actual_balance, ]); diff --git a/app/Console/Commands/CreateRandomData.php b/app/Console/Commands/CreateRandomData.php deleted file mode 100644 index de4da39cbe71..000000000000 --- a/app/Console/Commands/CreateRandomData.php +++ /dev/null @@ -1,88 +0,0 @@ -info(date('Y-m-d') . ' Running CreateRandomData...'); - - $user = User::first(); - - if (!$user) { - $this->error("Error: please create user account by logging in"); - return; - } - - $productNames = ['Arkansas', 'New York', 'Arizona', 'California', 'Colorado', 'Alabama', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'Alaska', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; - $clientNames = ['IBM', 'Nestle', 'Mitsubishi UFJ Financial', 'Vodafone', 'Eni', 'Procter & Gamble', 'Johnson & Johnson', 'American International Group', 'Banco Santander', 'BHP Billiton', 'Pfizer', 'Itaú Unibanco Holding', 'Ford Motor', 'BMW Group', 'Commonwealth Bank', 'EDF', 'Statoil', 'Google', 'Siemens', 'Novartis', 'Royal Bank of Canada', 'Sumitomo Mitsui Financial', 'Comcast', 'Sberbank', 'Goldman Sachs Group', 'Westpac Banking Group', 'Nippon Telegraph & Tel', 'Ping An Insurance Group', 'Banco Bradesco', 'Anheuser-Busch InBev', 'Bank of Communications', 'China Life Insurance', 'General Motors', 'Telefónica', 'MetLife', 'Honda Motor', 'Enel', 'BASF', 'Softbank', 'National Australia Bank', 'ANZ', 'ConocoPhillips', 'TD Bank Group', 'Intel', 'UBS', 'Hewlett-Packard', 'Coca-Cola', 'Cisco Systems', 'UnitedHealth Group', 'Boeing', 'Zurich Insurance Group', 'Hyundai Motor', 'Sanofi', 'Credit Agricole', 'United Technologies', 'Roche Holding', 'Munich Re', 'PepsiCo', 'Oracle', 'Bank of Nova Scotia']; - - foreach ($productNames as $i => $value) { - $product = Product::createNew($user); - $product->id = $i+1; - $product->product_key = $value; - $product->save(); - } - - foreach ($clientNames as $i => $value) { - $client = Client::createNew($user); - $client->name = $value; - $client->save(); - - $contact = Contact::createNew($user); - $contact->email = "client@aol.com"; - $contact->is_primary = 1; - $client->contacts()->save($contact); - - $numInvoices = rand(1, 25); - if ($numInvoices == 4 || $numInvoices == 10 || $numInvoices == 25) { - // leave these - } else if ($numInvoices % 3 == 0) { - $numInvoices = 1; - } else if ($numInvoices > 10) { - $numInvoices = $numInvoices % 2; - } - - $paidUp = rand(0, 1) == 1; - - for ($j=1; $j<=$numInvoices; $j++) { - - $price = rand(10, 1000); - if ($price < 900) { - $price = rand(10, 150); - } - - $invoice = Invoice::createNew($user); - $invoice->invoice_number = $user->account->getNextInvoiceNumber($invoice); - $invoice->amount = $invoice->balance = $price; - $invoice->created_at = date('Y-m-d', strtotime(date("Y-m-d") . ' - ' . rand(1, 100) . ' days')); - $client->invoices()->save($invoice); - - $productId = rand(0, 40); - if ($productId > 20) { - $productId = ($productId % 2) + rand(0, 2); - } - - $invoiceItem = InvoiceItem::createNew($user); - $invoiceItem->product_id = $productId+1; - $invoiceItem->product_key = $productNames[$invoiceItem->product_id]; - $invoiceItem->cost = $invoice->amount; - $invoiceItem->qty = 1; - $invoice->invoice_items()->save($invoiceItem); - - if ($paidUp || rand(0,2) > 1) { - $payment = Payment::createNew($user); - $payment->invoice_id = $invoice->id; - $payment->amount = $invoice->amount; - $client->payments()->save($payment); - } - } - } - } -} \ No newline at end of file diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fd97865beadc..03b6ce776484 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,7 +13,6 @@ class Kernel extends ConsoleKernel */ protected $commands = [ 'App\Console\Commands\SendRecurringInvoices', - 'App\Console\Commands\CreateRandomData', 'App\Console\Commands\ResetData', 'App\Console\Commands\CheckData', 'App\Console\Commands\SendRenewalInvoices', diff --git a/app/Events/ClientWasArchived.php b/app/Events/ClientWasArchived.php new file mode 100644 index 000000000000..03ebdc09cd18 --- /dev/null +++ b/app/Events/ClientWasArchived.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/app/Events/ClientWasCreated.php b/app/Events/ClientWasCreated.php new file mode 100644 index 000000000000..5c2d3700172b --- /dev/null +++ b/app/Events/ClientWasCreated.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/app/Events/ClientWasDeleted.php b/app/Events/ClientWasDeleted.php new file mode 100644 index 000000000000..b87063c4979d --- /dev/null +++ b/app/Events/ClientWasDeleted.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/app/Events/ClientWasRestored.php b/app/Events/ClientWasRestored.php new file mode 100644 index 000000000000..385a0472ab4c --- /dev/null +++ b/app/Events/ClientWasRestored.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/app/Events/ClientWasUpdated.php b/app/Events/ClientWasUpdated.php new file mode 100644 index 000000000000..7e4790da6885 --- /dev/null +++ b/app/Events/ClientWasUpdated.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/app/Events/CreditWasArchived.php b/app/Events/CreditWasArchived.php new file mode 100644 index 000000000000..2c680905b33a --- /dev/null +++ b/app/Events/CreditWasArchived.php @@ -0,0 +1,23 @@ +credit = $credit; + } + +} diff --git a/app/Events/CreditWasCreated.php b/app/Events/CreditWasCreated.php new file mode 100644 index 000000000000..bc20b312dc5f --- /dev/null +++ b/app/Events/CreditWasCreated.php @@ -0,0 +1,23 @@ +credit = $credit; + } + +} diff --git a/app/Events/CreditWasDeleted.php b/app/Events/CreditWasDeleted.php new file mode 100644 index 000000000000..e26a5d3ab053 --- /dev/null +++ b/app/Events/CreditWasDeleted.php @@ -0,0 +1,23 @@ +credit = $credit; + } + +} diff --git a/app/Events/CreditWasRestored.php b/app/Events/CreditWasRestored.php new file mode 100644 index 000000000000..8d17d961e7ff --- /dev/null +++ b/app/Events/CreditWasRestored.php @@ -0,0 +1,23 @@ +credit = $credit; + } + +} diff --git a/app/Events/InvoiceInvitationWasEmailed.php b/app/Events/InvoiceInvitationWasEmailed.php new file mode 100644 index 000000000000..da0031249217 --- /dev/null +++ b/app/Events/InvoiceInvitationWasEmailed.php @@ -0,0 +1,23 @@ +invitation = $invitation; + } + +} diff --git a/app/Events/InvoiceInvitationWasViewed.php b/app/Events/InvoiceInvitationWasViewed.php new file mode 100644 index 000000000000..bbf7e23c3353 --- /dev/null +++ b/app/Events/InvoiceInvitationWasViewed.php @@ -0,0 +1,25 @@ +invoice = $invoice; + $this->invitation = $invitation; + } + +} diff --git a/app/Events/InvoiceWasArchived.php b/app/Events/InvoiceWasArchived.php new file mode 100644 index 000000000000..7587c071a66e --- /dev/null +++ b/app/Events/InvoiceWasArchived.php @@ -0,0 +1,22 @@ +invoice = $invoice; + } + +} diff --git a/app/Events/InvoiceSent.php b/app/Events/InvoiceWasCreated.php similarity index 88% rename from app/Events/InvoiceSent.php rename to app/Events/InvoiceWasCreated.php index cbe08d0528f3..cfd943bcffbf 100644 --- a/app/Events/InvoiceSent.php +++ b/app/Events/InvoiceWasCreated.php @@ -4,10 +4,9 @@ use App\Events\Event; use Illuminate\Queue\SerializesModels; -class InvoiceSent extends Event { +class InvoiceWasCreated extends Event { use SerializesModels; - public $invoice; /** diff --git a/app/Events/InvoiceViewed.php b/app/Events/InvoiceWasDeleted.php similarity index 61% rename from app/Events/InvoiceViewed.php rename to app/Events/InvoiceWasDeleted.php index 8d9f129e764a..316b1b5c5001 100644 --- a/app/Events/InvoiceViewed.php +++ b/app/Events/InvoiceWasDeleted.php @@ -4,10 +4,9 @@ use App\Events\Event; use Illuminate\Queue\SerializesModels; -class InvoiceViewed extends Event { +class InvoiceWasDeleted extends Event { use SerializesModels; - public $invoice; /** @@ -15,9 +14,9 @@ class InvoiceViewed extends Event { * * @return void */ - public function __construct($invoice) - { - $this->invoice = $invoice; - } + public function __construct($invoice) + { + $this->invoice = $invoice; + } } diff --git a/app/Events/InvoiceWasEmailed.php b/app/Events/InvoiceWasEmailed.php new file mode 100644 index 000000000000..dc30f6a55869 --- /dev/null +++ b/app/Events/InvoiceWasEmailed.php @@ -0,0 +1,22 @@ +invoice = $invoice; + } + +} diff --git a/app/Events/InvoiceWasRestored.php b/app/Events/InvoiceWasRestored.php new file mode 100644 index 000000000000..5d75b4b246b4 --- /dev/null +++ b/app/Events/InvoiceWasRestored.php @@ -0,0 +1,25 @@ +invoice = $invoice; + $this->fromDeleted = $fromDeleted; + } + +} diff --git a/app/Events/QuoteApproved.php b/app/Events/InvoiceWasUpdated.php similarity index 87% rename from app/Events/QuoteApproved.php rename to app/Events/InvoiceWasUpdated.php index 12b5384b35e3..87a0f8f20136 100644 --- a/app/Events/QuoteApproved.php +++ b/app/Events/InvoiceWasUpdated.php @@ -4,10 +4,9 @@ use App\Events\Event; use Illuminate\Queue\SerializesModels; -class QuoteApproved extends Event { +class InvoiceWasUpdated extends Event { use SerializesModels; - public $invoice; /** diff --git a/app/Events/InvoicePaid.php b/app/Events/PaymentWasArchived.php similarity index 87% rename from app/Events/InvoicePaid.php rename to app/Events/PaymentWasArchived.php index 4dced73471a0..b8bb693dfc78 100644 --- a/app/Events/InvoicePaid.php +++ b/app/Events/PaymentWasArchived.php @@ -4,10 +4,9 @@ use App\Events\Event; use Illuminate\Queue\SerializesModels; -class InvoicePaid extends Event { +class PaymentWasArchived extends Event { use SerializesModels; - public $payment; /** diff --git a/app/Events/PaymentWasCreated.php b/app/Events/PaymentWasCreated.php new file mode 100644 index 000000000000..619d33e95890 --- /dev/null +++ b/app/Events/PaymentWasCreated.php @@ -0,0 +1,22 @@ +payment = $payment; + } + +} diff --git a/app/Events/PaymentWasDeleted.php b/app/Events/PaymentWasDeleted.php new file mode 100644 index 000000000000..e12647c86011 --- /dev/null +++ b/app/Events/PaymentWasDeleted.php @@ -0,0 +1,22 @@ +payment = $payment; + } + +} diff --git a/app/Events/PaymentWasRestored.php b/app/Events/PaymentWasRestored.php new file mode 100644 index 000000000000..711bdbb67fa5 --- /dev/null +++ b/app/Events/PaymentWasRestored.php @@ -0,0 +1,25 @@ +payment = $payment; + $this->fromDeleted = $fromDeleted; + } + +} diff --git a/app/Events/QuoteInvitationWasApproved.php b/app/Events/QuoteInvitationWasApproved.php new file mode 100644 index 000000000000..954aa83b4cf2 --- /dev/null +++ b/app/Events/QuoteInvitationWasApproved.php @@ -0,0 +1,25 @@ +quote = $quote; + $this->invitation = $invitation; + } + +} diff --git a/app/Events/QuoteInvitationWasEmailed.php b/app/Events/QuoteInvitationWasEmailed.php new file mode 100644 index 000000000000..5ce1c68602fb --- /dev/null +++ b/app/Events/QuoteInvitationWasEmailed.php @@ -0,0 +1,23 @@ +invitation = $invitation; + } + +} diff --git a/app/Events/QuoteInvitationWasViewed.php b/app/Events/QuoteInvitationWasViewed.php new file mode 100644 index 000000000000..3cd84b0e1189 --- /dev/null +++ b/app/Events/QuoteInvitationWasViewed.php @@ -0,0 +1,25 @@ +quote = $quote; + $this->invitation = $invitation; + } + +} diff --git a/app/Events/QuoteWasArchived.php b/app/Events/QuoteWasArchived.php new file mode 100644 index 000000000000..285a61250c04 --- /dev/null +++ b/app/Events/QuoteWasArchived.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Events/QuoteWasCreated.php b/app/Events/QuoteWasCreated.php new file mode 100644 index 000000000000..d17ef9c1318c --- /dev/null +++ b/app/Events/QuoteWasCreated.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Events/QuoteWasDeleted.php b/app/Events/QuoteWasDeleted.php new file mode 100644 index 000000000000..ce3685d7a212 --- /dev/null +++ b/app/Events/QuoteWasDeleted.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Events/QuoteWasEmailed.php b/app/Events/QuoteWasEmailed.php new file mode 100644 index 000000000000..19b1ec12d6a5 --- /dev/null +++ b/app/Events/QuoteWasEmailed.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Events/QuoteWasRestored.php b/app/Events/QuoteWasRestored.php new file mode 100644 index 000000000000..0f13a65b437e --- /dev/null +++ b/app/Events/QuoteWasRestored.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Events/QuoteWasUpdated.php b/app/Events/QuoteWasUpdated.php new file mode 100644 index 000000000000..f01b9822601f --- /dev/null +++ b/app/Events/QuoteWasUpdated.php @@ -0,0 +1,22 @@ +quote = $quote; + } + +} diff --git a/app/Http/Controllers/AccountApiController.php b/app/Http/Controllers/AccountApiController.php new file mode 100644 index 000000000000..a2154ac53fe2 --- /dev/null +++ b/app/Http/Controllers/AccountApiController.php @@ -0,0 +1,40 @@ +accountRepo = $accountRepo; + } + + public function index() + { + $manager = new Manager(); + $manager->setSerializer(new ArraySerializer()); + + $account = Auth::user()->account->load('users'); + $resource = new Item($account, new AccountTransformer, 'account'); + + $response = $manager->createData($resource)->toArray(); + $response = json_encode($response, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(); + + return Response::make($response, 200, $headers); + } +} diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d4a358ebcfc9..2b6fc33216bb 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -38,6 +38,7 @@ use App\Models\Industry; use App\Models\InvoiceDesign; use App\Models\TaxRate; use App\Ninja\Repositories\AccountRepository; +use App\Ninja\Repositories\ReferralRepository; use App\Ninja\Mailers\UserMailer; use App\Ninja\Mailers\ContactMailer; use App\Events\UserSignedUp; @@ -45,19 +46,23 @@ use App\Events\UserLoggedIn; use App\Events\UserSettingsChanged; use App\Services\AuthService; +use App\Commands\CreateClient; + class AccountController extends BaseController { protected $accountRepo; protected $userMailer; protected $contactMailer; + protected $referralRepository; - public function __construct(AccountRepository $accountRepo, UserMailer $userMailer, ContactMailer $contactMailer) + public function __construct(AccountRepository $accountRepo, UserMailer $userMailer, ContactMailer $contactMailer, ReferralRepository $referralRepository) { parent::__construct(); $this->accountRepo = $accountRepo; $this->userMailer = $userMailer; $this->contactMailer = $contactMailer; + $this->referralRepository = $referralRepository; } public function demo() @@ -221,13 +226,14 @@ class AccountController extends BaseController foreach (AuthService::$providers as $provider) { $oauthLoginUrls[] = ['label' => $provider, 'url' => '/auth/' . strtolower($provider)]; } - + $data = [ 'account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'title' => trans('texts.user_details'), 'user' => Auth::user(), 'oauthProviderName' => AuthService::getProviderName(Auth::user()->oauth_provider_id), 'oauthLoginUrls' => $oauthLoginUrls, + 'referralCounts' => $this->referralRepository->getCounts(Auth::user()->id), ]; return View::make('accounts.user_details', $data); @@ -519,8 +525,10 @@ class AccountController extends BaseController $account->invoice_number_counter = Input::get('invoice_number_counter'); $account->quote_number_prefix = Input::get('quote_number_prefix'); $account->share_counter = Input::get('share_counter') ? true : false; - $account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false; + $account->invoice_terms = Input::get('invoice_terms'); + $account->invoice_footer = Input::get('invoice_footer'); + $account->quote_terms = Input::get('quote_terms'); if (Input::has('recurring_hour')) { $account->recurring_hour = Input::get('recurring_hour'); @@ -637,49 +645,56 @@ class AccountController extends BaseController continue; } - $client = Client::createNew(); - $contact = Contact::createNew(); - $contact->is_primary = true; - $contact->send_invoice = true; - $count++; + $data = [ + 'contacts' => [[]] + ]; foreach ($row as $index => $value) { $field = $map[$index]; - $value = trim($value); + if ( ! $value = trim($value)) { + continue; + } - if ($field == Client::$fieldName && !$client->name) { - $client->name = $value; - } elseif ($field == Client::$fieldPhone && !$client->work_phone) { - $client->work_phone = $value; - } elseif ($field == Client::$fieldAddress1 && !$client->address1) { - $client->address1 = $value; - } elseif ($field == Client::$fieldAddress2 && !$client->address2) { - $client->address2 = $value; - } elseif ($field == Client::$fieldCity && !$client->city) { - $client->city = $value; - } elseif ($field == Client::$fieldState && !$client->state) { - $client->state = $value; - } elseif ($field == Client::$fieldPostalCode && !$client->postal_code) { - $client->postal_code = $value; - } elseif ($field == Client::$fieldCountry && !$client->country_id) { + if ($field == Client::$fieldName) { + $data['name'] = $value; + } elseif ($field == Client::$fieldPhone) { + $data['work_phone'] = $value; + } elseif ($field == Client::$fieldAddress1) { + $data['address1'] = $value; + } elseif ($field == Client::$fieldAddress2) { + $data['address2'] = $value; + } elseif ($field == Client::$fieldCity) { + $data['city'] = $value; + } elseif ($field == Client::$fieldState) { + $data['state'] = $value; + } elseif ($field == Client::$fieldPostalCode) { + $data['postal_code'] = $value; + } elseif ($field == Client::$fieldCountry) { $value = strtolower($value); - $client->country_id = isset($countryMap[$value]) ? $countryMap[$value] : null; - } elseif ($field == Client::$fieldNotes && !$client->private_notes) { - $client->private_notes = $value; - } elseif ($field == Contact::$fieldFirstName && !$contact->first_name) { - $contact->first_name = $value; - } elseif ($field == Contact::$fieldLastName && !$contact->last_name) { - $contact->last_name = $value; - } elseif ($field == Contact::$fieldPhone && !$contact->phone) { - $contact->phone = $value; - } elseif ($field == Contact::$fieldEmail && !$contact->email) { - $contact->email = strtolower($value); + $data['country_id'] = isset($countryMap[$value]) ? $countryMap[$value] : null; + } elseif ($field == Client::$fieldNotes) { + $data['private_notes'] = $value; + } elseif ($field == Contact::$fieldFirstName) { + $data['contacts'][0]['first_name'] = $value; + } elseif ($field == Contact::$fieldLastName) { + $data['contacts'][0]['last_name'] = $value; + } elseif ($field == Contact::$fieldPhone) { + $data['contacts'][0]['phone'] = $value; + } elseif ($field == Contact::$fieldEmail) { + $data['contacts'][0]['email'] = strtolower($value); } } - $client->save(); - $client->contacts()->save($contact); - Activity::createClient($client, false); + $rules = [ + 'contacts' => 'valid_contacts', + ]; + $validator = Validator::make($data, $rules); + if ($validator->fails()) { + continue; + } + + $this->dispatch(new CreateClient($data)); + $count++; } $message = Utils::pluralize('created_client', $count); @@ -792,12 +807,6 @@ class AccountController extends BaseController private function saveNotifications() { - $account = Auth::user()->account; - $account->invoice_terms = Input::get('invoice_terms'); - $account->invoice_footer = Input::get('invoice_footer'); - $account->email_footer = Input::get('email_footer'); - $account->save(); - $user = Auth::user(); $user->notify_sent = Input::get('notify_sent'); $user->notify_viewed = Input::get('notify_viewed'); @@ -838,6 +847,7 @@ class AccountController extends BaseController $account->country_id = Input::get('country_id') ? Input::get('country_id') : null; $account->size_id = Input::get('size_id') ? Input::get('size_id') : null; $account->industry_id = Input::get('industry_id') ? Input::get('industry_id') : null; + $account->email_footer = Input::get('email_footer'); $account->save(); /* Logo image file */ diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index e448f5bdb5be..9f190bbf26f5 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -60,20 +60,17 @@ class AccountGatewayController extends BaseController public function edit($publicId) { $accountGateway = AccountGateway::scope($publicId)->firstOrFail(); - $config = $accountGateway->config; - $selectedCards = $accountGateway->accepted_credit_cards; - - $configFields = json_decode($config); - - foreach ($configFields as $configField => $value) { - $configFields->$configField = str_repeat('*', strlen($value)); + $config = $accountGateway->getConfig(); + + foreach ($config as $field => $value) { + $config->$field = str_repeat('*', strlen($value)); } $data = self::getViewModel($accountGateway); $data['url'] = 'gateways/'.$publicId; $data['method'] = 'PUT'; $data['title'] = trans('texts.edit_gateway') . ' - ' . $accountGateway->gateway->name; - $data['config'] = $configFields; + $data['config'] = $config; $data['hiddenFields'] = Gateway::$hiddenFields; $data['paymentTypeId'] = $accountGateway->getPaymentType(); $data['selectGateways'] = Gateway::where('id', '=', $accountGateway->gateway_id)->get(); @@ -237,7 +234,7 @@ class AccountGatewayController extends BaseController if ($accountGatewayPublicId) { $accountGateway = AccountGateway::scope($accountGatewayPublicId)->firstOrFail(); - $oldConfig = json_decode($accountGateway->config); + $oldConfig = $accountGateway->getConfig(); } else { $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = $gatewayId; @@ -267,7 +264,7 @@ class AccountGatewayController extends BaseController $accountGateway->accepted_credit_cards = $cardCount; $accountGateway->show_address = Input::get('show_address') ? true : false; $accountGateway->update_address = Input::get('update_address') ? true : false; - $accountGateway->config = json_encode($config); + $accountGateway->setConfig($config); if ($accountGatewayPublicId) { $accountGateway->save(); diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 39419f227df6..02700e23301d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -5,20 +5,46 @@ use DB; use Datatable; use Utils; use View; +use App\Models\Client; +use App\Models\Activity; +use App\Ninja\Repositories\ActivityRepository; class ActivityController extends BaseController { + protected $activityRepo; + + public function __construct(ActivityRepository $activityRepo) + { + parent::__construct(); + + $this->activityRepo = $activityRepo; + } + public function getDatatable($clientPublicId) { - $query = DB::table('activities') - ->join('clients', 'clients.id', '=', 'activities.client_id') - ->where('clients.public_id', '=', $clientPublicId) - ->where('activities.account_id', '=', Auth::user()->account_id) - ->select('activities.id', 'activities.message', 'activities.created_at', 'clients.currency_id', 'activities.balance', 'activities.adjustment'); + $clientId = Client::getPrivateId($clientPublicId); + + if ( ! $clientId) { + app()->abort(404); + } + + $query = $this->activityRepo->findByClientId($clientId); return Datatable::query($query) ->addColumn('activities.id', function ($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) - ->addColumn('message', function ($model) { return Utils::decodeActivity($model->message); }) + ->addColumn('activity_type_id', function ($model) { + $data = [ + 'client' => link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)), + 'user' => $model->is_system ? '' . trans('texts.system') . '' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), + 'invoice' => $model->invoice ? link_to('/invoices/' . $model->invoice_public_id, $model->is_recurring ? trans('texts.recurring_invoice') : $model->invoice) : null, + 'quote' => $model->invoice ? link_to('/quotes/' . $model->invoice_public_id, $model->invoice) : null, + 'contact' => $model->contact_id ? link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)) : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), + 'payment' => $model->payment ?: '', + 'credit' => Utils::formatMoney($model->credit, $model->currency_id) + ]; + + return trans("texts.activity_{$model->activity_type_id}", $data); + }) ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) ->addColumn('adjustment', function ($model) { return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id) : ''; }) ->make(); diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index ae5a7a1256a7..8c3b9b5fe59f 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -189,6 +189,7 @@ class AppController extends BaseController Artisan::call('db:seed', array('--force' => true, '--class' => 'PaymentLibrariesSeeder')); Artisan::call('optimize', array('--force' => true)); Cache::flush(); + Session::flush(); Event::fire(new UserSettingsChanged()); Session::flash('message', trans('texts.processed_updates')); } catch (Exception $e) { diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index 6c732cf15dee..14ef9cf8b446 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -97,8 +97,14 @@ class AuthController extends Controller { } else { $users = $this->accountRepo->loadAccounts(Auth::user()->id); } - Session::put(SESSION_USER_ACCOUNTS, $users); + + if ($request->create_token) { + if ( ! env(API_SECRET) || $request->api_secret !== env(API_SECRET)) { + return 'Invalid secret'; + } + return $this->accountRepo->createToken($request->token_name); + } } elseif ($user) { $user->failed_logins = $user->failed_logins + 1; $user->save(); diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 0cc63c7c5a1a..1a2f6c8dc526 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -1,7 +1,11 @@ clientRepo->getErrors($data); + $client = $this->clientRepo->save($request->input()); - if ($error) { - $headers = Utils::getApiHeaders(); + $client = Client::scope($client->public_id)->with('country', 'contacts', 'industry', 'size', 'currency')->first(); + $client = Utils::remapPublicIds([$client]); + $response = json_encode($client, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(); - return Response::make($error, 500, $headers); - } else { - $client = $this->clientRepo->save(isset($data['id']) ? $data['id'] : false, $data, false); - $client = Client::scope($client->public_id)->with('country', 'contacts', 'industry', 'size', 'currency')->first(); - $client = Utils::remapPublicIds([$client]); - $response = json_encode($client, JSON_PRETTY_PRINT); - $headers = Utils::getApiHeaders(); - - return Response::make($response, 200, $headers); - } + return Response::make($response, 200, $headers); } } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 6b168751cb59..c5ed7e5b4154 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -21,18 +21,23 @@ use App\Models\Industry; use App\Models\Currency; use App\Models\Country; use App\Models\Task; - use App\Ninja\Repositories\ClientRepository; +use App\Services\ClientService; + +use App\Http\Requests\CreateClientRequest; +use App\Http\Requests\UpdateClientRequest; class ClientController extends BaseController { + protected $clientService; protected $clientRepo; - public function __construct(ClientRepository $clientRepo) + public function __construct(ClientRepository $clientRepo, ClientService $clientService) { parent::__construct(); $this->clientRepo = $clientRepo; + $this->clientService = $clientService; } /** @@ -63,9 +68,6 @@ class ClientController extends BaseController ->addColumn('last_login', function ($model) { return Utils::timestampToDateString(strtotime($model->last_login)); }) ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) ->addColumn('dropdown', function ($model) { - if ($model->is_deleted) { - return '
'; - } $str = ''; + } + + return $str.'
  • '.trans('texts.delete_client').'
  • '; }) ->make(); @@ -103,9 +109,13 @@ class ClientController extends BaseController * * @return Response */ - public function store() + public function store(CreateClientRequest $request) { - return $this->save(); + $client = $this->clientService->save($request->input()); + + Session::flash('message', trans('texts.created_client')); + + return redirect()->to($client->getRoute()); } /** @@ -194,6 +204,7 @@ class ClientController extends BaseController private static function getViewModel() { return [ + 'data' => Input::old('data'), 'account' => Auth::user()->account, 'sizes' => Cache::get('sizes'), 'paymentTerms' => Cache::get('paymentTerms'), @@ -212,105 +223,20 @@ class ClientController extends BaseController * @param int $id * @return Response */ - public function update($publicId) + public function update(UpdateClientRequest $request) { - return $this->save($publicId); - } - - private function save($publicId = null) - { - $rules = array( - 'email' => 'email|required_without:first_name', - 'first_name' => 'required_without:email', - ); - $validator = Validator::make(Input::all(), $rules); - - if ($validator->fails()) { - $url = $publicId ? 'clients/'.$publicId.'/edit' : 'clients/create'; - - return Redirect::to($url) - ->withErrors($validator) - ->withInput(Input::except('password')); - } else { - if ($publicId) { - $client = Client::scope($publicId)->firstOrFail(); - } else { - $client = Client::createNew(); - } - - $client->name = trim(Input::get('name')); - $client->id_number = trim(Input::get('id_number')); - $client->vat_number = trim(Input::get('vat_number')); - $client->work_phone = trim(Input::get('work_phone')); - $client->custom_value1 = trim(Input::get('custom_value1')); - $client->custom_value2 = trim(Input::get('custom_value2')); - $client->address1 = trim(Input::get('address1')); - $client->address2 = trim(Input::get('address2')); - $client->city = trim(Input::get('city')); - $client->state = trim(Input::get('state')); - $client->postal_code = trim(Input::get('postal_code')); - $client->country_id = Input::get('country_id') ?: null; - $client->private_notes = trim(Input::get('private_notes')); - $client->size_id = Input::get('size_id') ?: null; - $client->industry_id = Input::get('industry_id') ?: null; - $client->currency_id = Input::get('currency_id') ?: null; - $client->language_id = Input::get('language_id') ?: null; - $client->payment_terms = Input::get('payment_terms') ?: 0; - $client->website = trim(Input::get('website')); - - if (Input::has('invoice_number_counter')) { - $client->invoice_number_counter = (int) Input::get('invoice_number_counter'); - } - if (Input::has('quote_number_counter')) { - $client->invoice_number_counter = (int) Input::get('quote_number_counter'); - } - - $client->save(); - - $data = json_decode(Input::get('data')); - $contactIds = []; - $isPrimary = true; - - foreach ($data->contacts as $contact) { - if (isset($contact->public_id) && $contact->public_id) { - $record = Contact::scope($contact->public_id)->firstOrFail(); - } else { - $record = Contact::createNew(); - } - - $record->email = trim($contact->email); - $record->first_name = trim($contact->first_name); - $record->last_name = trim($contact->last_name); - $record->phone = trim($contact->phone); - $record->is_primary = $isPrimary; - $isPrimary = false; - - $client->contacts()->save($record); - $contactIds[] = $record->public_id; - } - - foreach ($client->contacts as $contact) { - if (!in_array($contact->public_id, $contactIds)) { - $contact->delete(); - } - } - - if ($publicId) { - Session::flash('message', trans('texts.updated_client')); - } else { - Activity::createClient($client); - Session::flash('message', trans('texts.created_client')); - } - - return Redirect::to('clients/'.$client->public_id); - } + $client = $this->clientService->save($request->input()); + + Session::flash('message', trans('texts.updated_client')); + + return redirect()->to($client->getRoute()); } public function bulk() { $action = Input::get('action'); - $ids = Input::get('id') ? Input::get('id') : Input::get('ids'); - $count = $this->clientRepo->bulk($ids, $action); + $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); + $count = $this->clientService->bulk($ids, $action); $message = Utils::pluralize($action.'d_client', $count); Session::flash('message', $message); diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 505400718caf..ad04651acfc9 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -8,18 +8,21 @@ use Utils; use View; use Validator; use App\Models\Client; - +use App\Services\CreditService; use App\Ninja\Repositories\CreditRepository; +use App\Http\Requests\CreateCreditRequest; class CreditController extends BaseController { protected $creditRepo; + protected $CreditService; - public function __construct(CreditRepository $creditRepo) + public function __construct(CreditRepository $creditRepo, CreditService $creditService) { parent::__construct(); $this->creditRepo = $creditRepo; + $this->creditService = $creditService; } /** @@ -106,46 +109,20 @@ class CreditController extends BaseController return View::make('credit.edit', $data); } - public function store() + public function store(CreateCreditRequest $request) { - return $this->save(); - } - - public function update($publicId) - { - return $this->save($publicId); - } - - private function save($publicId = null) - { - $rules = array( - 'client' => 'required', - 'amount' => 'required|positive', - ); - - $validator = Validator::make(Input::all(), $rules); - - if ($validator->fails()) { - $url = $publicId ? 'credits/'.$publicId.'/edit' : 'credits/create'; - - return Redirect::to($url) - ->withErrors($validator) - ->withInput(); - } else { - $this->creditRepo->save($publicId, Input::all()); - - $message = trans('texts.created_credit'); - Session::flash('message', $message); - - return Redirect::to('clients/'.Input::get('client')); - } + $credit = $this->creditRepo->save($request->input()); + + Session::flash('message', trans('texts.created_credit')); + + return redirect()->to($credit->client->getRoute()); } public function bulk() { $action = Input::get('action'); - $ids = Input::get('id') ? Input::get('id') : Input::get('ids'); - $count = $this->creditRepo->bulk($ids, $action); + $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); + $count = $this->creditService->bulk($ids, $action); if ($count > 0) { $message = Utils::pluralize($action.'d_credit', $count); diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 0b72d3669114..a8b31fdb8ab0 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -62,6 +62,7 @@ class DashboardController extends BaseController ->get(); $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id) + ->with('client.contacts', 'user', 'invoice', 'payment', 'credit') ->where('activity_type_id', '>', 0) ->orderBy('created_at', 'desc') ->take(50) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index d3bb9b44bfec..2a9bae80eab8 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -58,7 +58,11 @@ class InvoiceApiController extends Controller { $data = Input::all(); $error = null; - + + if (isset($data['id']) || isset($data['public_id'])) { + die("We don't yet support updating invoices"); + } + if (isset($data['email'])) { $client = Client::scope()->whereHas('contacts', function($query) use ($data) { $query->where('email', '=', $data['email']); @@ -78,7 +82,7 @@ class InvoiceApiController extends Controller } $error = $this->clientRepo->getErrors($clientData); if (!$error) { - $client = $this->clientRepo->save(false, $clientData, false); + $client = $this->clientRepo->save($clientData); } } } else if (isset($data['client_id'])) { @@ -108,7 +112,7 @@ class InvoiceApiController extends Controller } else { $data = self::prepareData($data, $client); $data['client_id'] = $client->id; - $invoice = $this->invoiceRepo->save(false, $data, false); + $invoice = $this->invoiceRepo->save($data); if (!isset($data['id'])) { $invitation = Invitation::createNew(); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 54d74258c771..4f6aefdd46ff 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -14,7 +14,6 @@ use Datatable; use Request; use DropdownButton; use App\Models\Invoice; -use App\Models\Invitation; use App\Models\Client; use App\Models\Account; use App\Models\Product; @@ -31,21 +30,27 @@ use App\Models\Gateway; use App\Ninja\Mailers\ContactMailer as Mailer; use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\ClientRepository; -use App\Events\InvoiceViewed; +use App\Events\InvoiceInvitationWasViewed; +use App\Events\QuoteInvitationWasViewed; + +use App\Services\InvoiceService; +use App\Http\Requests\SaveInvoiceRequest; class InvoiceController extends BaseController { protected $mailer; protected $invoiceRepo; protected $clientRepo; + protected $invoiceService; - public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo) + public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService) { parent::__construct(); $this->mailer = $mailer; $this->invoiceRepo = $invoiceRepo; $this->clientRepo = $clientRepo; + $this->invoiceService = $invoiceService; } public function index() @@ -53,24 +58,20 @@ class InvoiceController extends BaseController $data = [ 'title' => trans('texts.invoices'), 'entityType' => ENTITY_INVOICE, - 'columns' => Utils::trans(['checkbox', 'invoice_number', 'client', 'invoice_date', 'invoice_total', 'balance_due', 'due_date', 'status', 'action']), + 'columns' => Utils::trans([ + 'checkbox', + 'invoice_number', + 'client', + 'invoice_date', + 'invoice_total', + 'balance_due', + 'due_date', + 'status', + 'action' + ]), ]; - $recurringInvoices = Invoice::scope()->where('is_recurring', '=', true); - - if (Session::get('show_trash:invoice')) { - $recurringInvoices->withTrashed(); - } else { - $recurringInvoices->join('clients', 'clients.id', '=', 'invoices.client_id') - ->where('clients.deleted_at', '=', null); - } - - if ($recurringInvoices->count() > 0) { - $data['secEntityType'] = ENTITY_RECURRING_INVOICE; - $data['secColumns'] = Utils::trans(['checkbox', 'frequency', 'client', 'start_date', 'end_date', 'invoice_total', 'action']); - } - - return View::make('list', $data); + return response()->view('list', $data); } public function getDatatable($clientPublicId = null) @@ -100,9 +101,6 @@ class InvoiceController extends BaseController ->addColumn('end_date', function ($model) { return Utils::fromSqlDate($model->end_date); }) ->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); }) ->addColumn('dropdown', function ($model) { - if ($model->is_deleted) { - return '
    '; - } $str = '
    -

    {!! trans('texts.custom_fields') !!}

    @@ -190,6 +189,46 @@
    +
    +
    +

    {!! trans('texts.default_messages') !!}

    +
    +
    + +
    + +
    +
    +
    +
    + {!! Former::textarea('invoice_terms') + ->label(trans('texts.default_invoice_terms')) + ->rows(4) !!} +
    +
    +
    +
    + {!! Former::textarea('invoice_footer') + ->label(trans('texts.default_invoice_footer')) + ->rows(4) !!} +
    +
    +
    +
    + {!! Former::textarea('quote_terms') + ->label(trans('texts.default_quote_terms')) + ->rows(4) !!} +
    +
    +
    +
    +
    + + @if (Auth::user()->isPro())
    diff --git a/resources/views/accounts/notifications.blade.php b/resources/views/accounts/notifications.blade.php index c92bf3fc7b04..2b1ebd4847d9 100644 --- a/resources/views/accounts/notifications.blade.php +++ b/resources/views/accounts/notifications.blade.php @@ -48,20 +48,7 @@ --> - -
    -
    -

    {!! trans('texts.custom_messages') !!}

    -
    -
    - {!! Former::textarea('invoice_terms')->label(trans('texts.default_invoice_terms'))->rows(4) - ->onchange("$('#invoice_terms').val(wordWrapText($('#invoice_terms').val(), 300))") !!} - {!! Former::textarea('invoice_footer')->label(trans('texts.default_invoice_footer'))->rows(4) - ->onchange("$('#invoice_footer').val(wordWrapText($('#invoice_footer').val(), 600))") !!} - {!! Former::textarea('email_footer')->label(trans('texts.default_email_footer'))->rows(4) !!} -
    -
    - + {!! Former::actions( Button::success(trans('texts.save')) ->submit()->large() diff --git a/resources/views/accounts/token.blade.php b/resources/views/accounts/token.blade.php index 6fd73ec2f1b4..8fc4a3b14efe 100644 --- a/resources/views/accounts/token.blade.php +++ b/resources/views/accounts/token.blade.php @@ -25,7 +25,7 @@ @if (Auth::user()->isPro()) {!! Former::actions( - Button::normal(trans('texts.cancel'))->asLinkTo(URL::to('/settings/token_management'))->appendIcon(Icon::create('remove-circle'))->large(), + Button::normal(trans('texts.cancel'))->asLinkTo(URL::to('/settings/api_tokens'))->appendIcon(Icon::create('remove-circle'))->large(), Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) ) !!} @else diff --git a/resources/views/accounts/user_details.blade.php b/resources/views/accounts/user_details.blade.php index 071b95cb9f65..2066e0d79aea 100644 --- a/resources/views/accounts/user_details.blade.php +++ b/resources/views/accounts/user_details.blade.php @@ -38,7 +38,7 @@
    - @if (Utils::isNinja()) + @if (Utils::isOAuthEnabled()) {!! Former::plaintext('oneclick_login')->value( $user->oauth_provider_id ? $oauthProviderName . ' - ' . link_to('#', trans('texts.disable'), ['onclick' => 'disableSocialLogin()']) : @@ -49,10 +49,14 @@ @if (Utils::isNinja()) @if ($user->referral_code) + {{ Former::setOption('capitalize_translations', false) }} {!! Former::plaintext('referral_code') - ->help(trans('texts.referral_code_help')) - ->value($user->referral_code . ' ' . Icon::create('question-sign') . '') !!} - @elseif (Input::has('affiliate')) + ->help(NINJA_APP_URL . '/invoice_now?rc=' . $user->referral_code) + ->value($user->referral_code . ' - '. + $referralCounts['free'] . ' ' . trans('texts.free') . ' | ' . + $referralCounts['pro'] . ' ' . trans('texts.pro') . ' ' . + '' . Icon::create('question-sign') . '') !!} + @else {!! Former::checkbox('referral_code') ->help(trans('texts.referral_code_help')) ->text(trans('texts.enable') . ' ' . Icon::create('question-sign') . '') !!} diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index bdda6f1b65dc..33e2d84addab 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -89,16 +89,16 @@ @if (Input::get('new_company') && Utils::allowNewAccounts())

    - {{ trans('texts.or') }} -

    {!! Button::primary(trans('texts.new_company'))->asLinkTo(URL::to('/invoice_now?new_company=true&sign_up=true'))->large()->submit()->block() !!}


    - @elseif (Utils::isNinja()) + @elseif (Utils::isOAuthEnabled())

    - {{ trans('texts.or') }} -

    @foreach (App\Services\AuthService::$providers as $provider) +
    +
    @endforeach @endif diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 1891cc6f7cb0..becbfbdd9572 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -1,4 +1,3 @@ - @extends('header') @@ -7,6 +6,11 @@ @stop @section('content') + +@if ($errors->first('contacts')) +
    {{ trans($errors->first('contacts')) }}
    +@endif +
    {!! Former::open($url) @@ -17,6 +21,7 @@ @if ($client) {!! Former::populate($client) !!} + {!! Former::hidden('public_id') !!} @endif
    @@ -75,11 +80,16 @@
    - {!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown'") !!} - {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown'") !!} - {!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown'") !!} - {!! Former::text('email')->data_bind('value: email, valueUpdate: \'afterkeydown\', attr: {id:\'email\'+$index()}') !!} - {!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown'") !!} + {!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown', + attr: {name: 'contacts[' + \$index() + '][public_id]'}") !!} + {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown', + attr: {name: 'contacts[' + \$index() + '][first_name]'}") !!} + {!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown', + attr: {name: 'contacts[' + \$index() + '][last_name]'}") !!} + {!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown', + attr: {name: 'contacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} + {!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown', + attr: {name: 'contacts[' + \$index() + '][phone]'}") !!}
    @@ -141,13 +151,14 @@ self.phone = ko.observable(''); if (data) { - ko.mapping.fromJS(data, {}, this); - } + ko.mapping.fromJS(data, {}, this); + } } - function ContactsModel(data) { + function ClientModel(data) { var self = this; - self.contacts = ko.observableArray(); + + self.contacts = ko.observableArray(); self.mapping = { 'contacts': { @@ -155,10 +166,10 @@ return new ContactModel(options.data); } } - } + } if (data) { - ko.mapping.fromJS(data, self.mapping, this); + ko.mapping.fromJS(data, self.mapping, this); } else { self.contacts.push(new ContactModel()); } @@ -174,7 +185,11 @@ }); } - window.model = new ContactsModel({!! $client !!}); + @if ($data) + window.model = new ClientModel({!! $data !!}); + @else + window.model = new ClientModel({!! $client !!}); + @endif model.showContact = function(elem) { if (elem.nodeType === 1) $(elem).hide().slideDown() } model.hideContact = function(elem) { if (elem.nodeType === 1) $(elem).slideUp(function() { $(elem).remove(); }) } diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index c04e1f383efa..bed5942c14c7 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -25,7 +25,7 @@ {!! Former::open('clients/bulk')->addClass('mainForm') !!}
    {!! Former::text('action') !!} - {!! Former::text('id')->value($client->public_id) !!} + {!! Former::text('public_id')->value($client->public_id) !!}
    @if ($gatewayLink) diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 247626bf623b..eaeef27e628f 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,5 +1,6 @@ @extends('header') + @section('content')
    @@ -80,7 +81,7 @@ @foreach ($activities as $activity)
  • {{ Utils::timestampToDateString(strtotime($activity->created_at)) }}: - {!! Utils::decodeActivity($activity->message) !!} + {!! $activity->getMessage() !!}
  • @endforeach @@ -250,11 +251,7 @@
    @endif - -
    -
    -
    -
    + -@stop - +@stop \ No newline at end of file diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index a196d84f5b51..b8d257752ed7 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -122,22 +122,25 @@ '&go_pro=' + $('#go_pro').val(), success: function(result) { if (result) { - localStorage.setItem('guest_key', ''); - fbq('track', 'CompleteRegistration'); - window._fbq.push(['track', '{{ env('FACEBOOK_PIXEL_SIGN_UP') }}', {'value':'0.00','currency':'USD'}]); - trackEvent('/account', '/signed_up'); + handleSignedUp(); NINJA.isRegistered = true; $('#signUpButton').hide(); - $('#myAccountButton').html(result); - } + $('#myAccountButton').html(result); + } $('#signUpSuccessDiv, #signUpFooter, #closeSignUpButton').show(); $('#working, #saveSignUpButton').hide(); } - }); - } - + }); + } @endif + function handleSignedUp() { + localStorage.setItem('guest_key', ''); + fbq('track', 'CompleteRegistration'); + window._fbq.push(['track', '{{ env('FACEBOOK_PIXEL_SIGN_UP') }}', {'value':'0.00','currency':'USD'}]); + trackEvent('/account', '/signed_up'); + } + function checkForEnter(event) { if (event.keyCode === 13){ @@ -245,7 +248,12 @@ } function setSignupEnabled(enabled) { - $('.signup-form input[type=text], .signup-form button').prop('disabled', !enabled); + $('.signup-form input[type=text]').prop('disabled', !enabled); + if (enabled) { + $('.signup-form a.btn').removeClass('disabled'); + } else { + $('.signup-form a.btn').addClass('disabled'); + } } function setSocialLoginProvider(provider) { @@ -550,7 +558,7 @@ {!! Former::checkbox('terms_checkbox')->label(' ')->text(trans('texts.agree_to_terms', ['terms' => ''.trans('texts.terms_of_service').'']))->raw() !!}
    - @if (Utils::isNinja()) + @if (Utils::isOAuthEnabled())

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


    @foreach (App\Services\AuthService::$providers as $provider) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index b9094cc6511d..864fd1ba648d 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -15,8 +15,7 @@ @stop @section('content') - - @if ($invoice->id) + @if ($invoice->id)