diff --git a/app/Http/Controllers/BotController.php b/app/Http/Controllers/BotController.php
index 365e48c07537..d58b5f577e38 100644
--- a/app/Http/Controllers/BotController.php
+++ b/app/Http/Controllers/BotController.php
@@ -100,6 +100,7 @@ class BotController extends Controller
public function handleCommand()
{
$data = $this->parseMessage(request()->command);
+ //dd($data);
$intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, false, $data);
return $intent->process();
diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php
index 18d562dfbedc..fea15293ab57 100644
--- a/app/Http/Controllers/InvoiceController.php
+++ b/app/Http/Controllers/InvoiceController.php
@@ -194,6 +194,7 @@ class InvoiceController extends BaseController
$invoice = $account->createInvoice($entityType, $clientId);
$invoice->public_id = 0;
+ $invoice->loadFromRequest();
$clients = Client::scope()->with('contacts', 'country')->orderBy('name');
if (! Auth::user()->hasPermission('view_all')) {
diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php
index 3cb8a052cc19..36220a53b1d2 100644
--- a/app/Models/EntityModel.php
+++ b/app/Models/EntityModel.php
@@ -319,6 +319,15 @@ class EntityModel extends Eloquent
return array_get($icons, $entityType);
}
+ public function loadFromRequest()
+ {
+ foreach (static::$requestFields as $field) {
+ if ($value = request()->$field) {
+ $this->$field = strpos($field, 'date') ? Utils::fromSqlDate($value) : $value;
+ }
+ }
+ }
+
// isDirty return true if the field's new value is the same as the old one
public function isChanged()
{
diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php
index 848dd0a2cc4a..de26b7596151 100644
--- a/app/Models/Invoice.php
+++ b/app/Models/Invoice.php
@@ -73,6 +73,18 @@ class Invoice extends EntityModel implements BalanceAffecting
'date:',
];
+ /**
+ * @var array
+ */
+ public static $requestFields = [
+ 'invoice_number',
+ 'invoice_date',
+ 'due_date',
+ 'po_number',
+ 'discount',
+ 'partial',
+ ];
+
public static $statusClasses = [
INVOICE_STATUS_SENT => 'info',
INVOICE_STATUS_VIEWED => 'warning',
diff --git a/app/Ninja/Intents/BaseIntent.php b/app/Ninja/Intents/BaseIntent.php
index 766810c0180c..f95391c8ca72 100644
--- a/app/Ninja/Intents/BaseIntent.php
+++ b/app/Ninja/Intents/BaseIntent.php
@@ -187,9 +187,11 @@ class BaseIntent
{
$field = str_replace(' ', '_', $field);
+ /* Shouldn't be need any more
if (strpos($field, 'date') !== false) {
$field .= '_sql';
}
+ */
return $field;
}
diff --git a/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php b/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php
index d2962fd18499..c954bd65ee1c 100644
--- a/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php
+++ b/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php
@@ -2,6 +2,7 @@
namespace App\Ninja\Intents\WebApp;
+use App\Models\Invoice;
use App\Models\EntityModel;
use App\Ninja\Intents\InvoiceIntent;
use Exception;
@@ -11,18 +12,21 @@ class CreateInvoiceIntent extends InvoiceIntent
public function process()
{
$client = $this->requestClient();
- $invoiceItems = $this->requestInvoiceItems();
+ $clientPublicId = $client ? $client->public_id : null;
- if (! $client) {
- throw new Exception(trans('texts.client_not_found'));
+ //$invoiceItems = $this->requestInvoiceItems();
+
+ $url = '/invoices/create/' . $clientPublicId . '?';
+
+ foreach ($this->requestFields() as $field => $value) {
+ if (in_array($field, Invoice::$requestFields)) {
+ $url .= $field . '=' . urlencode($value) . '&';
+ }
}
- $data = array_merge($this->requestFields(), [
- 'client_id' => $client->public_id,
- 'invoice_items' => $invoiceItems,
- ]);
+ $url = rtrim($url, '?');
+ $url = rtrim($url, '&');
- //var_dump($data);
- dd($data);
+ return redirect($url);
}
}
diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php
index 7a0fd0a8e2d8..26632b74f7ee 100644
--- a/resources/lang/en/texts.php
+++ b/resources/lang/en/texts.php
@@ -2464,6 +2464,7 @@ $LANG = array(
'confirm_account_to_import' => 'Please confirm your account to import data.',
'import_started' => 'Your import has started, we\'ll send you an email once it completes.',
'listening' => 'Listening...',
+ 'microphone_help' => 'Say \'Create new invoice for...\'',
);
diff --git a/resources/views/partials/keyboard_shortcuts.blade.php b/resources/views/partials/keyboard_shortcuts.blade.php
index de2d6b7862c4..5c5b00868604 100644
--- a/resources/views/partials/keyboard_shortcuts.blade.php
+++ b/resources/views/partials/keyboard_shortcuts.blade.php
@@ -132,6 +132,12 @@
$('#left-menu-toggle').trigger('click');
});
+ @if (Utils::isNinja())
+ Mousetrap.bind('r', function(e) {
+ onMicrophoneClick();
+ });
+ @endif
+
@foreach([
'i' => ENTITY_INVOICE,
'p' => ENTITY_PAYMENT,
diff --git a/resources/views/partials/speech_recognition.blade.php b/resources/views/partials/speech_recognition.blade.php
index 693a9505f24c..e5951243dd82 100644
--- a/resources/views/partials/speech_recognition.blade.php
+++ b/resources/views/partials/speech_recognition.blade.php
@@ -1,20 +1,25 @@
+ title="{{ trans('texts.microphone_help') }}"
+ onclick="onMicrophoneClick()" aria-hidden="true">