2014-02-23 16:16:47 +01:00
< ? php
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2015-06-20 23:33:13 +02:00
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-02-23 16:16:47 +01:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
2014-02-23 16:16:47 +01:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2015-02-27 15:08:08 +01:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2014-02-23 16:16:47 +01: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-02-23 16:16:47 +01:00
*/
/**
2017-07-04 17:37:28 +02:00
* \file htdocs / societe / price . php
2014-02-23 17:01:51 +01:00
* \ingroup product
2017-07-04 17:37:28 +02:00
* \brief Page to show product prices by customer
2014-02-23 16:16:47 +01:00
*/
2017-07-04 17:37:28 +02:00
2014-02-23 16:16:47 +01:00
require '../main.inc.php' ;
2019-11-13 19:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2014-02-23 16:16:47 +01:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php' ;
2014-09-07 12:22:04 +02:00
2014-02-23 17:01:51 +01:00
$prodcustprice = new Productcustomerprice ( $db );
2014-02-23 16:16:47 +01:00
}
2018-10-01 08:22:23 +02:00
$langs -> loadLangs ( array ( " products " , " companies " , " bills " ));
2014-02-23 16:16:47 +01:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-01-27 11:55:16 +01:00
$search_prod = GETPOST ( 'search_prod' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2016-08-08 14:44:49 +02:00
$search_label = GETPOST ( 'search_label' , 'alpha' );
$search_price = GETPOST ( 'search_price' );
$search_price_ttc = GETPOST ( 'search_price_ttc' );
2014-02-23 16:16:47 +01:00
// Security check
2019-11-13 19:35:02 +01:00
$socid = GETPOST ( 'socid' , 'int' ) ? GETPOST ( 'socid' , 'int' ) : GETPOST ( 'id' , 'int' );
2021-02-26 21:17:52 +01:00
if ( $user -> socid ) {
2019-10-31 20:46:31 +01:00
$socid = $user -> socid ;
2021-02-26 21:17:52 +01:00
}
2014-02-23 16:16:47 +01:00
$result = restrictedArea ( $user , 'societe' , $socid , '&societe' );
2015-12-23 14:31:42 +01:00
$object = new Societe ( $db );
2015-11-03 11:40:06 +01:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-13 19:35:02 +01:00
$hookmanager -> initHooks ( array ( 'thirdpartycustomerprice' , 'globalcard' ));
2014-09-07 12:22:04 +02:00
2020-06-18 19:21:21 +02:00
$error = 0 ;
2014-09-07 12:22:04 +02:00
2015-12-23 14:31:42 +01:00
/*
* Actions
*/
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
$parameters = array ( 'id' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 21:17:52 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-09-07 12:22:04 +02:00
2021-02-26 21:17:52 +01:00
if ( empty ( $reshook )) {
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // Both test are required to be compatible with all browsers
2020-10-07 15:01:28 +02:00
$search_prod = $search_label = $search_price = $search_price_ttc = '' ;
}
if ( $action == 'add_customer_price_confirm' && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2020-10-31 14:32:18 +01:00
if ( ! ( GETPOST ( 'prodid' , 'int' ) > 0 )) {
2020-10-07 15:01:28 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " Product " )), null , 'errors' );
$action = 'add_customer_price' ;
}
2020-10-31 14:32:18 +01:00
if ( ! $error ) {
2020-10-07 15:01:28 +02:00
$update_child_soc = GETPOST ( 'updatechildprice' );
// add price by customer
$prodcustprice -> fk_soc = $socid ;
2020-10-26 12:18:24 +01:00
$prodcustprice -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
2020-10-07 15:01:28 +02:00
$prodcustprice -> fk_product = GETPOST ( 'prodid' , 'int' );
$prodcustprice -> price = price2num ( GETPOST ( " price " ), 'MU' );
$prodcustprice -> price_min = price2num ( GETPOST ( " price_min " ), 'MU' );
$prodcustprice -> price_base_type = GETPOST ( " price_base_type " , 'alpha' );
$tva_tx_txt = GETPOST ( 'tva_tx' , 'alpha' ); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
// We must define tva_tx, npr and local taxes
$vatratecode = '' ;
$tva_tx = preg_replace ( '/[^0-9\.].*$/' , '' , $tva_tx_txt ); // keep remove all after the numbers and dot
$npr = preg_match ( '/\*/' , $tva_tx_txt ) ? 1 : 0 ;
$localtax1 = 0 ; $localtax2 = 0 ; $localtax1_type = '0' ; $localtax2_type = '0' ;
// If value contains the unique code of vat line (new recommended method), we use it to find npr and local taxes
2021-02-26 21:17:52 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2020-10-07 15:01:28 +02:00
// We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
$vatratecode = $reg [ 1 ];
// Get record from code
$sql = " SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $db -> escape ( $mysoc -> country_code ) . " ' " ;
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
$sql .= " AND t.code =' " . $db -> escape ( $vatratecode ) . " ' " ;
$resql = $db -> query ( $sql );
2021-02-26 21:17:52 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
}
$prodcustprice -> default_vat_code = $vatratecode ;
$prodcustprice -> tva_tx = $tva_tx ;
$prodcustprice -> recuperableonly = $npr ;
$prodcustprice -> localtax1_tx = $localtax1 ;
$prodcustprice -> localtax2_tx = $localtax2 ;
$prodcustprice -> localtax1_type = $localtax1_type ;
$prodcustprice -> localtax2_type = $localtax2_type ;
$result = $prodcustprice -> create ( $user , 0 , $update_child_soc );
if ( $result < 0 ) {
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
} else {
2020-11-23 15:12:52 +01:00
setEventMessages ( $langs -> trans ( " Save " ), null , 'mesgs' );
2020-10-07 15:01:28 +02:00
}
$action = '' ;
}
}
if ( $action == 'delete_customer_price' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
// Delete price by customer
2021-03-14 12:20:23 +01:00
$prodcustprice -> id = GETPOST ( 'lineid' , 'int' );
2020-10-07 15:01:28 +02:00
$result = $prodcustprice -> delete ( $user );
if ( $result < 0 ) {
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( 'Delete' ), null , 'errors' );
}
$action = '' ;
}
2022-02-22 23:44:56 +01:00
if ( $action == 'update_customer_price_confirm' && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2020-10-07 15:01:28 +02:00
$prodcustprice -> fetch ( GETPOST ( 'lineid' , 'int' ));
$update_child_soc = GETPOST ( 'updatechildprice' );
// update price by customer
2020-10-26 12:18:24 +01:00
$prodcustprice -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
2020-10-07 15:01:28 +02:00
$prodcustprice -> price = price2num ( GETPOST ( " price " ), 'MU' );
$prodcustprice -> price_min = price2num ( GETPOST ( " price_min " ), 'MU' );
$prodcustprice -> price_base_type = GETPOST ( " price_base_type " , 'alpha' );
$prodcustprice -> tva_tx = str_replace ( '*' , '' , GETPOST ( " tva_tx " ));
$prodcustprice -> recuperableonly = ( preg_match ( '/\*/' , GETPOST ( " tva_tx " )) ? 1 : 0 );
$result = $prodcustprice -> update ( $user , 0 , $update_child_soc );
if ( $result < 0 ) {
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
} else {
2020-11-23 15:12:52 +01:00
setEventMessages ( $langs -> trans ( " Save " ), null , 'mesgs' );
2020-10-07 15:01:28 +02:00
}
$action = '' ;
}
2014-02-23 16:16:47 +01:00
}
2015-11-03 11:40:06 +01:00
2014-02-23 16:16:47 +01:00
/*
* View
*/
$form = new Form ( $db );
2015-10-13 13:06:32 +02:00
$object = new Societe ( $db );
2014-02-23 16:16:47 +01:00
2015-10-13 13:06:32 +02:00
$result = $object -> fetch ( $socid );
2019-11-13 19:35:02 +01:00
llxHeader ( " " , $langs -> trans ( " ThirdParty " ) . '-' . $langs -> trans ( 'PriceByCustomer' ));
2014-02-23 16:16:47 +01:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> notification -> enabled )) {
2014-02-23 17:01:51 +01:00
$langs -> load ( " mails " );
2021-02-26 21:17:52 +01:00
}
2015-10-13 13:06:32 +02:00
$head = societe_prepare_head ( $object );
2014-02-23 16:16:47 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'price' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
2014-02-23 16:16:47 +01:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-09-18 14:12:49 +02:00
2019-11-13 19:35:02 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2017-07-04 17:37:28 +02:00
2015-10-13 13:06:32 +02:00
print '<div class="fichecenter">' ;
2014-02-23 16:16:47 +01:00
2015-10-13 13:06:32 +02:00
print '<div class="underbanner clearboth"></div>' ;
2021-05-18 17:24:17 +02:00
print '<table class="border centpercent tableforfield">' ;
2014-02-23 16:16:47 +01:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_USEPREFIX )) { // Old not used prefix field
2019-11-13 19:35:02 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Prefix' ) . '</td><td colspan="3">' . $object -> prefix_comm . '</td></tr>' ;
2014-02-23 16:16:47 +01:00
}
2015-10-13 13:06:32 +02:00
if ( $object -> client ) {
2017-07-11 13:25:41 +02:00
print '<tr><td class="titlefield">' ;
2019-11-13 19:35:02 +01:00
print $langs -> trans ( 'CustomerCode' ) . '</td><td colspan="3">' ;
2015-10-13 13:06:32 +02:00
print $object -> code_client ;
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codeclient ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongCustomerCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
}
2015-10-13 13:06:32 +02:00
if ( $object -> fournisseur ) {
2017-07-11 13:25:41 +02:00
print '<tr><td class="titlefield">' ;
2019-11-13 19:35:02 +01:00
print $langs -> trans ( 'SupplierCode' ) . '</td><td colspan="3">' ;
2015-10-13 13:06:32 +02:00
print $object -> code_fournisseur ;
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codefournisseur ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongSupplierCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
}
print '</table>' ;
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-10-13 13:06:32 +02:00
2015-10-24 19:29:41 +02:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2014-02-23 17:01:51 +01:00
$prodcustprice = new Productcustomerprice ( $db );
2014-09-07 12:22:04 +02:00
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-10-07 15:01:28 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 21:17:52 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2015-12-16 19:38:40 +01:00
$offset = $limit * $page ;
2014-02-23 16:16:47 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 21:17:52 +01:00
if ( ! $sortorder ) {
2014-02-23 16:16:47 +01:00
$sortorder = " ASC " ;
2021-02-26 21:17:52 +01:00
}
if ( ! $sortfield ) {
2014-02-23 16:16:47 +01:00
$sortfield = " soc.nom " ;
2021-02-26 21:17:52 +01:00
}
2014-09-07 12:22:04 +02:00
2019-02-10 12:59:09 +01:00
// Build filter to display only concerned lines
2019-11-13 19:35:02 +01:00
$filter = array (
2015-10-13 13:06:32 +02:00
't.fk_soc' => $object -> id
2014-02-23 16:16:47 +01:00
);
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $search_prod )) {
2016-02-12 12:06:23 +01:00
$filter [ 'prod.ref' ] = $search_prod ;
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2020-10-07 15:01:28 +02:00
if ( ! empty ( $search_label )) {
2016-08-08 14:44:49 +02:00
$filter [ 'prod.label' ] = $search_label ;
}
2020-10-07 15:01:28 +02:00
if ( ! empty ( $search_price )) {
2016-08-08 14:44:49 +02:00
$filter [ 't.price' ] = $search_price ;
}
2020-10-07 15:01:28 +02:00
if ( ! empty ( $search_price_ttc )) {
2016-08-08 14:44:49 +02:00
$filter [ 't.price_ttc' ] = $search_price_ttc ;
}
2014-02-23 16:16:47 +01:00
if ( $action == 'add_customer_price' ) {
// Create mode
2014-09-07 12:22:04 +02:00
2020-06-18 19:21:21 +02:00
print '<br>' ;
print '<!-- Price by customer -->' . " \n " ;
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'PriceByCustomer' ));
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="POST">' ;
2020-03-24 13:10:35 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2014-02-23 16:16:47 +01:00
print '<input type="hidden" name="action" value="add_customer_price_confirm">' ;
2019-11-13 19:35:02 +01:00
print '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2014-02-23 16:16:47 +01:00
print '<tr>' ;
2019-11-13 19:35:02 +01:00
print '<td>' . $langs -> trans ( 'Product' ) . '</td>' ;
2014-02-23 16:16:47 +01:00
print '<td>' ;
2019-11-28 21:23:53 +01:00
$form -> select_produits ( '' , 'prodid' , '' , 0 );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2020-10-26 12:18:24 +01:00
// Ref. Customer
2021-01-05 16:01:31 +01:00
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2020-10-26 12:18:24 +01:00
print '<td><input name="ref_customer" size="12"></td></tr>' ;
2014-02-23 16:16:47 +01:00
// VAT
2019-11-13 19:35:02 +01:00
print '<tr><td>' . $langs -> trans ( " VATRate " ) . '</td><td>' ;
2017-07-04 17:37:28 +02:00
print $form -> load_tva ( " tva_tx " , $object -> tva_tx , $mysoc , '' , $object -> id , $object -> tva_npr , '' , false , 1 );
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Price base
print '<tr><td width="15%">' ;
2014-02-23 17:01:51 +01:00
print $langs -> trans ( 'PriceBase' );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '<td>' ;
2015-06-06 14:21:18 +02:00
print $form -> selectPriceBaseType ( $object -> price_base_type , " price_base_type " );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Price
print '<tr><td width="20%">' ;
2014-02-23 17:01:51 +01:00
$text = $langs -> trans ( 'SellingPrice' );
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $text , $langs -> trans ( " PrecisionUnitIsLimitedToXDecimals " , $conf -> global -> MAIN_MAX_DECIMALS_UNIT ), 1 , 1 );
2014-02-23 16:16:47 +01:00
print '</td><td>' ;
2021-10-21 19:18:01 +02:00
print '<input name="price" size="10" value="' . GETPOST ( 'price' , 'int' ) . '">' ;
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Price minimum
print '<tr><td>' ;
2014-02-23 17:01:51 +01:00
$text = $langs -> trans ( 'MinPrice' );
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $text , $langs -> trans ( " PrecisionUnitIsLimitedToXDecimals " , $conf -> global -> MAIN_MAX_DECIMALS_UNIT ), 1 , 1 );
2021-10-21 19:18:01 +02:00
print '<td><input name="price_min" size="10" value="' . GETPOST ( 'price_min' , 'int' ) . '">' ;
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Update all child soc
print '<tr><td width="15%">' ;
2014-02-23 17:01:51 +01:00
print $langs -> trans ( 'ForceUpdateChildPriceSoc' );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '<td>' ;
print '<input type="checkbox" name="updatechildprice" value="1"/>' ;
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2014-09-07 12:22:04 +02:00
2021-08-20 14:41:30 +02:00
print '</form>' ;
2014-02-23 16:16:47 +01:00
} elseif ( $action == 'edit_customer_price' ) {
// Edit mode
2014-09-07 12:22:04 +02:00
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'PriceByCustomer' ));
2014-09-07 12:22:04 +02:00
2014-02-23 17:01:51 +01:00
$result = $prodcustprice -> fetch ( GETPOST ( 'lineid' , 'int' ));
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
if ( $result <= 0 ) {
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
} else {
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="update_customer_price_confirm">' ;
print '<input type="hidden" name="lineid" value="' . $prodcustprice -> id . '">' ;
print '<table class="border centpercent">' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( 'Product' ) . '</td>' ;
$staticprod = new Product ( $db );
$staticprod -> fetch ( $prodcustprice -> fk_product );
print " <td> " . $staticprod -> getNomUrl ( 1 ) . " </td> " ;
print '</tr>' ;
2020-10-26 12:18:24 +01:00
2021-03-14 18:07:53 +01:00
// Ref. Customer
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2021-10-25 22:07:31 +02:00
print '<td><input name="ref_customer" size="12" value="' . dol_escape_htmltag ( $prodcustprice -> ref_customer ) . '"></td></tr>' ;
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
// VAT
print '<tr><td>' . $langs -> trans ( " VATRate " ) . '</td><td>' ;
print $form -> load_tva ( " tva_tx " , $prodcustprice -> tva_tx , $mysoc , '' , $staticprod -> id , $prodcustprice -> recuperableonly );
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
// Price base
print '<tr><td width="15%">' ;
print $langs -> trans ( 'PriceBase' );
print '</td>' ;
print '<td>' ;
print $form -> selectPriceBaseType ( $prodcustprice -> price_base_type , " price_base_type " );
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
// Price
print '<tr><td>' ;
$text = $langs -> trans ( 'SellingPrice' );
print $form -> textwithpicto ( $text , $langs -> trans ( " PrecisionUnitIsLimitedToXDecimals " , $conf -> global -> MAIN_MAX_DECIMALS_UNIT ), 1 , 1 );
print '</td><td>' ;
if ( $prodcustprice -> price_base_type == 'TTC' ) {
print '<input name="price" size="10" value="' . price ( $prodcustprice -> price_ttc ) . '">' ;
} else {
print '<input name="price" size="10" value="' . price ( $prodcustprice -> price ) . '">' ;
}
print '</td></tr>' ;
// Price minimum
print '<tr><td>' ;
$text = $langs -> trans ( 'MinPrice' );
print $form -> textwithpicto ( $text , $langs -> trans ( " PrecisionUnitIsLimitedToXDecimals " , $conf -> global -> MAIN_MAX_DECIMALS_UNIT ), 1 , 1 );
print '</td><td>' ;
if ( $prodcustprice -> price_base_type == 'TTC' ) {
print '<input name="price_min" size="10" value="' . price ( $prodcustprice -> price_min_ttc ) . '">' ;
} else {
print '<input name="price_min" size="10" value="' . price ( $prodcustprice -> price_min ) . '">' ;
}
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
// Update all child soc
print '<tr><td>' ;
print $langs -> trans ( 'ForceUpdateChildPriceSoc' );
print '</td>' ;
print '<td>' ;
print '<input type="checkbox" name="updatechildprice" value="1">' ;
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2014-09-07 12:22:04 +02:00
2021-08-20 14:41:30 +02:00
print '</form>' ;
2021-03-14 18:07:53 +01:00
}
2014-02-23 17:01:51 +01:00
} elseif ( $action == 'showlog_customer_price' ) {
2020-10-07 15:01:28 +02:00
print '<br>' ;
2020-06-18 19:21:21 +02:00
print '<!-- showlog_customer_price -->' . " \n " ;
2017-07-04 17:37:28 +02:00
2019-11-13 19:35:02 +01:00
$filter = array (
2021-03-14 18:07:53 +01:00
't.fk_product' => GETPOST ( 'prodid' , 'int' ),
't.fk_soc' => $socid
2014-02-23 17:01:51 +01:00
);
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Count total nb of records
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2014-02-23 17:01:51 +01:00
$result = $prodcustprice -> fetch_all_log ( $sortorder , $sortfield , $conf -> liste_limit , $offset , $filter );
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2015-12-20 10:36:20 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2021-03-14 18:07:53 +01:00
} else {
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
$nbtotalofrecords = $result ;
}
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
$option = '&socid=' . GETPOST ( 'socid' , 'int' ) . '&prodid=' . GETPOST ( 'prodid' , 'int' );
2014-09-07 12:22:04 +02:00
2019-05-15 19:12:33 +02:00
print_barre_liste ( $langs -> trans ( 'PriceByCustomerLog' ), $page , $_SERVER [ 'PHP_SELF' ], $option , $sortfield , $sortorder , '' , count ( $prodcustprice -> lines ), $nbtotalofrecords );
2014-09-07 12:22:04 +02:00
2014-02-23 17:01:51 +01:00
if ( count ( $prodcustprice -> lines ) > 0 ) {
2019-11-13 19:35:02 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-06-18 19:21:21 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 19:35:02 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2014-09-07 12:22:04 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<tr class="liste_titre">' ;
2019-11-13 19:35:02 +01:00
print '<td>' . $langs -> trans ( " Product " ) . '</td>' ;
2021-01-05 16:01:31 +01:00
print '<td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2019-11-13 19:35:02 +01:00
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " VAT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " ChangedBy " ) . '</td>' ;
2021-03-14 18:07:53 +01:00
print '<td></td>' ;
2014-02-23 16:16:47 +01:00
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2019-02-02 18:25:01 +01:00
foreach ( $prodcustprice -> lines as $line ) {
2014-02-23 17:01:51 +01:00
$staticprod = new Product ( $db );
$staticprod -> fetch ( $line -> fk_product );
2014-09-07 12:22:04 +02:00
2021-03-14 18:07:53 +01:00
$userstatic = new User ( $db );
$userstatic -> fetch ( $line -> fk_user );
print '<tr class="oddeven">' ;
2019-11-13 19:35:02 +01:00
print " <td> " . $staticprod -> getNomUrl ( 1 ) . " </td> " ;
2021-01-05 16:01:31 +01:00
print '<td>' . $line -> ref_customer . '</td>' ;
2019-11-13 19:35:02 +01:00
print " <td> " . dol_print_date ( $line -> datec , " dayhour " ) . " </td> " ;
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
print '<td class="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
print '<td class="right">' . vatrate ( $line -> tva_tx , true , $line -> recuperableonly ) . " </td> " ;
print '<td class="right">' . price ( $line -> price ) . " </td> " ;
print '<td class="right">' . price ( $line -> price_ttc ) . " </td> " ;
print '<td class="right">' . price ( $line -> price_min ) . '</td>' ;
print '<td class="right">' . price ( $line -> price_min_ttc ) . '</td>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// User
2019-02-23 21:02:39 +01:00
print '<td class="right">' ;
2021-03-14 18:07:53 +01:00
print $userstatic -> getNomUrl ( - 1 );
2014-02-23 16:16:47 +01:00
print '</td>' ;
2021-03-14 18:07:53 +01:00
print '<td></td>' ;
2014-02-23 17:01:51 +01:00
}
print " </table> " ;
2020-05-21 15:05:19 +02:00
} else {
2014-02-23 17:01:51 +01:00
print $langs -> trans ( 'None' );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2019-11-13 19:35:02 +01:00
print " \n " . '<div class="tabsAction">' . " \n " ;
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '">' . $langs -> trans ( " Ok " ) . '</a></div>' ;
2014-02-23 16:16:47 +01:00
print " \n </div><br> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
// View mode
2014-09-07 12:22:04 +02:00
2021-03-16 04:22:43 +01:00
/*
* Action bar
*/
2019-11-13 19:35:02 +01:00
print " \n " . '<div class="tabsAction">' . " \n " ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2021-10-02 12:58:15 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=add_customer_price&token=' . newToken () . '&socid=' . $object -> id . '">' . $langs -> trans ( " AddCustomerPrice " ) . '</a></div>' ;
2014-02-23 16:16:47 +01:00
}
2015-10-24 16:09:26 +02:00
print " \n </div> \n " ;
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-10-07 15:01:28 +02:00
$nbtotalofrecords = $prodcustprice -> fetch_all ( '' , '' , 0 , 0 , $filter );
}
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
$result = $prodcustprice -> fetch_all ( $sortorder , $sortfield , $conf -> liste_limit , $offset , $filter );
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2020-10-07 15:01:28 +02:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
}
2017-07-04 17:37:28 +02:00
2020-10-31 14:32:18 +01:00
$option = '&search_prod=' . $search_prod . '&id=' . $object -> id . '&label=' . $search_label . '&price=' . $search_price . '&price_ttc=' . $search_price_ttc ;
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
print '<!-- view specific price for each product -->' . " \n " ;
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
print_barre_liste ( $langs -> trans ( 'PriceForEachProduct' ), $page , $_SERVER [ 'PHP_SELF' ], $option , $sortfield , $sortorder , '' , count ( $prodcustprice -> lines ), $nbtotalofrecords , '' );
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2017-07-04 17:37:28 +02:00
2022-07-25 18:03:07 +02:00
print '<div class="div-table-responsive-no-min">' ;
2020-10-07 15:01:28 +02:00
print '<table class="noborder centpercent">' ;
2017-07-04 17:37:28 +02:00
2020-10-07 15:01:28 +02:00
print '<tr class="liste_titre">' ;
2020-10-31 14:32:18 +01:00
print '<td>' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Product " ) . '</td>' ;
2021-01-05 16:01:31 +01:00
print '<td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2020-10-07 15:01:28 +02:00
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " VAT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " ChangedBy " ) . '</td>' ;
2021-03-14 18:07:53 +01:00
print '<td></td>' ;
2020-10-07 15:01:28 +02:00
print '</tr>' ;
2021-02-26 21:17:52 +01:00
if ( count ( $prodcustprice -> lines ) > 0 || $search_prod ) {
2020-10-07 15:01:28 +02:00
print '<tr class="liste_titre">' ;
2022-07-25 18:03:07 +02:00
print '<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="' . $search_prod . '"></td>' ;
print '<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="' . $search_label . '"></td>' ;
2021-03-14 18:07:53 +01:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
2022-07-25 18:03:07 +02:00
print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price" value="' . $search_price . '"></td>' ;
print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price_ttc" value="' . $search_price_ttc . '"></td>' ;
2021-03-14 18:07:53 +01:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
2020-10-07 15:01:28 +02:00
// Print the search button
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
}
2021-02-26 21:17:52 +01:00
if ( count ( $prodcustprice -> lines ) > 0 ) {
foreach ( $prodcustprice -> lines as $line ) {
2020-10-07 15:01:28 +02:00
$staticprod = new Product ( $db );
$staticprod -> fetch ( $line -> fk_product );
2021-03-14 18:07:53 +01:00
$userstatic = new User ( $db );
$userstatic -> fetch ( $line -> fk_user );
print '<tr class="oddeven">' ;
2020-10-07 15:01:28 +02:00
print " <td> " . $staticprod -> getNomUrl ( 1 ) . " </td> " ;
2020-10-31 14:32:18 +01:00
print " <td> " . $staticprod -> label . " </td> " ;
2021-01-05 16:01:31 +01:00
print '<td>' . $line -> ref_customer . '</td>' ;
2020-10-07 15:01:28 +02:00
print " <td> " . dol_print_date ( $line -> datec , " dayhour " ) . " </td> " ;
print '<td class="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
print '<td class="right">' . vatrate ( $line -> tva_tx . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), true , $line -> recuperableonly ) . " </td> " ;
print '<td class="right">' . price ( $line -> price ) . " </td> " ;
print '<td class="right">' . price ( $line -> price_ttc ) . " </td> " ;
print '<td class="right">' . price ( $line -> price_min ) . '</td>' ;
print '<td class="right">' . price ( $line -> price_min_ttc ) . '</td>' ;
// User
print '<td class="right">' ;
2021-03-14 18:07:53 +01:00
print $userstatic -> getNomUrl ( - 1 );
2020-10-07 15:01:28 +02:00
print '</td>' ;
// Action
2021-02-26 21:17:52 +01:00
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2020-10-07 15:01:28 +02:00
print '<td class="right nowraponall">' ;
2021-09-27 12:24:01 +02:00
print '<a class="paddingleftonly paddingrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=showlog_customer_price&token=' . newToken () . '&socid=' . $object -> id . '&prodid=' . $line -> fk_product . '">' ;
2020-10-07 15:01:28 +02:00
print img_info ();
print '</a>' ;
print ' ' ;
2021-09-27 12:24:01 +02:00
print '<a class="editfielda paddingleftonly paddingrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit_customer_price&token=' . newToken () . '&socid=' . $object -> id . '&lineid=' . $line -> id . '">' ;
2020-10-07 15:01:28 +02:00
print img_edit ( 'default' , 0 , 'style="vertical-align: middle;"' );
print '</a>' ;
print ' ' ;
2021-09-18 22:04:41 +02:00
print '<a class="paddingleftonly paddingrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete_customer_price&token=' . newToken () . '&socid=' . $object -> id . '&lineid=' . $line -> id . '">' ;
2020-10-07 15:01:28 +02:00
print img_delete ( 'default' , 'style="vertical-align: middle;"' );
print '</a>' ;
print '</td>' ;
}
print " </tr> \n " ;
}
} else {
2020-10-26 11:50:04 +01:00
$colspan = 10 ;
2021-02-26 21:17:52 +01:00
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer ) {
$colspan += 1 ;
}
2020-10-07 15:01:28 +02:00
print '<tr class="oddeven"><td colspan="' . $colspan . '">' . $langs -> trans ( 'None' ) . '</td></tr>' ;
}
print " </table> " ;
2022-07-25 18:03:07 +02:00
print '</div>' ;
2020-10-07 15:01:28 +02:00
print " </form> " ;
2014-02-23 16:16:47 +01:00
}
}
2018-08-05 17:21:59 +02:00
// End of page
2014-02-23 16:16:47 +01:00
llxFooter ();
$db -> close ();