mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Working on speech rec
This commit is contained in:
parent
c4e960a805
commit
4abb5dd2c5
@ -84,6 +84,17 @@ class BaseIntent
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function hasField($field, $value = false)
|
||||
{
|
||||
$fieldValue = $this->getField($field);
|
||||
|
||||
if ($value) {
|
||||
return $fieldValue && $fieldValue == $value;
|
||||
} else {
|
||||
return $fieldValue ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
throw new Exception(trans('texts.intent_not_supported'));
|
||||
@ -154,6 +165,20 @@ class BaseIntent
|
||||
return $client;
|
||||
}
|
||||
|
||||
protected function requestInvoice()
|
||||
{
|
||||
$invoiceRepo = app('App\Ninja\Repositories\InvoiceRepository');
|
||||
$invoice = false;
|
||||
|
||||
foreach ($this->data->entities as $param) {
|
||||
if ($param->type == 'builtin.number') {
|
||||
return $invoiceRepo->findPhonetically($param->entity);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function requestFields()
|
||||
{
|
||||
$data = [];
|
||||
|
@ -8,12 +8,18 @@ class CreatePaymentIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
$clientPublicId = 0;
|
||||
$invoicePublicId = 0;
|
||||
|
||||
if ($invoice = $this->requestInvoice()) {
|
||||
$invoicePublicId = $invoice->public_id;
|
||||
} elseif ($client = $this->requestClient()) {
|
||||
$clientPublicId = $client->public_id;
|
||||
}
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/payments/create/' . $clientPublicId . '?';
|
||||
$url = sprintf('/payments/create/%s/%s', $clientPublicId, $invoicePublicId);
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
|
@ -1121,4 +1121,26 @@ class InvoiceRepository extends BaseRepository
|
||||
$this->save($data, $invoice);
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
|
||||
public function findPhonetically($invoiceNumber)
|
||||
{
|
||||
$map = [];
|
||||
$max = SIMILAR_MIN_THRESHOLD;
|
||||
$invoiceId = 0;
|
||||
|
||||
$invoices = Invoice::scope()->get(['id', 'invoice_number', 'public_id']);
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$map[$invoice->id] = $invoice;
|
||||
$similar = similar_text($invoiceNumber, $invoice->invoice_number, $percent);
|
||||
var_dump($similar);
|
||||
if ($percent > $max) {
|
||||
$invoiceId = $invoice->id;
|
||||
$max = $percent;
|
||||
}
|
||||
}
|
||||
|
||||
return ($invoiceId && isset($map[$invoiceId])) ? $map[$invoiceId] : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -172,11 +172,11 @@
|
||||
}
|
||||
|
||||
function onMicrophoneClick() {
|
||||
//$('#search').val('create new invoice for edgar a po number of 1234');
|
||||
$('#search').val('new payment for invoice 1279');
|
||||
//$('#search').val('invoice for edgar');
|
||||
//$('#search').val('create a task for edgar');
|
||||
//$('#search-form').submit();
|
||||
//return;
|
||||
$('#search-form').submit();
|
||||
return;
|
||||
|
||||
$('.fa-microphone').hide();
|
||||
$('#search').val("{{ trans('texts.listening') }}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user