diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 2128abe73d6..990e21dd08b 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2017 Regis Houssin + * 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 @@ -18,6 +19,7 @@ use Luracast\Restler\RestException; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; @@ -76,6 +78,117 @@ class Members extends DolibarrApi return $this->_cleanObjectDatas($member); } + /** + * Get properties of a member object by linked thirdparty + * + * Return an array with member informations + * + * @param int $thirdparty ID of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/{thirdparty} + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function getByThirdparty($thirdparty) + { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty); + if ( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + + /** + * Get properties of a member object by linked thirdparty email + * + * Return an array with member informations + * + * @param string $email Email of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/email/{email} + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function getByThirdpartyEmail($email) + { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $thirdparty = new Societe($this->db); + $result = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); + if ( ! $result ) { + throw new RestException(404, 'thirdparty not found'); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty->id); + if ( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + + /** + * Get properties of a member object by linked thirdparty barcode + * + * Return an array with member informations + * + * @param string $barcode Barcode of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/barcode/{barcode} + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function getByThirdpartyBarcode($barcode) + { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $thirdparty = new Societe($this->db); + $result = $thirdparty->fetch('', '', '', $barcode); + if ( ! $result ) { + throw new RestException(404, 'thirdparty not found'); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty->id); + if ( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + /** * List members * diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index cd4432707cd..86f073d2c70 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1577,7 +1577,10 @@ if ($action == 'create') print ''; // Delivery delay - print ''.$langs->trans('AvailabilityPeriod').''; + print ''.$langs->trans('AvailabilityPeriod'); + if (!empty($conf->commande->enabled)) + print ' ('.$langs->trans('AfterOrder').')'; + print ''; $form->selectAvailabilityDelay('', 'availability_id', '', 1); print ''; diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index cb81d30798a..d7bcafc8363 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -77,7 +77,7 @@ $search_no_email = GETPOST("search_no_email", 'int'); if (!empty($conf->socialnetworks->enabled)) { foreach ($socialnetworks as $key => $value) { if ($value['active']) { - $search_{$key} = GETPOST("search_".$key, 'alpha'); + $search_[$key] = GETPOST("search_".$key, 'alpha'); } } } @@ -265,7 +265,7 @@ if (empty($reshook)) if (!empty($conf->socialnetworks->enabled)) { foreach ($socialnetworks as $key => $value) { if ($value['active']) { - $search_{$key} = ""; + $search_[$key] = ""; } } } @@ -407,8 +407,8 @@ if (strlen($search_phone_mobile)) $sql .= natural_search('p.phone_mobile', $se if (strlen($search_fax)) $sql .= natural_search('p.fax', $search_fax); if (!empty($conf->socialnetworks->enabled)) { foreach ($socialnetworks as $key => $value) { - if ($value['active'] && strlen($search_{$key})) { - $sql .= ' AND p.socialnetworks LIKE \'%"'.$key.'":"'.$search_{$key}.'%\''; + if ($value['active'] && strlen($search_[$key])) { + $sql .= ' AND p.socialnetworks LIKE \'%"'.$key.'":"'.$search_[$key].'%\''; } } } @@ -719,7 +719,7 @@ if (!empty($conf->socialnetworks->enabled)) { if (!empty($arrayfields['p.'.$key]['checked'])) { print ''; - print ''; + print ''; print ''; } } diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 1efe6287c66..ba807fa1706 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -67,7 +67,7 @@ class Thirdparties extends DolibarrApi * * Return an array with thirdparty informations * - * @param int $id ID of thirdparty + * @param int $id Id of third party to load * @return array|mixed data without useless information * * @throws RestException @@ -82,7 +82,7 @@ class Thirdparties extends DolibarrApi * * Return an array with thirdparty informations * - * @param string $email Sort field + * @param string $email Email of third party to load * @return array|mixed data without useless information * * @url GET byEmail/{email} @@ -94,6 +94,23 @@ class Thirdparties extends DolibarrApi return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email); } + /** + * Get properties of a thirdparty object by barcode. + * + * Return an array with thirdparty informations + * + * @param string $barcode Barcode of third party to load + * @return array|mixed data without useless information + * + * @url GET barcode/{barcode} + * + * @throws RestException + */ + public function getByBarcode($barcode) + { + return $this->_fetch('', '', '', $barcode); + } + /** * List thirdparties * @@ -1810,7 +1827,7 @@ class Thirdparties extends DolibarrApi * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) - * @param string $ref_int Internal reference of third party (not used by dolibarr) + * @param string $barcode Barcode of third party to load * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) @@ -1823,14 +1840,14 @@ class Thirdparties extends DolibarrApi * * @throws RestException */ - private function _fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') + private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') { global $conf; if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } - $result = $this->company->fetch($rowid, $ref, $ref_ext, $ref_int, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias); + $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias); if (!$result) { throw new RestException(404, 'Thirdparty not found'); } 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 ee304b7438e..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 @@ -44,9 +45,16 @@ $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is $action = GETPOST('action', 'alpha'); $setterminal = GETPOST('setterminal', 'int'); +if ($_SESSION["takeposterminal"] == "") +{ + if ($conf->global->TAKEPOS_NUM_TERMINALS == "1") $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal + elseif (!empty($_COOKIE["takeposterminal"])) $_SESSION["takeposterminal"] = $_COOKIE["takeposterminal"]; // Restore takeposterminal from previous session +} + if ($setterminal > 0) { $_SESSION["takeposterminal"] = $setterminal; + setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, false, true); // Permanent takeposterminal var in a cookie } $_SESSION["urlfrom"] = '/takepos/index.php'; @@ -399,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() { @@ -524,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); } @@ -734,8 +755,7 @@ $( document ).ready(function() { //IF NO TERMINAL SELECTED if ($_SESSION["takeposterminal"] == "") { - if ($conf->global->TAKEPOS_NUM_TERMINALS == "1") $_SESSION["takeposterminal"] = 1; - else print "TerminalsDialog();"; + print "TerminalsDialog();"; } if ($conf->global->TAKEPOS_CONTROL_CASH_OPENING) { diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index a25c809b551..8179b236158 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -817,6 +817,7 @@ $( document ).ready(function() { if ($result > 0) { $adh->ref = $adh->getFullName($langs); + if (empty($adh->statut)) { $s .= ""; } $s .= $adh->getFullName($langs); $s .= ' - '.$adh->type; if ($adh->datefin) @@ -829,6 +830,7 @@ $( document ).ready(function() { $s .= '
'.$langs->trans("SubscriptionNotReceived"); if ($adh->statut > 0) $s .= " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft and not terminated } + if (empty($adh->statut)) { $s .= "
"; } } else { $s .= '
'.$langs->trans("ThirdpartyNotLinkedToMember"); }