diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 7c4471b0ec8..7f9555c3226 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2020 Thibault FOUCART * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,6 +69,24 @@ if ($action == 'getProducts') { echo 'Failed to load category with id='.$category; } } elseif ($action == 'search' && $term != '') { + // Change thirdparty with barcode + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + + $thirdparty = new Societe($db); + $result = $thirdparty->fetch('', '', '', $term); + + if ( $result && $thirdparty->id > 0) { + $rows = array(); + $rows[] = array( + 'rowid' => $thirdparty->id, + 'name' => $thirdparty->name, + 'barcode' => $thirdparty->barcode, + 'object' => 'thirdparty' + ); + echo json_encode($rows); + exit; + } + // Define $filteroncategids, the filter on category ID if there is a Root category defined. $filteroncategids = ''; if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) { // A root category is defined, we must filter on products inside this category tree @@ -101,7 +120,8 @@ if ($action == 'getProducts') { 'tosell' => $obj->tosell, 'tobuy' => $obj->tobuy, 'barcode' => $obj->barcode, - 'price' => $obj->price + 'price' => $obj->price, + 'object' => 'product' //'price_formated' => price(price2num($obj->price, 'MU'), 1, $langs, 1, -1, -1, $conf->currency) ); } diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 2dd57ce391f..82dec49b7db 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -1,6 +1,7 @@ * Copyright (C) 2019 Josep LluĂ­s Amador + * Copyright (C) 2020 Thibault FOUCART * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -406,6 +407,15 @@ function ClickProduct(position) { ClearSearch(); } +function ChangeThirdparty(idcustomer) { + console.log("ChangeThirdparty"); + // Call page list.php to change customer + $("#poslines").load("../societe/list.php?action=change&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() { + }); + + ClearSearch(); +} + function deleteline() { console.log("Delete line"); $("#poslines").load("invoice.php?action=deleteline&place="+place+"&idline="+selectedline, function() { @@ -531,7 +541,11 @@ function Search2(keyCodeForEnter) { // If there is only 1 answer if ($('#search').val().length > 0 && data.length == 1) { console.log($('#search').val()+' - '+data[0]['barcode']); - if ($('#search').val() == data[0]['barcode']) { + if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) { + console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']); + ChangeThirdparty(data[0]['rowid']); + } + else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) { console.log("There is only 1 answer with barcode matching the search, so we add the product in basket"); ClickProduct(0); }