2016-02-07 08:47:02 +01:00
< ? php
2015-08-12 15:53:17 +02:00
/* Copyright ( C ) 2013 - 2014 Olivier Geffroy < jeff @ jeffinfo . com >
2022-04-28 05:34:02 +02:00
* Copyright ( C ) 2013 - 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Ari Elbaz ( elarifr ) < github @ accedinfo . com >
* Copyright ( C ) 2021 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2014-08-27 07:03:42 +02:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-08-27 07:03:42 +02:00
*/
/**
2016-04-17 15:44:04 +02:00
* \file htdocs / accountancy / admin / productaccount . php
2019-05-13 22:25:15 +02:00
* \ingroup Accountancy ( Double entries )
2016-04-17 15:44:04 +02:00
* \brief To define accounting account on product / service
2014-08-27 07:03:42 +02:00
*/
2015-07-08 07:46:26 +02:00
require '../../main.inc.php' ;
2019-11-13 19:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2022-08-24 10:26:27 +02:00
if ( isModEnabled ( 'categorie' )) {
2022-04-28 05:34:02 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
}
2014-08-27 07:03:42 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2019-11-13 19:35:02 +01:00
$langs -> loadLangs ( array ( " companies " , " compta " , " accountancy " , " products " ));
2014-08-27 07:03:42 +02:00
2015-12-21 06:51:46 +01:00
// Security check
2022-08-24 10:26:27 +02:00
if ( ! isModEnabled ( 'accounting' )) {
2016-02-01 15:07:12 +01:00
accessforbidden ();
}
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> accounting -> bind -> write )) {
2020-10-31 14:32:18 +01:00
accessforbidden ();
2021-02-22 21:36:42 +01:00
}
2016-10-06 17:43:10 +02:00
2015-08-12 15:53:17 +02:00
// search & action GETPOST
2018-11-05 17:53:31 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-11-15 14:35:55 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' );
2015-07-08 07:46:26 +02:00
$codeventil_buy = GETPOST ( 'codeventil_buy' , 'array' );
$codeventil_sell = GETPOST ( 'codeventil_sell' , 'array' );
2015-08-12 15:53:17 +02:00
$chk_prod = GETPOST ( 'chk_prod' , 'array' );
2021-11-15 14:35:55 +01:00
$default_account = GETPOST ( 'default_account' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2015-08-12 15:53:17 +02:00
$account_number_buy = GETPOST ( 'account_number_buy' );
2015-07-08 07:46:26 +02:00
$account_number_sell = GETPOST ( 'account_number_sell' );
2015-08-12 15:53:17 +02:00
$changeaccount = GETPOST ( 'changeaccount' , 'array' );
$changeaccount_buy = GETPOST ( 'changeaccount_buy' , 'array' );
$changeaccount_sell = GETPOST ( 'changeaccount_sell' , 'array' );
2022-04-28 05:34:02 +02:00
$searchCategoryProductOperator = ( GETPOST ( 'search_category_product_operator' , 'int' ) ? GETPOST ( 'search_category_product_operator' , 'int' ) : 0 );
$searchCategoryProductList = GETPOST ( 'search_category_product_list' , 'array' );
2015-08-12 15:53:17 +02:00
$search_ref = GETPOST ( 'search_ref' , 'alpha' );
$search_label = GETPOST ( 'search_label' , 'alpha' );
$search_desc = GETPOST ( 'search_desc' , 'alpha' );
2020-09-28 11:08:27 +02:00
$search_vat = GETPOST ( 'search_vat' , 'alpha' );
2016-11-04 15:43:30 +01:00
$search_current_account = GETPOST ( 'search_current_account' , 'alpha' );
$search_current_account_valid = GETPOST ( 'search_current_account_valid' , 'alpha' );
2021-02-22 21:36:42 +01:00
if ( $search_current_account_valid == '' ) {
$search_current_account_valid = 'withoutvalidaccount' ;
}
2019-11-11 19:42:54 +01:00
$search_onsell = GETPOST ( 'search_onsell' , 'alpha' );
$search_onpurchase = GETPOST ( 'search_onpurchase' , 'alpha' );
2016-11-04 15:43:30 +01:00
2015-08-12 15:53:17 +02:00
$accounting_product_mode = GETPOST ( 'accounting_product_mode' , 'alpha' );
2018-10-12 16:49:53 +02:00
$btn_changetype = GETPOST ( 'changetype' , 'alpha' );
2021-10-23 21:10:43 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2015-08-12 15:53:17 +02:00
2021-02-22 21:36:42 +01:00
if ( empty ( $accounting_product_mode )) {
$accounting_product_mode = 'ACCOUNTANCY_SELL' ;
}
2019-03-14 16:16:50 +01:00
2020-03-12 12:45:44 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : ( empty ( $conf -> global -> ACCOUNTING_LIMIT_LIST_VENTILATION ) ? $conf -> liste_limit : $conf -> global -> ACCOUNTING_LIMIT_LIST_VENTILATION );
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-22 21:36:42 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2016-10-21 12:45:19 +02:00
$offset = $limit * $page ;
2015-07-08 07:46:26 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-22 21:36:42 +01:00
if ( ! $sortfield ) {
$sortfield = " p.ref " ;
}
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
2015-07-08 07:46:26 +02:00
2021-02-22 21:36:42 +01:00
if ( empty ( $action )) {
$action = 'list' ;
}
2016-10-21 12:45:19 +02:00
2019-11-13 19:35:02 +01:00
$arrayfields = array ();
2016-10-21 12:45:19 +02:00
2021-03-18 17:08:55 +01:00
$accounting_product_modes = array (
'ACCOUNTANCY_SELL' ,
'ACCOUNTANCY_SELL_INTRA' ,
'ACCOUNTANCY_SELL_EXPORT' ,
'ACCOUNTANCY_BUY' ,
'ACCOUNTANCY_BUY_INTRA' ,
'ACCOUNTANCY_BUY_EXPORT'
);
if ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ) {
$accountancy_field_name = " accountancy_code_buy " ;
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ) {
$accountancy_field_name = " accountancy_code_buy_intra " ;
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ) {
$accountancy_field_name = " accountancy_code_buy_export " ;
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ) {
$accountancy_field_name = " accountancy_code_sell " ;
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ) {
$accountancy_field_name = " accountancy_code_sell_intra " ;
} else { // $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT'
$accountancy_field_name = " accountancy_code_sell_export " ;
}
2016-10-21 12:45:19 +02:00
/*
* Actions
*/
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = 'list' ; $massaction = '' ;
}
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) {
$massaction = '' ;
}
2016-11-04 15:43:30 +01:00
2019-11-13 19:35:02 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-22 21:36:42 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2016-11-04 15:43:30 +01:00
2016-10-21 12:45:19 +02:00
// Purge search criteria
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
2022-04-28 05:34:02 +02:00
$searchCategoryProductOperator = 0 ;
$searchCategoryProductList = array ();
2020-10-31 14:32:18 +01:00
$search_ref = '' ;
$search_label = '' ;
$search_desc = '' ;
2020-09-28 11:08:27 +02:00
$search_vat = '' ;
2020-10-31 14:32:18 +01:00
$search_onsell = '' ;
$search_onpurchase = '' ;
$search_current_account = '' ;
$search_current_account_valid = '-1' ;
2016-02-01 15:07:12 +01:00
}
2016-10-21 12:45:19 +02:00
2015-12-21 06:51:46 +01:00
// Sales or Purchase mode ?
2015-08-06 21:23:02 +02:00
if ( $action == 'update' ) {
2019-11-13 19:35:02 +01:00
if ( ! empty ( $btn_changetype )) {
2015-08-12 15:53:17 +02:00
$error = 0 ;
2017-06-22 14:48:13 +02:00
2015-08-12 15:53:17 +02:00
if ( in_array ( $accounting_product_mode , $accounting_product_modes )) {
2019-11-13 19:35:02 +01:00
if ( ! dolibarr_set_const ( $db , 'ACCOUNTING_PRODUCT_MODE' , $accounting_product_mode , 'chaine' , 0 , '' , $conf -> entity )) {
$error ++ ;
2015-08-06 21:23:02 +02:00
}
2015-08-12 15:53:17 +02:00
} else {
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-08-12 15:53:17 +02:00
}
}
2017-06-22 14:48:13 +02:00
2021-11-15 14:35:55 +01:00
if ( ! empty ( $chk_prod ) && $massaction === 'changeaccount' ) {
2016-10-04 20:28:58 +02:00
//$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
2021-03-18 17:08:55 +01:00
if ( ! empty ( $chk_prod ) && in_array ( $accounting_product_mode , $accounting_product_modes )) {
2015-08-12 15:53:17 +02:00
$accounting = new AccountingAccount ( $db );
2017-06-22 14:48:13 +02:00
2020-09-28 11:08:27 +02:00
//$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
2018-01-22 21:07:10 +01:00
$arrayofdifferentselectedvalues = array ();
2017-06-22 14:48:13 +02:00
2016-10-04 20:28:58 +02:00
$cpt = 0 ; $ok = 0 ; $ko = 0 ;
2021-02-22 21:36:42 +01:00
foreach ( $chk_prod as $productid ) {
2019-11-13 19:35:02 +01:00
$accounting_account_id = GETPOST ( 'codeventil_' . $productid );
2017-06-22 14:48:13 +02:00
2018-01-22 21:07:10 +01:00
$result = 0 ;
2021-02-22 21:36:42 +01:00
if ( $accounting_account_id > 0 ) {
2019-11-13 19:35:02 +01:00
$arrayofdifferentselectedvalues [ $accounting_account_id ] = $accounting_account_id ;
2018-01-22 21:07:10 +01:00
$result = $accounting -> fetch ( $accounting_account_id , null , 1 );
}
if ( $result <= 0 ) {
2016-02-01 15:07:12 +01:00
// setEventMessages(null, $accounting->errors, 'errors');
2021-04-19 21:30:25 +02:00
$msg .= '<div><span style="color:red">' . $langs -> trans ( " ErrorDB " ) . ' : ' . $langs -> trans ( " Product " ) . ' ' . $productid . ' ' . $langs -> trans ( " NotVentilatedinAccount " ) . ' : id=' . $accounting_account_id . '<br> <pre>' . $sql . '</pre></span></div>' ;
2018-01-22 21:07:10 +01:00
$ko ++ ;
2015-08-12 15:53:17 +02:00
} else {
2021-10-01 16:37:54 +02:00
$sql = '' ;
2021-03-27 05:23:20 +01:00
if ( ! empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED )) {
2021-10-01 16:37:54 +02:00
$sql_exists = " SELECT rowid FROM " . MAIN_DB_PREFIX . " product_perentity " ;
$sql_exists .= " WHERE fk_product = " . (( int ) $productid ) . " AND entity = " . (( int ) $conf -> entity );
$resql_exists = $db -> query ( $sql_exists );
if ( ! $resql_exists ) {
$msg .= '<div><span style="color:red">' . $langs -> trans ( " ErrorDB " ) . ' : ' . $langs -> trans ( " Product " ) . ' ' . $productid . ' ' . $langs -> trans ( " NotVentilatedinAccount " ) . ' : id=' . $accounting_account_id . '<br> <pre>' . $resql_exists . '</pre></span></div>' ;
$ko ++ ;
} else {
$nb_exists = $db -> num_rows ( $resql_exists );
if ( $nb_exists <= 0 ) {
// insert
2021-10-29 05:47:29 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " product_perentity (fk_product, entity, " . $db -> escape ( $accountancy_field_name ) . " ) " ;
2021-10-01 16:37:54 +02:00
$sql .= " VALUES ( " . (( int ) $productid ) . " , " . (( int ) $conf -> entity ) . " , ' " . $db -> escape ( $accounting -> account_number ) . " ') " ;
} else {
$obj_exists = $db -> fetch_object ( $resql_exists );
// update
$sql = " UPDATE " . MAIN_DB_PREFIX . " product_perentity " ;
$sql .= " SET " . $accountancy_field_name . " = ' " . $db -> escape ( $accounting -> account_number ) . " ' " ;
$sql .= " WHERE rowid = " . (( int ) $obj_exists -> rowid );
}
}
2021-03-18 17:08:55 +01:00
} else {
$sql = " UPDATE " . MAIN_DB_PREFIX . " product " ;
2021-03-30 03:37:54 +02:00
$sql .= " SET " . $accountancy_field_name . " = ' " . $db -> escape ( $accounting -> account_number ) . " ' " ;
$sql .= " WHERE rowid = " . (( int ) $productid );
2020-10-31 14:32:18 +01:00
}
2017-06-22 14:48:13 +02:00
2021-08-27 22:42:04 +02:00
dol_syslog ( " /accountancy/admin/productaccount.php " , LOG_DEBUG );
2021-10-04 14:53:44 +02:00
2021-10-01 16:37:54 +02:00
$db -> begin ();
2021-10-04 14:53:44 +02:00
2021-02-22 21:36:42 +01:00
if ( $db -> query ( $sql )) {
2020-10-31 14:32:18 +01:00
$ok ++ ;
$db -> commit ();
2015-08-12 15:53:17 +02:00
} else {
2020-10-31 14:32:18 +01:00
$ko ++ ;
$db -> rollback ();
2015-08-12 15:53:17 +02:00
}
}
2017-06-22 14:48:13 +02:00
2018-01-22 21:07:10 +01:00
$cpt ++ ;
2015-08-06 21:23:02 +02:00
}
}
2018-01-22 21:07:10 +01:00
2021-02-22 21:36:42 +01:00
if ( $ko ) {
setEventMessages ( $langs -> trans ( " XLineFailedToBeBinded " , $ko ), null , 'errors' );
}
if ( $ok ) {
setEventMessages ( $langs -> trans ( " XLineSuccessfullyBinded " , $ok ), null , 'mesgs' );
}
2015-08-06 21:23:02 +02:00
}
}
2016-10-21 12:45:19 +02:00
/*
* View
*/
2017-05-25 06:57:28 +02:00
$form = new FormAccounting ( $db );
2015-07-08 07:46:26 +02:00
2019-02-10 12:59:09 +01:00
// Default AccountingAccount RowId Product / Service
2015-08-12 15:53:17 +02:00
// at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
2019-11-11 19:05:42 +01:00
// so we need to get those the rowid of those default value first
2015-07-08 07:46:26 +02:00
$accounting = new AccountingAccount ( $db );
2019-05-04 12:26:54 +02:00
// TODO: we should need to check if result is already exists accountaccount rowid.....
2021-10-23 20:53:46 +02:00
$aarowid_servbuy = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_ACCOUNT' ), 1 );
$aarowid_servbuy_intra = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT' ), 1 );
$aarowid_servbuy_export = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT' ), 1 );
$aarowid_prodbuy = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_ACCOUNT' ), 1 );
$aarowid_prodbuy_intra = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT' ), 1 );
$aarowid_prodbuy_export = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT' ), 1 );
$aarowid_servsell = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_ACCOUNT' ), 1 );
$aarowid_servsell_intra = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT' ), 1 );
$aarowid_servsell_export = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT' ), 1 );
$aarowid_prodsell = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT' ), 1 );
$aarowid_prodsell_intra = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT' ), 1 );
$aarowid_prodsell_export = $accounting -> fetch ( '' , getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT' ), 1 );
2019-05-03 14:08:20 +02:00
2021-10-23 21:06:37 +02:00
$aacompta_servbuy = getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_servbuy_intra = getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_servbuy_export = getDolGlobalString ( 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodbuy = getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodbuy_intra = getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodbuy_export = getDolGlobalString ( 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_servsell = getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_servsell_intra = getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_servsell_export = getDolGlobalString ( 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodsell = getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodsell_intra = getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
$aacompta_prodsell_export = getDolGlobalString ( 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT' , $langs -> trans ( " CodeNotDef " ));
2015-07-08 07:46:26 +02:00
2022-04-28 05:34:02 +02:00
$title = $langs -> trans ( " ProductsBinding " );
$helpurl = '' ;
$paramsCat = '' ;
foreach ( $searchCategoryProductList as $searchCategoryProduct ) {
$paramsCat .= " &search_category_product_list[]= " . urlencode ( $searchCategoryProduct );
}
llxHeader ( '' , $title , $helpurl , '' , 0 , 0 , array (), array (), $paramsCat , '' );
2015-12-21 06:51:46 +01:00
2021-10-23 20:53:46 +02:00
$pcgverid = getDolGlobalString ( 'CHARTOFACCOUNTS' );
2016-11-04 15:43:30 +01:00
$pcgvercode = dol_getIdFromCode ( $db , $pcgverid , 'accounting_system' , 'rowid' , 'pcg_version' );
2021-02-22 21:36:42 +01:00
if ( empty ( $pcgvercode )) {
$pcgvercode = $pcgverid ;
}
2014-08-27 07:03:42 +02:00
2020-09-28 11:08:27 +02:00
$sql = " SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx, " ;
2021-03-27 05:23:20 +01:00
if ( ! empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED )) {
2021-04-14 04:45:17 +02:00
$sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, " ;
$sql .= " ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export, " ;
2021-03-18 17:08:55 +01:00
} else {
$sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, " ;
$sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, " ;
}
2020-03-12 12:45:44 +01:00
$sql .= " p.tms, p.fk_product_type as product_type, " ;
$sql .= " aa.rowid as aaid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2021-03-27 05:23:20 +01:00
if ( ! empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED )) {
2021-04-14 04:45:17 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . (( int ) $conf -> entity );
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_account as aa ON aa.account_number = ppe. " . $accountancy_field_name . " AND aa.fk_pcg_version = ' " . $db -> escape ( $pcgvercode ) . " ' " ;
2020-05-21 00:02:33 +02:00
} else {
2021-03-18 17:08:55 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_account as aa ON aa.account_number = p. " . $accountancy_field_name . " AND aa.fk_pcg_version = ' " . $db -> escape ( $pcgvercode ) . " ' " ;
2019-05-03 14:08:20 +02:00
}
2022-04-28 05:34:02 +02:00
if ( ! empty ( $searchCategoryProductList )) {
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . " categorie_product as cp ON p.rowid = cp.fk_product " ; // We'll need this table joined to the select in order to filter by categ
}
2020-03-12 12:45:44 +01:00
$sql .= ' WHERE p.entity IN (' . getEntity ( 'product' ) . ')' ;
2021-03-18 17:08:55 +01:00
if ( strlen ( trim ( $search_current_account ))) {
2021-04-14 04:45:17 +02:00
$sql .= natural_search (( empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED ) ? " p. " : " ppe. " ) . $accountancy_field_name , $search_current_account );
2019-05-03 14:08:20 +02:00
}
2021-02-22 21:36:42 +01:00
if ( $search_current_account_valid == 'withoutvalidaccount' ) {
2016-11-04 15:43:30 +01:00
$sql .= " AND aa.account_number IS NULL " ;
}
2021-02-22 21:36:42 +01:00
if ( $search_current_account_valid == 'withvalidaccount' ) {
2020-10-31 14:32:18 +01:00
$sql .= " AND aa.account_number IS NOT NULL " ;
2016-10-21 12:45:19 +02:00
}
2022-04-28 05:34:02 +02:00
$searchCategoryProductSqlList = array ();
if ( $searchCategoryProductOperator == 1 ) {
foreach ( $searchCategoryProductList as $searchCategoryProduct ) {
if ( intval ( $searchCategoryProduct ) == - 2 ) {
$searchCategoryProductSqlList [] = " cp.fk_categorie IS NULL " ;
} elseif ( intval ( $searchCategoryProduct ) > 0 ) {
$searchCategoryProductSqlList [] = " cp.fk_categorie = " . $db -> escape ( $searchCategoryProduct );
}
}
if ( ! empty ( $searchCategoryProductSqlList )) {
$sql .= " AND ( " . implode ( ' OR ' , $searchCategoryProductSqlList ) . " ) " ;
}
} else {
foreach ( $searchCategoryProductList as $searchCategoryProduct ) {
if ( intval ( $searchCategoryProduct ) == - 2 ) {
$searchCategoryProductSqlList [] = " cp.fk_categorie IS NULL " ;
} elseif ( intval ( $searchCategoryProduct ) > 0 ) {
$searchCategoryProductSqlList [] = " p.rowid IN (SELECT fk_product FROM " . MAIN_DB_PREFIX . " categorie_product WHERE fk_categorie = " . (( int ) $searchCategoryProduct ) . " ) " ;
}
}
if ( ! empty ( $searchCategoryProductSqlList )) {
$sql .= " AND ( " . implode ( ' AND ' , $searchCategoryProductSqlList ) . " ) " ;
}
}
2015-08-12 15:53:17 +02:00
// Add search filter like
2015-07-08 07:46:26 +02:00
if ( strlen ( trim ( $search_ref ))) {
2019-01-27 11:55:16 +01:00
$sql .= natural_search ( " p.ref " , $search_ref );
2015-07-08 07:46:26 +02:00
}
if ( strlen ( trim ( $search_label ))) {
2019-01-27 11:55:16 +01:00
$sql .= natural_search ( " p.label " , $search_label );
2015-07-08 07:46:26 +02:00
}
if ( strlen ( trim ( $search_desc ))) {
2019-01-27 11:55:16 +01:00
$sql .= natural_search ( " p.description " , $search_desc );
2015-07-08 07:46:26 +02:00
}
2020-09-28 11:08:27 +02:00
if ( strlen ( trim ( $search_vat ))) {
$sql .= natural_search ( " p.tva_tx " , price2num ( $search_vat ), 1 );
}
2021-02-22 21:36:42 +01:00
if ( $search_onsell != '' && $search_onsell != '-1' ) {
$sql .= natural_search ( 'p.tosell' , $search_onsell , 1 );
}
if ( $search_onpurchase != '' && $search_onpurchase != '-1' ) {
$sql .= natural_search ( 'p.tobuy' , $search_onpurchase , 1 );
}
2019-11-11 19:42:54 +01:00
2022-04-28 05:34:02 +02:00
$sql .= " GROUP BY p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx, " ;
$sql .= " p.fk_product_type, " ;
$sql .= ' p.tms,' ;
2022-05-08 06:34:47 +02:00
$sql .= ' aa.rowid,' ;
2022-04-28 05:34:02 +02:00
if ( empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED )) {
$sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export " ;
} else {
$sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export " ;
}
2015-08-12 15:53:17 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2016-11-04 15:43:30 +01:00
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2021-02-22 21:36:42 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2022-05-15 22:29:19 +02:00
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
2021-02-22 21:36:42 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-10-31 14:32:18 +01:00
$page = 0 ;
$offset = 0 ;
}
2016-10-21 12:45:19 +02:00
}
2018-04-24 11:37:57 +02:00
2015-07-08 07:46:26 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2021-08-27 22:42:04 +02:00
dol_syslog ( " /accountancy/admin/productaccount.php " , LOG_DEBUG );
2022-05-15 22:29:19 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
2015-08-06 21:23:02 +02:00
$i = 0 ;
2017-06-22 14:48:13 +02:00
2020-10-31 14:32:18 +01:00
$param = '' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
2022-04-28 05:34:02 +02:00
if ( $searchCategoryProductOperator == 1 ) {
$param .= " &search_category_product_operator= " . urlencode ( $searchCategoryProductOperator );
}
foreach ( $searchCategoryProductList as $searchCategoryProduct ) {
$param .= " &search_category_product_list[]= " . urlencode ( $searchCategoryProduct );
}
2021-02-22 21:36:42 +01:00
if ( $search_ref > 0 ) {
2022-04-28 05:34:02 +02:00
$param .= " &search_ref= " . urlencode ( $search_ref );
2021-02-22 21:36:42 +01:00
}
if ( $search_label > 0 ) {
2022-04-28 05:34:02 +02:00
$param .= " &search_label= " . urlencode ( $search_label );
2021-02-22 21:36:42 +01:00
}
if ( $search_desc > 0 ) {
$param .= " &search_desc= " . urlencode ( $search_desc );
}
if ( $search_vat > 0 ) {
$param .= '&search_vat=' . urlencode ( $search_vat );
}
if ( $search_current_account > 0 ) {
$param .= " &search_current_account= " . urlencode ( $search_current_account );
}
if ( $search_current_account_valid && $search_current_account_valid != '-1' ) {
$param .= " &search_current_account_valid= " . urlencode ( $search_current_account_valid );
}
if ( $accounting_product_mode ) {
$param .= '&accounting_product_mode=' . urlencode ( $accounting_product_mode );
}
2020-10-31 14:32:18 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2021-02-22 21:36:42 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="update">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print load_fiche_titre ( $langs -> trans ( " ProductsBinding " ), '' , 'title_accountancy' );
2015-12-21 06:51:46 +01:00
print '<br>' ;
2017-06-22 14:48:13 +02:00
2020-03-12 12:45:44 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " InitAccountancyDesc " ) . '</span><br>' ;
2015-12-21 06:51:46 +01:00
print '<br>' ;
2017-06-22 14:48:13 +02:00
2020-10-31 14:32:18 +01:00
// Select mode
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2015-08-06 21:23:02 +02:00
print '<tr class="liste_titre">' ;
2020-03-12 12:45:44 +01:00
print '<td>' . $langs -> trans ( 'Options' ) . '</td><td>' . $langs -> trans ( 'Description' ) . '</td>' ;
2015-08-12 15:53:17 +02:00
print " </tr> \n " ;
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"' . ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductSell' ) . '</td>' ;
2016-11-04 15:43:30 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductSellDesc' );
2015-08-12 15:53:17 +02:00
print " </td></tr> \n " ;
2021-02-22 21:36:42 +01:00
if ( $mysoc -> isInEEC ()) {
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"' . ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductSellIntra' ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductSellIntraDesc' );
print " </td></tr> \n " ;
2019-05-04 12:26:54 +02:00
}
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"' . ( $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductSellExport' ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductSellExportDesc' );
print " </td></tr> \n " ;
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"' . ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductBuy' ) . '</td>' ;
2016-11-04 15:43:30 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductBuyDesc' ) . " </td></tr> \n " ;
2021-02-22 21:36:42 +01:00
if ( $mysoc -> isInEEC ()) {
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_INTRA"' . ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductBuyIntra' ) . '</td>' ;
2020-03-12 12:45:44 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductBuyDesc' ) . " </td></tr> \n " ;
2020-03-01 04:52:12 +01:00
}
2021-01-17 11:46:41 +01:00
print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_EXPORT"' . ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ? ' checked' : '' ) . '> ' . $langs -> trans ( 'OptionModeProductBuyExport' ) . '</td>' ;
2020-03-01 04:52:12 +01:00
print '<td>' . $langs -> trans ( 'OptionModeProductBuyDesc' ) . " </td></tr> \n " ;
2015-08-12 15:53:17 +02:00
print " </table> \n " ;
2017-06-22 14:48:13 +02:00
2020-03-12 12:45:44 +01:00
print '<div class="center"><input type="submit" class="button" value="' . $langs -> trans ( 'Refresh' ) . '" name="changetype"></div>' ;
2017-06-22 14:48:13 +02:00
2016-10-04 20:28:58 +02:00
print " <br> \n " ;
2016-10-21 12:45:19 +02:00
2017-06-22 14:48:13 +02:00
2016-10-21 12:45:19 +02:00
// Filter on categories
2020-03-12 12:45:44 +01:00
$moreforfilter = '' ;
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
2017-06-22 14:48:13 +02:00
2021-11-15 14:35:55 +01:00
if ( $massaction !== 'set_default_account' ) {
$arrayofmassactions = array (
'changeaccount' => img_picto ( '' , 'check' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Save " )
, 'set_default_account' => img_picto ( '' , 'check' , 'class="pictofixedwidth"' ) . $langs -> trans ( " ConfirmPreselectAccount " )
);
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions , 1 );
}
2020-11-19 20:23:38 +01:00
$buttonsave = '<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="' . $langs -> trans ( " Save " ) . '">' ;
2020-10-31 14:32:18 +01:00
//print '<br><div class="center">'.$buttonsave.'</div>';
2019-05-03 14:08:20 +02:00
2020-03-12 12:45:44 +01:00
$texte = $langs -> trans ( " ListOfProductsServices " );
2021-11-15 14:35:55 +01:00
print_barre_liste ( $texte , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , '' , 0 , '' , '' , $limit , 0 , 0 , 1 );
if ( $massaction == 'set_default_account' ) {
$formquestion [] = array ( 'type' => 'other' ,
'name' => 'set_default_account' ,
'label' => $langs -> trans ( " AccountancyCode " ),
'value' => $form -> select_account ( '' , 'default_account' , 1 , array (), 0 , 0 , 'maxwidth200 maxwidthonsmartphone' , 'cachewithshowemptyone' ));
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ], $langs -> trans ( " ConfirmPreselectAccount " ), $langs -> trans ( " ConfirmPreselectAccountQuestion " , count ( $chk_prod )), " confirm_set_default_account " , $formquestion , 1 , 0 , 200 , 500 , 1 );
}
2017-06-22 14:48:13 +02:00
2022-04-28 05:34:02 +02:00
// Filter on categories
$moreforfilter = '' ;
2022-08-24 10:26:27 +02:00
if ( isModEnabled ( 'categorie' ) && $user -> rights -> categorie -> lire ) {
2022-04-28 05:34:02 +02:00
$moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= img_picto ( $langs -> trans ( 'Categories' ), 'category' , 'class="pictofixedwidth"' );
$categoriesProductArr = $form -> select_all_categories ( Categorie :: TYPE_PRODUCT , '' , '' , 64 , 0 , 1 );
$categoriesProductArr [ - 2 ] = '- ' . $langs -> trans ( 'NotCategorized' ) . ' -' ;
$moreforfilter .= Form :: multiselectarray ( 'search_category_product_list' , $categoriesProductArr , $searchCategoryProductList , 0 , 0 , 'minwidth300' );
$moreforfilter .= ' <input type="checkbox" class="valignmiddle" name="search_category_product_operator" value="1"' . ( $searchCategoryProductOperator == 1 ? ' checked="checked"' : '' ) . '/> <span class="none">' . $langs -> trans ( 'UseOrOperatorForCategories' ) . '</span>' ;
$moreforfilter .= '</div>' ;
}
//Show/hide child products. Hidden by default
2022-08-24 10:26:27 +02:00
if ( isModEnabled ( 'variants' ) && ! empty ( $conf -> global -> PRODUIT_ATTRIBUTES_HIDECHILD )) {
2022-04-28 05:34:02 +02:00
$moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= '<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"' . ( $show_childproducts ? 'checked="checked"' : '' ) . '>' ;
$moreforfilter .= ' <label for="search_show_childproducts">' . $langs -> trans ( 'ShowChildProducts' ) . '</label>' ;
$moreforfilter .= '</div>' ;
}
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook )) {
$moreforfilter .= $hookmanager -> resPrint ;
} else {
$moreforfilter = $hookmanager -> resPrint ;
}
if ( $moreforfilter ) {
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
}
2017-09-05 20:42:34 +02:00
print '<div class="div-table-responsive">' ;
2020-03-12 12:45:44 +01:00
print '<table class="liste ' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' ;
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">' ;
2020-03-12 12:45:44 +01:00
print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="' . dol_escape_htmltag ( $search_ref ) . '"></td>' ;
print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . dol_escape_htmltag ( $search_label ) . '"></td>' ;
2020-09-28 11:08:27 +02:00
print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" size="5" name="search_vat" placeholder="%" value="' . dol_escape_htmltag ( $search_vat ) . '"></td>' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_SHOW_PROD_DESC )) {
print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="' . dol_escape_htmltag ( $search_desc ) . '"></td>' ;
}
2016-11-04 15:43:30 +01:00
// On sell
2019-11-11 19:42:54 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ) {
2019-12-16 19:40:18 +01:00
print '<td class="liste_titre center">' . $form -> selectyesno ( 'search_onsell' , $search_onsell , 1 , false , 1 ) . '</td>' ;
2021-03-18 17:08:55 +01:00
} else {
2021-02-22 21:36:42 +01:00
// On buy
2019-12-16 19:40:18 +01:00
print '<td class="liste_titre center">' . $form -> selectyesno ( 'search_onpurchase' , $search_onpurchase , 1 , false , 1 ) . '</td>' ;
2019-11-11 19:42:54 +01:00
}
2016-11-04 15:43:30 +01:00
// Current account
print '<td class="liste_titre">' ;
2020-03-12 12:45:44 +01:00
print '<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="' . dol_escape_htmltag ( $search_current_account ) . '">' ;
$listofvals = array ( 'withoutvalidaccount' => $langs -> trans ( " WithoutValidAccount " ), 'withvalidaccount' => $langs -> trans ( " WithValidAccount " ));
2016-11-04 15:43:30 +01:00
print ' ' . $langs -> trans ( " or " ) . ' ' . $form -> selectarray ( 'search_current_account_valid' , $listofvals , $search_current_account_valid , 1 );
print '</td>' ;
print '<td class="liste_titre"> </td>' ;
2019-03-03 10:31:46 +01:00
print '<td class="center liste_titre">' ;
2020-03-12 12:45:44 +01:00
$searchpicto = $form -> showFilterButtons ();
2017-05-14 21:06:33 +02:00
print $searchpicto ;
2015-08-06 21:23:02 +02:00
print '</td>' ;
print '</tr>' ;
2017-06-22 14:48:13 +02:00
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Ref " , $_SERVER [ " PHP_SELF " ], " p.ref " , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Label " , $_SERVER [ " PHP_SELF " ], " p.label " , " " , $param , '' , $sortfield , $sortorder );
2021-02-22 21:36:42 +01:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_SHOW_PROD_DESC )) {
print_liste_field_titre ( " Description " , $_SERVER [ " PHP_SELF " ], " p.description " , " " , $param , '' , $sortfield , $sortorder );
}
2020-09-28 11:08:27 +02:00
print_liste_field_titre ( " VATRate " , $_SERVER [ " PHP_SELF " ], " p.tva_tx " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
// On sell / On purchase
2021-03-18 17:08:55 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ) {
2020-10-31 14:32:18 +01:00
print_liste_field_titre ( " OnSell " , $_SERVER [ " PHP_SELF " ], " p.tosell " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
2021-03-18 17:08:55 +01:00
} else {
2020-10-31 14:32:18 +01:00
print_liste_field_titre ( " OnBuy " , $_SERVER [ " PHP_SELF " ], " p.tobuy " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
2020-03-01 04:52:12 +01:00
}
2021-04-14 04:45:17 +02:00
print_liste_field_titre ( " CurrentDedicatedAccountingAccount " , $_SERVER [ " PHP_SELF " ], ( empty ( $conf -> global -> MAIN_PRODUCT_PERENTITY_SHARED ) ? " p. " : " ppe. " ) . $accountancy_field_name , " " , $param , '' , $sortfield , $sortorder );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " AssignDedicatedAccountingAccount " );
2020-03-12 12:45:44 +01:00
$clickpitco = $form -> showCheckAddButtons ( 'checkforselect' , 1 );
2019-03-03 10:31:46 +01:00
print_liste_field_titre ( $clickpitco , '' , '' , '' , '' , '' , '' , '' , 'center ' );
2017-04-01 12:46:47 +02:00
print '</tr>' ;
2017-06-22 14:48:13 +02:00
2016-11-04 15:43:30 +01:00
$product_static = new Product ( $db );
2017-06-22 14:48:13 +02:00
2020-03-12 12:45:44 +01:00
$i = 0 ;
2021-02-22 21:36:42 +01:00
while ( $i < min ( $num , $limit )) {
2022-05-15 22:29:19 +02:00
$obj = $db -> fetch_object ( $resql );
2016-11-04 15:43:30 +01:00
// Ref produit as link
$product_static -> ref = $obj -> ref ;
$product_static -> id = $obj -> rowid ;
$product_static -> type = $obj -> product_type ;
$product_static -> label = $obj -> label ;
$product_static -> description = $obj -> description ;
$product_static -> status = $obj -> tosell ;
$product_static -> status_buy = $obj -> tobuy ;
2017-06-22 14:48:13 +02:00
2019-11-11 19:05:42 +01:00
// Sales
if ( $obj -> product_type == 0 ) {
if ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ) {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_SOLD_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2019-11-11 19:05:42 +01:00
$compta_prodsell_id = $aarowid_prodsell ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ) {
2020-10-31 14:32:18 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
$compta_prodsell_id = $aarowid_prodsell_intra ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ) {
2020-10-31 14:32:18 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
$compta_prodsell_id = $aarowid_prodsell_export ;
} else {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_SOLD_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodsell_id = $aarowid_prodsell ;
2019-11-11 19:05:42 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-11 19:05:42 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ) {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_SOLD_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodsell_id = $aarowid_servsell ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ) {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodsell_id = $aarowid_servsell_intra ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ) {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodsell_id = $aarowid_servsell_export ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-12 12:45:44 +01:00
$compta_prodsell = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_SOLD_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2019-11-11 19:05:42 +01:00
$compta_prodsell_id = $aarowid_servsell ;
}
2015-08-12 15:53:17 +02:00
}
2017-06-22 14:48:13 +02:00
2019-11-11 19:05:42 +01:00
// Purchases
2015-08-12 15:53:17 +02:00
if ( $obj -> product_type == 0 ) {
2020-03-01 04:52:12 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_BUY_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-01 04:52:12 +01:00
$compta_prodbuy_id = $aarowid_prodbuy ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-01 04:52:12 +01:00
$compta_prodbuy_id = $aarowid_prodbuy_intra ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-01 04:52:12 +01:00
$compta_prodbuy_id = $aarowid_prodbuy_export ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_PRODUCT_BUY_ACCOUNT ) ? $conf -> global -> ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodbuy_id = $aarowid_prodbuy ;
2020-03-01 04:52:12 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-03-01 04:52:12 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_BUY_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodbuy_id = $aarowid_servbuy ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodbuy_id = $aarowid_servbuy_intra ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ) {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-03 05:16:14 +01:00
$compta_prodbuy_id = $aarowid_servbuy_export ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-12 12:45:44 +01:00
$compta_prodbuy = ( ! empty ( $conf -> global -> ACCOUNTING_SERVICE_BUY_ACCOUNT ) ? $conf -> global -> ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs -> trans ( " CodeNotDef " ));
2020-03-01 04:52:12 +01:00
$compta_prodbuy_id = $aarowid_servbuy ;
}
2015-08-12 15:53:17 +02:00
}
2017-06-22 14:48:13 +02:00
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">' ;
2017-06-22 14:48:13 +02:00
2015-08-06 21:23:02 +02:00
print '<td>' ;
2016-11-04 15:43:30 +01:00
print $product_static -> getNomUrl ( 1 );
2015-08-06 21:23:02 +02:00
print '</td>' ;
2017-06-22 14:48:13 +02:00
2019-01-16 19:19:14 +01:00
print '<td class="left">' . $obj -> label . '</td>' ;
2017-06-22 14:48:13 +02:00
2021-02-22 21:36:42 +01:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_SHOW_PROD_DESC )) {
2020-10-31 14:32:18 +01:00
// TODO ADJUST DESCRIPTION SIZE
// print '<td class="left">' . $obj->description . '</td>';
// TODO: we should set a user defined value to adjust user square / wide screen size
$trunclength = empty ( $conf -> global -> ACCOUNTING_LENGTH_DESCRIPTION ) ? 32 : $conf -> global -> ACCOUNTING_LENGTH_DESCRIPTION ;
print '<td>' . nl2br ( dol_trunc ( $obj -> description , $trunclength )) . '</td>' ;
2016-10-22 14:05:04 +02:00
}
2017-06-22 14:48:13 +02:00
2020-09-28 11:08:27 +02:00
// VAT
print '<td class="right">' ;
print vatrate ( $obj -> tva_tx );
print '</td>' ;
2021-03-18 17:08:55 +01:00
// On sell / On purchase
2021-02-22 21:36:42 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ) {
2019-03-03 10:31:46 +01:00
print '<td class="center">' . $product_static -> getLibStatut ( 3 , 0 ) . '</td>' ;
2021-03-18 17:08:55 +01:00
} else {
2019-03-03 10:31:46 +01:00
print '<td class="center">' . $product_static -> getLibStatut ( 3 , 1 ) . '</td>' ;
2021-02-22 21:36:42 +01:00
}
2017-06-22 14:48:13 +02:00
2016-11-04 15:43:30 +01:00
// Current accounting account
2019-01-16 19:19:54 +01:00
print '<td class="left">' ;
2016-11-04 15:43:30 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ) {
2020-10-31 14:32:18 +01:00
print length_accountg ( $obj -> accountancy_code_buy );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_buy && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2020-03-01 04:52:12 +01:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ) {
2020-10-31 14:32:18 +01:00
print length_accountg ( $obj -> accountancy_code_buy_intra );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_buy_intra && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2020-10-31 14:32:18 +01:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ) {
print length_accountg ( $obj -> accountancy_code_buy_export );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_buy_export && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2020-10-31 14:32:18 +01:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ) {
print length_accountg ( $obj -> accountancy_code_sell );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_sell && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2020-10-31 14:32:18 +01:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ) {
print length_accountg ( $obj -> accountancy_code_sell_intra );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_sell_intra && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2019-05-03 14:08:20 +02:00
} else {
2020-10-31 14:32:18 +01:00
print length_accountg ( $obj -> accountancy_code_sell_export );
2021-02-22 21:36:42 +01:00
if ( $obj -> accountancy_code_sell_export && empty ( $obj -> aaid )) {
print ' ' . img_warning ( $langs -> trans ( " ValueNotIntoChartOfAccount " ));
}
2020-10-31 14:32:18 +01:00
}
2016-11-04 15:43:30 +01:00
print '</td>' ;
2017-06-22 14:48:13 +02:00
2019-11-11 19:05:42 +01:00
// New account to set
2020-03-12 12:45:44 +01:00
$defaultvalue = '' ;
2016-02-01 15:07:12 +01:00
if ( $accounting_product_mode == 'ACCOUNTANCY_BUY' ) {
2020-10-31 14:32:18 +01:00
// Accounting account buy
2019-01-16 19:19:54 +01:00
print '<td class="left">' ;
2016-11-04 15:43:30 +01:00
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodbuy ;
}
2020-03-12 12:45:44 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_buy );
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2015-08-12 15:53:17 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ) {
2020-03-01 04:52:12 +01:00
// Accounting account buy intra (In EEC)
print '<td class="left">' ;
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodbuy ;
}
2020-03-12 12:45:44 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_buy_intra );
2020-03-01 04:52:12 +01:00
//var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2020-03-01 04:52:12 +01:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ) {
2020-03-01 04:52:12 +01:00
// Accounting account buy export (Out of EEC)
print '<td class="left">' ;
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodbuy ;
}
2020-03-12 12:45:44 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_buy_export );
2020-03-01 04:52:12 +01:00
//var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2020-03-01 04:52:12 +01:00
print '</td>' ;
2019-05-03 14:08:20 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL' ) {
2015-12-21 06:51:46 +01:00
// Accounting account sell
2019-01-16 19:20:28 +01:00
print '<td class="left">' ;
2016-11-04 15:43:30 +01:00
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodsell ;
}
2020-03-12 12:45:44 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_sell );
2016-11-04 15:43:30 +01:00
//var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2015-08-12 15:53:17 +02:00
print '</td>' ;
2019-05-03 14:08:20 +02:00
} elseif ( $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ) {
2020-10-31 14:32:18 +01:00
// Accounting account sell intra (In EEC)
print '<td class="left">' ;
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodsell ;
}
2020-10-31 14:32:18 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_sell_intra );
//var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2020-10-31 14:32:18 +01:00
print '</td>' ;
} else {
// Accounting account sell export (Out of EEC)
print '<td class="left">' ;
//$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
2021-02-22 21:36:42 +01:00
if ( empty ( $defaultvalue )) {
$defaultvalue = $compta_prodsell ;
}
2020-10-31 14:32:18 +01:00
$codesell = length_accountg ( $obj -> accountancy_code_sell_export );
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> aaid )) {
$defaultvalue = '' ; // Do not suggest default new value is code is already valid
}
2021-11-15 14:35:55 +01:00
print $form -> select_account (( $default_account > 0 && $confirm === 'yes' && in_array ( $product_static -> id , $chk_prod )) ? $default_account : $defaultvalue , 'codeventil_' . $product_static -> id , 1 , array (), 1 , 0 , 'maxwidth300 maxwidthonsmartphone productforselect' );
2020-10-31 14:32:18 +01:00
print '</td>' ;
}
2017-06-22 14:48:13 +02:00
2021-11-15 14:35:55 +01:00
if ( ! empty ( $chk_prod )) {
$ischecked = 0 ;
if ( in_array ( $product_static -> id , $chk_prod )) {
$ischecked = true ;
}
}
2015-08-12 15:53:17 +02:00
// Checkbox select
2019-03-03 10:31:46 +01:00
print '<td class="center">' ;
2021-11-15 14:35:55 +01:00
print '<input type="checkbox" class="checkforselect productforselectcodeventil_' . $product_static -> id . '" name="chk_prod[]" ' . ( $ischecked ? " checked " : " " ) . ' value="' . $obj -> rowid . '"/></td>' ;
2015-08-06 21:23:02 +02:00
print " </tr> " ;
2020-03-12 12:45:44 +01:00
$i ++ ;
2015-08-06 21:23:02 +02:00
}
2015-08-12 15:53:17 +02:00
print '</table>' ;
2017-09-05 20:42:34 +02:00
print '</div>' ;
2017-06-22 14:48:13 +02:00
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2016-11-04 15:43:30 +01:00
jQuery ( document ) . ready ( function () {
function init_savebutton ()
{
console . log ( " We check if at least one line is checked " )
2019-02-12 12:50:36 +01:00
atleastoneselected = 0 ;
2016-11-04 15:43:30 +01:00
jQuery ( " .checkforselect " ) . each ( function ( index ) {
/* console.log( index + ": " + $( this ).text() ); */
2019-02-12 12:51:52 +01:00
if ( $ ( this ) . is ( \ ' : checked\ ' )) atleastoneselected ++ ;
2016-11-04 15:43:30 +01:00
});
2017-06-22 14:48:13 +02:00
2019-02-12 12:51:52 +01:00
if ( atleastoneselected ) jQuery ( " #changeaccount " ) . removeAttr ( \ ' disabled\ ' );
2016-11-04 15:43:30 +01:00
else jQuery ( " #changeaccount " ) . attr ( \ ' disabled\ ' , \ ' disabled\ ' );
2019-04-19 18:45:01 +02:00
if ( atleastoneselected ) jQuery ( " #changeaccount " ) . attr ( \ ' class\ ' , \ ' button\ ' );
else jQuery ( " #changeaccount " ) . attr ( \ ' class\ ' , \ ' button\ ' );
2016-11-04 15:43:30 +01:00
}
2020-11-01 14:34:29 +01:00
jQuery ( " .checkforselect " ) . change ( function () {
init_savebutton ();
});
jQuery ( " .productforselect " ) . change ( function () {
console . log ( $ ( this ) . attr ( " id " ) + " " + $ ( this ) . val ());
if ( $ ( this ) . val () && $ ( this ) . val () != - 1 ) {
$ ( " .productforselect " + $ ( this ) . attr ( " id " )) . prop ( \ ' checked\ ' , true );
} else {
$ ( " .productforselect " + $ ( this ) . attr ( " id " )) . prop ( \ ' checked\ ' , false );
}
2016-11-04 15:43:30 +01:00
init_savebutton ();
});
init_savebutton ();
2019-03-25 16:47:20 +01:00
jQuery ( " #search_current_account " ) . keyup ( function () {
if ( jQuery ( " #search_current_account " ) . val () != \ ' \ ' )
{
console . log ( " We set a value of account to search " + jQuery ( " #search_current_account " ) . val () + " , so we disable the other search criteria on account " );
jQuery ( " #search_current_account_valid " ) . val ( - 1 );
}
});
2016-11-04 15:43:30 +01:00
});
</ script > ' ;
2017-06-22 14:48:13 +02:00
2015-08-12 15:53:17 +02:00
print '</form>' ;
2017-06-22 14:48:13 +02:00
2022-05-15 22:29:19 +02:00
$db -> free ( $resql );
2014-08-27 07:03:42 +02:00
} else {
2015-08-06 21:23:02 +02:00
dol_print_error ( $db );
2014-08-27 07:03:42 +02:00
}
2018-07-28 14:02:33 +02:00
// End of page
2014-08-27 07:03:42 +02:00
llxFooter ();
2018-05-26 23:52:52 +02:00
$db -> close ();