diff --git a/htdocs/admin/bank.php b/htdocs/admin/bank.php index 8f196de9f13..8a5c60c8483 100644 --- a/htdocs/admin/bank.php +++ b/htdocs/admin/bank.php @@ -92,10 +92,10 @@ print "\n"; $bankorder[0][0]=$langs->trans("BankOrderGlobal"); $bankorder[0][1]=$langs->trans("BankOrderGlobalDesc"); -$bankorder[0][2]='BankCode DeskCode AccountNumber BankAccountNumberKey'; +$bankorder[0][2]='BankCode DeskCode BankAccountNumber BankAccountNumberKey'; $bankorder[1][0]=$langs->trans("BankOrderES"); $bankorder[1][1]=$langs->trans("BankOrderESDesc"); -$bankorder[1][2]='BankCode DeskCode BankAccountNumberKey AccountNumber'; +$bankorder[1][2]='BankCode DeskCode BankAccountNumberKey BankAccountNumber'; $var = true; $i=0; diff --git a/htdocs/categories/class/api_category.class.php b/htdocs/categories/class/api_category.class.php index 364147d097d..5e558ddc486 100644 --- a/htdocs/categories/class/api_category.class.php +++ b/htdocs/categories/class/api_category.class.php @@ -18,6 +18,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; /** * API class for category object @@ -162,6 +163,86 @@ class CategoryApi extends DolibarrApi } return $obj_ret; } + /** + * List categories of an entity + * + * Get a list of categories + * + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param int $item Id of the item to get categories for + * @return array Array of category objects + * + * @url GET /product/{item}/categories + */ + function getListForItem($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) { + global $db, $conf; + + $obj_ret = array(); + + if(! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + //if ($type == "") { + //$type="product"; + //} + $sub_type = $type; + $subcol_name = "fk_".$type; + if ($type=="customer" || $type=="supplier") { + $sub_type="societe"; + $subcol_name="fk_soc"; + } + $sql = "SELECT s.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; + $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub "; + $sql.= ' WHERE s.entity IN ('.getEntity('categorie', 1).')'; + $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES); + $sql.= ' AND s.rowid = sub.fk_categorie'; + $sql.= ' AND sub.'.$subcol_name.' = '.$item; + + $nbtotalofrecords = 0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) + { + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + } + + $sql.= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql.= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + while ($i < $num) + { + $obj = $db->fetch_object($result); + $category_static = new Categorie($db); + if($category_static->fetch($obj->rowid)) { + $obj_ret[] = parent::_cleanObjectDatas($category_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve category list : '.$category_static->error); + } + if( ! count($obj_ret)) { + throw new RestException(404, 'No category found'); + } + return $obj_ret; + } /** * Get member categories list @@ -193,6 +274,56 @@ class CategoryApi extends DolibarrApi function getListCategoryCustomer($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { return $this->getList('customer', $sortfield, $sortorder, $limit, $page); } + /** + * Get categories for a customer + * + * @param int $cusid Customer id filter + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET /customer/{cusid}/categories + */ + function getListCustomerCategories($cusid, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + return $this->getListForItem('customer', $sortfield, $sortorder, $limit, $page, $cusid); + } + + /** + * Add category to customer + * + * @param int $cusid Id of customer + * @param int $catid Id of category + * + * @return mixed + * + * @url GET /customer/{cusid}/addCategory/{catid} + */ + function addCustomerCategory($cusid,$catid) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $customer = new Client($this->db); + $customer->fetch($cusid); + if( ! $customer ) { + throw new RestException(404, 'customer not found'); + } + $result = $this->category->fetch($catid); + if( ! $result ) { + throw new RestException(404, 'category not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$customer->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->category->add_type($customer,'customer'); + return $customer; + } /** * Get supplier categories list diff --git a/htdocs/commande/class/api_commande.class.php b/htdocs/commande/class/api_commande.class.php index b7b6cb0c21c..04d78f30a1d 100644 --- a/htdocs/commande/class/api_commande.class.php +++ b/htdocs/commande/class/api_commande.class.php @@ -102,16 +102,17 @@ class CommandeApi extends DolibarrApi * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number + * @param string $societe Societe filter field * * @url GET /order/list * @return array Array of order objects */ - function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $societe = 0) { global $db, $conf; $obj_ret = array(); - - $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; + // case of external user, $societe param is ignored and replaced by user's socid + $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; // If the internal user must only see his customers, force searching by him if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; @@ -178,6 +179,22 @@ class CommandeApi extends DolibarrApi } return $obj_ret; } + + /** + * List orders for specific thirdparty + * + * Get a list of orders + * + * @param int $socid Id of customer + * + * @url GET /customer/{socid}/order/list + * @url GET /thirdparty/{socid}/order/list + * @return array Array of order objects + */ + function getListForSoc($socid = 0) { + return getList(0,"s.rowid","ASC",0,0,$socid); + } + /** * Create order object @@ -186,7 +203,7 @@ class CommandeApi extends DolibarrApi * * @url POST order/ * - * @return string ID of commande + * @return int ID of commande */ function post($request_data = NULL) { @@ -195,19 +212,203 @@ class CommandeApi extends DolibarrApi } // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->commande->$field = $value; } + if (isset($request_data["lines"])) { + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->commande->lines = $lines; + } if(! $this->commande->create(DolibarrApiAccess::$user) ) { throw new RestException(401); } - return $this->commande->ref; + return $this->commande->id; + } + /** + * Get lines of an order + * + * + * @param int $id Id of order + * + * @url GET order/{id}/line/list + * + * @return int + */ + function getLines($id) { + if(! DolibarrApiAccess::$user->rights->commande->lire) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Commande not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->commande->getLinesArray(); + $result = array(); + foreach ($this->commande->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + /** + * Add a line to given order + * + * + * @param int $id Id of commande to update + * @param array $request_data Orderline data + * + * @url POST order/{id}/line + * + * @return int + */ + function postLine($id, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Commande not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->commande->addline( + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + $request_data->fk_product, + $request_data->remise_percent, + $request_data->info_bits, + $request_data->fk_remise_except, + 'HT', + 0, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->array_options, + $request_data->fk_unit, + $this->element, + $request_data->id + ); + + if ($updateRes > 0) { + return $this->get($id)->line->rowid; + + } + return false; + } + /** + * Update a line to given order + * + * + * @param int $id Id of commande to update + * @param int $lineid Id of line to update + * @param array $request_data Orderline data + * + * @url PUT order/{id}/line/{lineid} + * + * @return object + */ + function putLine($id, $lineid, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Commande not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->commande->updateline( + $lineid, + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->remise_percent, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + 'HT', + $request_data->info_bits, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->special_code, + $request_data->array_options, + $request_data->fk_unit + ); + + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + return false; + } + /** + * Delete a line to given order + * + * + * @param int $id Id of commande to update + * @param int $lineid Id of line to delete + * + * @url DELETE order/{id}/line/{lineid} + * + * @return int + */ + function delLine($id, $lineid) { + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Commande not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->commande->deleteline($lineid); + if ($updateRes == 1) { + return $this->get($id); + } + return false; } /** - * Update order + * Update order general fields (won't touch lines of order) * * @param int $id Id of commande to update * @param array $request_data Datas @@ -216,11 +417,10 @@ class CommandeApi extends DolibarrApi * * @return int */ - function put($id, $request_data = NULL) - { - if(! DolibarrApiAccess::$user->rights->commande->creer) { - throw new RestException(401); - } + function put($id, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } $result = $this->commande->fetch($id); if( ! $result ) { @@ -230,13 +430,12 @@ class CommandeApi extends DolibarrApi if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - foreach($request_data as $field => $value) { $this->commande->$field = $value; } if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update')) - return $this->get ($id); + return $this->get($id); return false; } @@ -329,6 +528,7 @@ class CommandeApi extends DolibarrApi if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $commande[$field] = $data[$field]; + } return $commande; } diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index f4962bd2cf1..e2cecacb83c 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2014-2015 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2016 Marcos García * * 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 @@ -387,65 +388,28 @@ if ($action == 'create') print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''; + print ''; } $ibankey = FormBank::getIBANLabel($account); $bickey="BICNumber"; @@ -650,64 +614,20 @@ else print ''.$account->bank.''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''.$account->code_guichet.''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $content = $account->cle_rib; } - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''.$account->number.''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''.$account->cle_rib.''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''.$content.''; + print ''; } $ibankey = FormBank::getIBANLabel($account); @@ -937,65 +857,28 @@ else print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''; + print ''; } $ibankey = FormBank::getIBANLabel($account); diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index bad817d7a21..123f4537a58 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -238,6 +238,31 @@ class Account extends CommonObject ); } + /** + * Shows the account number in the appropiate format + * + * @return string + */ + public function __toString() + { + $string = ''; + + foreach ($this->getFieldsToShow() as $val) { + + if ($val == 'BankCode') { + $string .= $this->code_banque.' '; + } elseif ($val == 'BankAccountNumber') { + $string .= $this->number.' '; + } elseif ($val == 'DeskCode') { + $string .= $this->code_guichet.' '; + } elseif ($val == 'BankAccountNumberKey') { + $string .= $this->cle_rib.' '; + } + } + + return trim($string); + } + /** * Return if a bank account need to be conciliated @@ -1230,6 +1255,83 @@ class Account extends CommonObject } + /** + * Returns the fields in order that this bank account should show to the user + * Will return an array with the following values: + * - BankAccountNumber + * - BankCode + * - BankAccountNumberKey + * - DeskCode + * + * Some countries show less or more bank account properties to the user + * + * @return array + * @see useDetailedBBAN + */ + public function getFieldsToShow() + { + //Get the required properties depending on the country + $detailedBBAN = $this->useDetailedBBAN(); + + if ($detailedBBAN == 0) { + return array( + 'BankAccountNumber' + ); + } elseif ($detailedBBAN == 2) { + return array( + 'BankCode', + 'BankAccountNumber' + ); + } + + //Get the order the properties are shown + return self::getAccountNumberOrder(); + } + + /** + * Returns the components of the bank account in order. + * Will return an array with the following values: + * - BankAccountNumber + * - BankCode + * - BankAccountNumberKey + * - DeskCode + * + * @return array + */ + public static function getAccountNumberOrder() + { + global $conf; + + $fieldlists = array( + 'BankCode', + 'DeskCode', + 'BankAccountNumber', + 'BankAccountNumberKey' + ); + + if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) { + if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) { + if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') { + $fieldlists = array( + 'BankCode', + 'DeskCode', + 'BankAccountNumberKey', + 'BankAccountNumber' + ); + } + } else { + //Replace the old AccountNumber key with the new BankAccountNumber key + $fieldlists = explode( + ' ', + preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', + $conf->global->BANK_SHOW_ORDER_OPTION) + ); + } + } + + return $fieldlists; + } + /** * Initialise an instance with random values. diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index e995b06aa6b..ca58ff334b5 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -55,6 +55,9 @@ $subcat = false; if (GETPOST('subcat', 'alpha') === 'yes') { $subcat = true; } +// product/service +$selected_type = GETPOST('search_type', 'int'); +if ($selected_type =='') $selected_type = -1; // Date range $year=GETPOST("year"); @@ -124,6 +127,7 @@ $headerparams['q'] = $q; $tableparams = array(); $tableparams['search_categ'] = $selected_cat; +$tableparams['search_type'] = $selected_type; $tableparams['subcat'] = ($subcat === true)?'yes':''; // Adding common parameters @@ -180,7 +184,7 @@ $catotal=0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label,"; + $sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,"; $sql.= " SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,"; $sql.= " SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as l, ".MAIN_DB_PREFIX."product as p"; @@ -203,6 +207,10 @@ if ($modecompta == 'CREANCES-DETTES') if ($date_start && $date_end) { $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } + if ($selected_type >=0) + { + $sql.= " AND l.product_type = ".$selected_type; + } if ($selected_cat === -2) // Without any category { $sql.=" AND cp.fk_product is null"; @@ -214,7 +222,7 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid"; } $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY p.rowid, p.ref, p.label"; + $sql.= " GROUP BY p.rowid, p.ref, p.label, p.fk_product_type"; $sql.= $db->order($sortfield,$sortorder); dol_syslog("cabyprodserv", LOG_DEBUG); @@ -228,6 +236,7 @@ if ($modecompta == 'CREANCES-DETTES') $amount[$obj->rowid] = $obj->amount_ttc; $qty[$obj->rowid] = $obj->qty; $name[$obj->rowid] = $obj->ref . ' - ' . $obj->label; + $type[$obj->rowid] = $obj->product_type; $catotal_ht+=$obj->amount; $catotal+=$obj->amount_ttc; $qtytotal+=$obj->qty; @@ -257,8 +266,14 @@ if ($modecompta == 'CREANCES-DETTES') if ($subcat) { print ' checked'; } - print '>'; - print ''; + print '>'; + // type filter (produit/service) + print ' '; + print $langs->trans("Type"). ': '; + $form->select_type_of_lines(isset($selected_type)?$selected_type:-1,'search_type',1,1,1); + print ''; + + print ''; print ''; print ''; @@ -337,7 +352,7 @@ if ($modecompta == 'CREANCES-DETTES') // Product $fullname=$name[$key]; if ($key >= 0) { - $linkname=''.img_object($langs->trans("ShowProduct"),'product').' '.$fullname.''; + $linkname=''.img_object($langs->trans("ShowProduct"),$type[$key]==0?'product':'service').' '.$fullname.''; } else { $linkname=$langs->trans("PaymentsNotLinkedToProduct"); } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d3cb3361b02..51cb77ea1a4 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -9,7 +9,7 @@ * Copyright (C) 2012-2015 Raphaël Doursenaud * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> - * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2016 Marcos García * * 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 @@ -648,64 +648,42 @@ function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default // key = check control key used only when $usedetailedbban = 1 if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6); - if ($usedetailedbban == 1) - { - $fieldstoshow=array('bank','desk','number','key'); - if ($conf->global->BANK_SHOW_ORDER_OPTION == 1) $fieldstoshow=array('bank','desk','key','number'); - } - else if ($usedetailedbban == 2) - { - $fieldstoshow=array('bank','number'); - } - else dol_print_error('','Value returned by function useDetailedBBAN not managed'); - - foreach ($fieldstoshow as $val) - { - if ($val == 'bank') - { - // Bank code - $tmplength=18; - $pdf->SetXY($curx, $cury+4); - $pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_banque), 0, 'C', 0); - $pdf->SetXY($curx, $cury+1); - $curx+=$tmplength; - $pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0); - if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+7); - } - if ($val == 'desk') - { - // Desk - $tmplength=18; - $pdf->SetXY($curx, $cury+4); - $pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_guichet), 0, 'C', 0); - $pdf->SetXY($curx, $cury+1); - $curx+=$tmplength; - $pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0); - if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+7); - } - if ($val == 'number') - { - // Number - $tmplength=24; - $pdf->SetXY($curx, $cury+4); - $pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->number), 0, 'C', 0); - $pdf->SetXY($curx, $cury+1); - $curx+=$tmplength; - $pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0); - if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+7); - } - if ($val == 'key') - { - // Key - $tmplength=13; - $pdf->SetXY($curx, $cury+4); - $pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->cle_rib), 0, 'C', 0); - $pdf->SetXY($curx, $cury+1); - $curx+=$tmplength; - $pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0); - if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+7); - } - } + + foreach ($account->getFieldsToShow() as $val) + { + $pdf->SetXY($curx, $cury+4); + $pdf->SetFont('','',$default_font_size - 3); + + if ($val == 'BankCode') { + // Bank code + $tmplength = 18; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + // Desk + $tmplength = 18; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + // Number + $tmplength = 24; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + // Key + $tmplength = 13; + $content = $account->cle_rib; + } else { + dol_print_error($this->db, 'Unexpected value for getFieldsToShow: '.$val); + break; + } + + $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0); + $pdf->SetXY($curx, $cury + 1); + $curx += $tmplength; + $pdf->SetFont('', 'B', $default_font_size - 4); + $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0); + if (empty($onlynumber)) { + $pdf->line($curx, $cury + 1, $curx, $cury + 7); + } + } $curx=$savcurx; $cury+=8; diff --git a/htdocs/societe/class/api_contact.class.php b/htdocs/societe/class/api_contact.class.php index f2c19f2e484..ba7c0d4a211 100644 --- a/htdocs/societe/class/api_contact.class.php +++ b/htdocs/societe/class/api_contact.class.php @@ -17,7 +17,7 @@ use Luracast\Restler\RestException; -require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; /** * API class for contact object @@ -100,6 +100,7 @@ class ContactApi extends DolibarrApi * @url GET /contact/list * @url GET /contact/list/{socid} * @url GET /thirdparty/{socid}/contacts + * @url GET /customer/{socid}/contacts * * @throws RestException */ diff --git a/htdocs/societe/class/api_thirdparty.class.php b/htdocs/societe/class/api_thirdparty.class.php index d56c269e08e..9c65d08ac43 100644 --- a/htdocs/societe/class/api_thirdparty.class.php +++ b/htdocs/societe/class/api_thirdparty.class.php @@ -40,6 +40,10 @@ class ThirdpartyApi extends DolibarrApi * @var Societe $company {@type Societe} */ public $company; + /** + * @var Customer $customer {@type Client} + */ + public $customer; /** * Constructor @@ -52,39 +56,87 @@ class ThirdpartyApi extends DolibarrApi global $db, $conf; $this->db = $db; $this->company = new Societe($this->db); + $this->customer = new Client($this->db); if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) { static::$FIELDS[] = 'email'; } } - /** - * Get properties of a thirdparty object - * - * Return an array with thirdparty informations - * - * @param int $id ID of thirdparty - * @return array|mixed data without useless information + /** + * Get properties of a customer object + * + * Return an array with customer informations + * + * @param int $id ID of customer + * @return array|mixed data without useless information * - * @url GET thirdparty/{id} - * @throws RestException + * @url GET customer/{id} + * @throws RestException + */ + function getCustomer($id) + { + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } + + $result = $this->customer->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Customer not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->customer->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($this->customer); + } + + /** + * Search customer by email + * + * @param string $email email id + * + * @return object client with given email + * + * @url GET customer/byemail/{email} */ + function getByEmail($email) { + $res = $this->getList(1,$email); + if (count($res) == 1) { + $customer = $res[0]; + return $customer; + } + return $res; + } + + /** + * Get properties of a thirdparty object + * + * Return an array with thirdparty informations + * + * @param int $id ID of thirdparty + * @return array|mixed data without useless information + * + * @url GET thirdparty/{id} + * @throws RestException + */ function get($id) { - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - return $this->_cleanObjectDatas($this->company); + return $this->_cleanObjectDatas($this->company); } /** @@ -95,6 +147,7 @@ class ThirdpartyApi extends DolibarrApi * @param int $mode Set to 1 to show only customers * Set to 2 to show only prospects * Set to 3 to show only those are not customer neither prospect + * @param Text $email Search by email filter * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list @@ -104,7 +157,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list * */ - function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + function getList($mode=0, $email=NULL, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); @@ -126,6 +179,7 @@ class ThirdpartyApi extends DolibarrApi if ($mode == 3) $sql.= " AND s.client IN (0)"; $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; + if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale @@ -183,6 +237,7 @@ class ThirdpartyApi extends DolibarrApi * @return array List of customers * * @url GET /thirdparty/list/customers + * @url GET /customer/list */ function getListCustomers() { return $this->getList(1); @@ -196,7 +251,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list/prospects */ function getListProspects() { - return $this->getList('',1); + return $this->getList(2); } /** @@ -207,7 +262,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list/others */ function getListOthers() { - return $this->getList('','',1); + return $this->getList(3); } /** @@ -220,16 +275,31 @@ class ThirdpartyApi extends DolibarrApi */ function post($request_data = NULL) { - if(! DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach($request_data as $field => $value) { - $this->company->$field = $value; - } - return $this->company->create(DolibarrApiAccess::$user); + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach($request_data as $field => $value) { + $this->company->$field = $value; + } + return $this->company->create(DolibarrApiAccess::$user); + } + + + /** + * Create customer object + * + * @param array $request_data Request datas + * @return int ID of thirdparty + * + * @url POST customer/ + */ + function postCustomer($request_data) { + $this->post($request_data); + $this->company->set_as_client(); + return $this->company->id; } /** @@ -265,30 +335,59 @@ class ThirdpartyApi extends DolibarrApi return false; } + /** + * Update customer + * + * @param int $id Id of thirdparty to update + * @param array $request_data Datas + * @return int + * + * @url PUT customer/{id} + */ + function putClient($id, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $result = $this->customer->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Customer not found'); + } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->customer->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + foreach($request_data as $field => $value) { + $this->customer->$field = $value; + } + + if($this->customer->update($id, DolibarrApiAccess::$user,1,'','','update')) + return $this->get ($id); + + return false; + } /** * Delete thirdparty * * @param int $id Thirparty ID - * @return integer + * @return type * * @url DELETE thirdparty/{id} + * @url DELETE customer/{id} */ function delete($id) { - if(! DolibarrApiAccess::$user->rights->societe->supprimer) { - throw new RestException(401); - } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->company->delete($id); + if(! DolibarrApiAccess::$user->rights->societe->supprimer) { + throw new RestException(401); + } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + return $this->company->delete($id); } /** diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index f71b04b7730..fe34f57fd6d 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2010-2013 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * Copyright (C) 2013 Peter Fontaine + * Copyright (C) 2016 Marcos García * * 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 @@ -60,7 +61,7 @@ class CompanyBankAccount extends Account /** * Create bank information record * - * @param Object $user User + * @param User $user User * @return int <0 if KO, >= 0 if OK */ function create($user='') @@ -222,79 +223,27 @@ class CompanyBankAccount extends Account } } - /** - * Return RIB - * - * @param boolean $displayriblabel Prepend or Hide Label - * @return string RIB - */ - function getRibLabel($displayriblabel = true) - { - global $langs,$conf; + /** + * Return RIB + * + * @param boolean $displayriblabel Prepend or Hide Label + * @return string RIB + */ + public function getRibLabel($displayriblabel = true) + { + $rib = ''; - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) - { - if ($this->label && $displayriblabel) $rib = $this->label." : "; + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; + if ($this->label && $displayriblabel) { + $rib = $this->label." : "; } - $fieldlistsarray=explode(' ',$fieldlists); - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_banque.' '; - } - } + $rib .= (string) $this; + } - if ($val == 'DeskCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_guichet.' '; - } - } - - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 2) - { - $rib.=$this->code_banque.' '; - } - } - - if ($val == 'AccountNumber') - { - $rib.=$this->number.' '; - } - - if ($val == 'BankAccountNumberKey') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->cle_rib.' '; - } - } - } - } - else - { - $rib=''; - } - - return $rib; - } + return $rib; + } /** * Set RIB as Default diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php index c7f087daf72..0d8cdcc1264 100644 --- a/htdocs/societe/rib.php +++ b/htdocs/societe/rib.php @@ -4,7 +4,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2016 Marcos García * * 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 @@ -254,64 +254,22 @@ if ($socid && $action != 'edit' && $action != "create") print ''.$account->bank.''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) + + foreach($account->getFieldsToShow() as $val) { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''.$account->code_guichet.''; - print ''; - } + if ($val == 'BankCode') { + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $content = $account->cle_rib; } - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''.$account->number.''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''.$account->cle_rib.''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''.$content.''; + print ''; } print ''.$langs->trans("IBAN").''; @@ -473,65 +431,28 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''; + print ''; } // IBAN diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index b4f070a2187..951c3a6ef7e 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -4,7 +4,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify @@ -149,64 +149,20 @@ if ($id && $action != 'edit') print ''.$account->bank.''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''.$account->code_guichet.''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $content = $account->cle_rib; } - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''.$account->code_banque.''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''.$account->number.''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''.$account->cle_rib.''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''.$content.''; + print ''; } print ''.$langs->trans("IBAN").''; @@ -290,65 +246,28 @@ if ($id && $action == 'edit' && $user->rights->user->user->creer) print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("DeskCode").''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''.$langs->trans("BankCode").''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''.$langs->trans("BankAccountNumber").''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''.$langs->trans("BankAccountNumberKey").''; - print ''; - print ''; - } - } + print ''.$langs->trans($val).''; + print ''; + print ''; } // IBAN diff --git a/htdocs/user/class/api_user.class.php b/htdocs/user/class/api_user.class.php new file mode 100644 index 00000000000..d09785d3ccb --- /dev/null +++ b/htdocs/user/class/api_user.class.php @@ -0,0 +1,208 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +use Luracast\Restler\RestException; + +//require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; + +/** + * API class for user object + * + * @smart-auto-routing false + * @access protected + * @class DolibarrApiAccess {@requires user,external} + * + */ +class UserApi extends DolibarrApi +{ + /** + * + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'login' + ); + + /** + * @var User $user {@type User} + */ + public $useraccount; + + /** + * Constructor + * + * @url user/ + * + */ + function __construct() { + global $db, $conf; + $this->db = $db; + $this->useraccount = new User($this->db); + } + + /** + * Get properties of an user object + * + * Return an array with user informations + * + * @param int $id ID of user + * @return array|mixed data without useless information + * + * @url GET user/{id} + * @throws RestException + */ + function get($id) { + //if (!DolibarrApiAccess::$user->rights->user->user->lire) { + //throw new RestException(401); + //} + + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($this->useraccount); + } + + /** + * Create useraccount object from contact + * + * @param int $contactid Id of contact + * @param array $request_data Request datas + * @return int ID of user + * + * @url POST /contact/{contactid}/createUser + */ + function createFromContact($contactid, $request_data = NULL) { + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //throw new RestException(401); + //} + + if (!isset($request_data["login"])) + throw new RestException(400, "login field missing"); + if (!isset($request_data["password"])) + throw new RestException(400, "password field missing"); + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { + throw new RestException(401); + } + $contact = new Contact($this->db); + $contact->fetch($contactid); + if ($contact->id <= 0) { + throw new RestException(404, 'Contact not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + // Check mandatory fields + $login = $request_data["login"]; + $password = $request_data["password"]; + $result = $this->useraccount->create_from_contact($contact,$login,$password); + if ($result <= 0) { + throw new RestException(500, "User not created"); + } + // password parameter not used in create_from_contact + $this->useraccount->setPassword($this->useraccount,$password); + return $result; + } + + /** + * Update account + * + * @param int $id Id of account to update + * @param array $request_data Datas + * @return int + * + * @url PUT user/{id} + */ + function put($id, $request_data = NULL) { + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //throw new RestException(401); + //} + + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'Account not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + foreach ($request_data as $field => $value) + { + $this->useraccount->$field = $value; + } + + if ($this->useraccount->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) + return $this->get($id); + + return false; + } + + /** + * Delete account + * + * @param int $id Account ID + * @return array + * + * @url DELETE user/{id} + */ + function delete($id) { + //if (!DolibarrApiAccess::$user->rights->user->user->supprimer) { + //throw new RestException(401); + //} + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + return $this->useraccount->delete($id); + } + + /** + * Validate fields before create or update object + * + * @param array $data Data to validate + * @return array + * @throws RestException + */ + function _validate($data) { + $account = array(); + foreach (UserApi::$FIELDS as $field) + { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $account[$field] = $data[$field]; + } + return $account; + } +} diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index a91d064c7f8..4e88233fe35 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2012 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2016 Marcos García * * 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 @@ -57,7 +58,7 @@ class UserBankAccount extends Account /** * Create bank information record * - * @param Object $user User + * @param User $user User * @return int <0 if KO, >= 0 if OK */ function create($user='') @@ -177,78 +178,26 @@ class UserBankAccount extends Account } } - /** - * Return RIB - * - * @param boolean $displayriblabel Prepend or Hide Label - * @return string RIB - */ - function getRibLabel($displayriblabel = true) - { - global $langs,$conf; + /** + * Return RIB + * + * @param boolean $displayriblabel Prepend or Hide Label + * @return string RIB + */ + public function getRibLabel($displayriblabel = true) + { + $rib = ''; - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) - { - if ($this->label && $displayriblabel) $rib = $this->label." : "; + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; + if ($this->label && $displayriblabel) { + $rib = $this->label." : "; } - $fieldlistsarray=explode(' ',$fieldlists); - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_banque.' '; - } - } + $rib .= (string) $this; + } - if ($val == 'DeskCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_guichet.' '; - } - } - - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 2) - { - $rib.=$this->code_banque.' '; - } - } - - if ($val == 'AccountNumber') - { - $rib.=$this->number.' '; - } - - if ($val == 'BankAccountNumberKey') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->cle_rib.' '; - } - } - } - } - else - { - $rib=''; - } - - return $rib; - } + return $rib; + } }