2004-10-20 22:06:49 +02:00
< ? php
2019-01-21 10:02:11 +01:00
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-05-01 12:19:24 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-01-08 10:53:05 +01:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2019-01-21 10:02:11 +01:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2014-02-23 16:16:47 +01:00
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - concept . pro >
2018-10-23 13:07:09 +02:00
* Copyright ( C ) 2014 - 2018 Juanjo Menent < jmenent @ 2 byte . es >
2019-01-21 10:02:11 +01:00
* Copyright ( C ) 2014 - 2019 Philippe Grand < philippe . grand @ atoo - net . com >
2015-02-24 12:58:43 +01:00
* Copyright ( C ) 2014 Ion agorria < ion @ agorria . com >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2015 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2015-10-18 19:34:10 +02:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2016-09-02 12:32:14 +02:00
* Copyright ( C ) 2016 Ferran Marcet < fmarcet @ 2 byte . es >
2020-11-19 21:12:16 +01:00
* Copyright ( C ) 2018 - 2020 Frédéric France < frederic . france @ netlogic . fr >
2018-12-01 15:58:37 +01:00
* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
2004-07-13 10:28:37 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-07-13 10:28:37 +02:00
* ( 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 />.
2004-07-13 10:28:37 +02:00
*/
2004-08-29 17:22:57 +02:00
2005-02-01 17:57:45 +01:00
/**
2014-02-23 20:10:05 +01:00
* \file htdocs / product / price . php
* \ingroup product
* \brief Page to show product prices
2008-10-25 14:14:16 +02:00
*/
2020-11-27 15:45:12 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_expression.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2004-08-02 04:00:18 +02:00
2019-11-12 00:15:34 +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 20:10:05 +01:00
$prodcustprice = new Productcustomerprice ( $db );
2014-02-23 16:16:47 +01:00
}
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2018-07-25 19:05:40 +02:00
$langs -> loadLangs ( array ( 'products' , 'bills' , 'companies' , 'other' ));
2004-08-02 04:00:18 +02:00
2020-11-19 21:12:16 +01:00
$error = 0 ;
$errors = array ();
2015-06-10 18:42:16 +02:00
2014-02-23 20:10:05 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2015-06-10 18:42:16 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2015-02-02 16:23:25 +01:00
$eid = GETPOST ( 'eid' , 'int' );
2012-01-08 10:53:05 +01:00
2015-12-20 20:24:12 +01:00
$search_soc = GETPOST ( 'search_soc' );
2009-04-27 22:37:50 +02:00
// Security check
2019-11-12 00:15:34 +01:00
$fieldvalue = ( ! empty ( $id ) ? $id : ( ! empty ( $ref ) ? $ref : '' ));
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2021-02-26 14:25:17 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2007-06-16 15:06:05 +02:00
2021-02-26 14:25:17 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2015-06-10 18:42:16 +02:00
$object = new Product ( $db );
$object -> fetch ( $id , $ref );
}
2006-12-19 11:58:33 +01:00
2015-04-02 19:41:19 +02:00
// Clean param
2021-02-26 14:25:17 +01:00
if (( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && empty ( $conf -> global -> PRODUIT_MULTIPRICES_LIMIT )) {
$conf -> global -> PRODUIT_MULTIPRICES_LIMIT = 5 ;
}
2015-04-02 19:41:19 +02: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-12 00:15:34 +01:00
$hookmanager -> initHooks ( array ( 'productpricecard' , 'globalcard' ));
2014-08-29 19:19:26 +02:00
2021-05-21 15:54:11 +02:00
if ( $object -> id > 0 ) {
if ( $object -> type == $object :: TYPE_PRODUCT ) {
restrictedArea ( $user , 'produit' , $object -> id , 'product&product' , '' , '' );
}
if ( $object -> type == $object :: TYPE_SERVICE ) {
restrictedArea ( $user , 'service' , $object -> id , 'product&product' , '' , '' );
}
} else {
restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
}
2021-04-01 11:01:07 +02:00
2014-12-14 16:01:25 +01:00
2005-06-11 13:39:38 +02:00
/*
* Actions
*/
2021-02-26 14:25:17 +01:00
if ( $cancel ) {
$action = '' ;
}
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
$parameters = array ( 'id' => $id , 'ref' => $ref );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 14:25:17 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( empty ( $reshook )) {
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2020-10-07 15:01:28 +02:00
$search_soc = '' ;
}
2021-02-26 14:25:17 +01:00
if ( $action == 'setlabelsellingprice' && $user -> admin ) {
2020-10-07 15:01:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
$keyforlabel = 'PRODUIT_MULTIPRICES_LABEL' . GETPOST ( 'pricelevel' );
dolibarr_set_const ( $db , $keyforlabel , GETPOST ( 'labelsellingprice' , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
$action = '' ;
}
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if (( $action == 'update_vat' ) && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2020-10-07 15:01:28 +02:00
$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
$tva_tx = $tva_tx_txt ;
2020-12-01 02:41:19 +01:00
$reg = array ();
2020-10-07 15:01:28 +02:00
$vatratecode = '' ;
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2021-11-23 13:08:00 +01:00
$vatratecode = $reg [ 1 ];
2020-10-07 15:01:28 +02:00
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx_txt ); // Remove code into vatrate.
}
$tva_tx = price2num ( preg_replace ( '/\*/' , '' , $tva_tx )); // 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 recommanded method), we use it to find npr and local taxes
2021-02-26 14:25:17 +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 create product.
$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 " ;
2022-01-20 18:09:30 +01:00
$sql .= " AND t.code = ' " . $db -> escape ( $vatratecode ) . " ' " ;
2020-10-07 15:01:28 +02:00
$resql = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
2022-01-20 18:09:30 +01:00
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
}
} else {
// Get record with empty 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 = '' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
2020-10-07 15:01:28 +02:00
}
}
$object -> default_vat_code = $vatratecode ;
$object -> tva_tx = $tva_tx ;
$object -> tva_npr = $npr ;
$object -> localtax1_tx = $localtax1 ;
$object -> localtax2_tx = $localtax2 ;
$object -> localtax1_type = $localtax1_type ;
$object -> localtax2_type = $localtax2_type ;
$db -> begin ();
$resql = $object -> update ( $object -> id , $user );
2021-02-26 14:25:17 +01:00
if ( $resql <= 0 ) {
2020-10-07 15:01:28 +02:00
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2022-03-08 14:49:26 +01:00
if ( ! $error ) {
2022-05-06 12:37:18 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
// Force the update of the price of the product using the new VAT
if ( $object -> multiprices_base_type [ $i ] == 'HT' ) {
$oldprice = $object -> multiprices [ $i ];
$oldminprice = $object -> multiprices_min [ $i ];
} else {
$oldprice = $object -> multiprices_ttc [ $i ];
$oldminprice = $object -> multiprices_min_ttc [ $i ];
}
$oldpricebasetype = $object -> multiprices_base_type [ $i ];
$oldnpr = $object -> multiprices_recuperableonly [ $i ];
2021-11-23 13:08:00 +01:00
2022-05-06 12:37:18 +02:00
//$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
$localtaxarray = array (); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
$level = $i ;
$ret = $object -> updatePrice ( $oldprice , $oldpricebasetype , $user , $tva_tx , $oldminprice , $level , $oldnpr , 0 , 0 , $localtaxarray , $vatratecode );
2022-03-08 14:49:26 +01:00
2022-05-06 12:37:18 +02:00
if ( $ret < 0 ) {
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
} else {
// Force the update of the price of the product using the new VAT
if ( $object -> price_base_type == 'HT' ) {
$oldprice = $object -> price ;
$oldminprice = $object -> price_min ;
} else {
$oldprice = $object -> price_ttc ;
$oldminprice = $object -> price_min_ttc ;
}
$oldpricebasetype = $object -> price_base_type ;
$oldnpr = $object -> tva_npr ;
//$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
$localtaxarray = array (); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
$level = 0 ;
$ret = $object -> updatePrice ( $oldprice , $oldpricebasetype , $user , $tva_tx , $oldminprice , $level , $oldnpr , 0 , 0 , $localtaxarray , $vatratecode );
if ( $ret < 0 ) {
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2022-03-08 14:49:26 +01:00
}
2020-10-07 15:01:28 +02:00
}
2021-02-26 14:25:17 +01:00
if ( ! $error ) {
2020-10-07 15:01:28 +02:00
$db -> commit ();
} else {
$db -> rollback ();
}
$action = '' ;
2015-10-25 22:50:05 +01:00
}
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if (( $action == 'update_price' ) && ! $cancel && $object -> getRights () -> creer ) {
2015-11-07 12:19:48 +01:00
$error = 0 ;
$pricestoupdate = array ();
$psq = GETPOST ( 'psqflag' );
$psq = empty ( $newpsq ) ? 0 : $newpsq ;
2015-06-10 18:42:16 +02:00
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2015-11-07 12:19:48 +01:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) {
$object -> fk_price_expression = empty ( $eid ) ? 0 : $eid ; //0 discards expression
if ( $object -> fk_price_expression != 0 ) {
//Check the expression validity by parsing it
$priceparser = new PriceParser ( $db );
if ( $priceparser -> parseProduct ( $object ) < 0 ) {
2019-11-12 00:15:34 +01:00
$error ++ ;
2015-12-14 20:54:55 +01:00
setEventMessages ( $priceparser -> translatedError (), null , 'errors' );
2015-11-07 12:19:48 +01:00
}
}
}
// Multiprices
2019-11-12 00:15:34 +01:00
if ( ! $error && ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))) {
2015-11-07 12:19:48 +01:00
$newprice = GETPOST ( 'price' , 'array' );
$newprice_min = GETPOST ( 'price_min' , 'array' );
$newpricebase = GETPOST ( 'multiprices_base_type' , 'array' );
$newvattx = GETPOST ( 'tva_tx' , 'array' );
2016-02-19 02:41:00 +01:00
$newvatnpr = GETPOST ( 'tva_npr' , 'array' );
$newlocaltax1_tx = GETPOST ( 'localtax1_tx' , 'array' );
$newlocaltax1_type = GETPOST ( 'localtax1_type' , 'array' );
$newlocaltax2_tx = GETPOST ( 'localtax2_tx' , 'array' );
$newlocaltax2_type = GETPOST ( 'localtax2_type' , 'array' );
2015-06-10 18:42:16 +02:00
2015-10-19 15:13:19 +02:00
//Shall we generate prices using price rules?
2016-03-08 12:15:49 +01:00
$object -> price_autogen = GETPOST ( 'usePriceRules' ) == 'on' ;
2015-10-19 15:13:19 +02:00
2021-02-26 14:25:17 +01:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
2015-11-07 12:19:48 +01:00
if ( ! isset ( $newprice [ $i ])) {
continue ;
}
2016-02-19 02:41:00 +01:00
$tva_tx_txt = $newvattx [ $i ];
2017-06-12 16:26:25 +02:00
2017-09-25 21:41:53 +02:00
$tva_tx = $tva_tx_txt ;
2016-04-18 21:02:14 +02:00
$vatratecode = '' ;
2020-11-23 19:08:26 +01:00
$reg = array ();
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2017-09-25 21:41:53 +02:00
$vat_src_code = $reg [ 1 ];
2019-11-12 00:15:34 +01:00
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx_txt ); // Remove code into vatrate.
2017-09-25 21:41:53 +02:00
}
2019-11-12 00:15:34 +01:00
$tva_tx = price2num ( preg_replace ( '/\*/' , '' , $tva_tx )); // keep remove all after the numbers and dot
2017-09-25 21:41:53 +02:00
2020-10-07 15:01:28 +02:00
$npr = preg_match ( '/\*/' , $tva_tx_txt ) ? 1 : 0 ;
2016-02-19 02:41:00 +01:00
$localtax1 = $newlocaltax1_tx [ $i ];
$localtax1_type = $newlocaltax1_type [ $i ];
$localtax2 = $newlocaltax2_tx [ $i ];
$localtax2_type = $newlocaltax2_type [ $i ];
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2020-10-07 15:01:28 +02:00
// We look into database using code
$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 14:25:17 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
2022-01-20 18:09:30 +01:00
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if ( in_array ( $mysoc -> country_code , array ( 'ES' ))) {
$localtax1 = get_localtax ( $tva_tx , 1 );
$localtax2 = get_localtax ( $tva_tx , 2 );
}
}
} else {
// Get record with empty 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 = '' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
2020-10-07 15:01:28 +02:00
}
}
2016-04-18 21:02:14 +02:00
2015-11-07 12:19:48 +01:00
$pricestoupdate [ $i ] = array (
2020-11-27 14:24:15 +01:00
'price' => price2num ( $newprice [ $i ], '' , 2 ),
'price_min' => price2num ( $newprice_min [ $i ], '' , 2 ),
2015-11-07 12:19:48 +01:00
'price_base_type' => $newpricebase [ $i ],
2020-10-07 15:01:28 +02:00
'default_vat_code' => $vatratecode ,
2019-11-12 00:15:34 +01:00
'vat_tx' => $tva_tx , // default_vat_code should be used in priority in a future
'npr' => $npr , // default_vat_code should be used in priority in a future
2020-10-07 15:01:28 +02:00
'localtaxes_array' => array ( '0' => $localtax1_type , '1' => $localtax1 , '2' => $localtax2_type , '3' => $localtax2 ) // default_vat_code should be used in priority in a future
2015-11-07 12:19:48 +01:00
);
//If autogeneration is enabled, then we only set the first level
if ( $object -> price_autogen ) {
break ;
2015-06-10 18:42:16 +02:00
}
2007-06-16 15:06:05 +02:00
}
2021-02-26 14:25:17 +01:00
} elseif ( ! $error ) {
2020-11-27 14:24:15 +01:00
$newprice = price2num ( GETPOST ( 'price' , 'alpha' ), '' , 2 );
$newprice_min = price2num ( GETPOST ( 'price_min' , 'alpha' ), '' , 2 );
2020-11-23 19:08:26 +01:00
$newpricebase = GETPOST ( 'price_base_type' , 'alpha' );
2019-11-12 00:15:34 +01:00
$tva_tx_txt = GETPOST ( 'tva_tx' , 'alpha' ); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
2016-02-19 02:41:00 +01:00
2017-09-25 21:41:53 +02:00
$tva_tx = $tva_tx_txt ;
2016-04-18 21:02:14 +02:00
$vatratecode = '' ;
2020-11-23 19:08:26 +01:00
$reg = array ();
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2017-09-25 21:41:53 +02:00
$vat_src_code = $reg [ 1 ];
2019-11-12 00:15:34 +01:00
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx_txt ); // Remove code into vatrate.
2017-09-25 21:41:53 +02:00
}
2019-11-12 00:15:34 +01:00
$tva_tx = price2num ( preg_replace ( '/\*/' , '' , $tva_tx )); // keep remove all after the numbers and dot
2017-09-25 21:41:53 +02:00
2020-10-07 15:01:28 +02:00
$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 recommanded method), we use it to find npr and local taxes
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2020-10-07 15:01:28 +02:00
// We look into database using code
$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 ) . " ' " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
2020-10-07 15:01:28 +02:00
$sql .= " AND t.code =' " . $db -> escape ( $vatratecode ) . " ' " ;
$resql = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
2022-01-20 18:09:30 +01:00
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
2020-10-07 15:01:28 +02:00
2022-01-20 18:09:30 +01:00
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
2021-02-26 14:25:17 +01:00
if ( in_array ( $mysoc -> country_code , array ( 'ES' ))) {
2020-10-07 15:01:28 +02:00
$localtax1 = get_localtax ( $tva_tx , 1 );
2021-02-26 14:25:17 +01:00
$localtax2 = get_localtax ( $tva_tx , 2 );
2020-10-07 15:01:28 +02:00
}
}
2022-01-20 18:09:30 +01:00
} else {
// Get record with empty 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 = '' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
}
2020-10-07 15:01:28 +02:00
}
2022-01-20 18:09:30 +01:00
2015-11-07 12:19:48 +01:00
$pricestoupdate [ 0 ] = array (
2020-11-23 19:08:26 +01:00
'price' => $newprice ,
'price_min' => $newprice_min ,
'price_base_type' => $newpricebase ,
2020-10-07 15:01:28 +02:00
'default_vat_code' => $vatratecode ,
2019-11-12 00:15:34 +01:00
'vat_tx' => $tva_tx , // default_vat_code should be used in priority in a future
'npr' => $npr , // default_vat_code should be used in priority in a future
2020-10-07 15:01:28 +02:00
'localtaxes_array' => array ( '0' => $localtax1_type , '1' => $localtax1 , '2' => $localtax2_type , '3' => $localtax2 ) // default_vat_code should be used in priority in a future
2015-11-07 12:19:48 +01:00
);
2007-06-16 15:06:05 +02:00
}
2014-09-07 12:22:04 +02:00
2015-11-07 12:19:48 +01:00
if ( ! $error ) {
$db -> begin ();
2015-06-10 18:42:16 +02:00
2015-11-07 12:19:48 +01:00
foreach ( $pricestoupdate as $key => $val ) {
$newprice = $val [ 'price' ];
2015-10-19 15:13:19 +02:00
2015-11-07 12:19:48 +01:00
if ( $val [ 'price' ] < $val [ 'price_min' ] && ! empty ( $object -> fk_price_expression )) {
$newprice = $val [ 'price_min' ]; //Set price same as min, the user will not see the
}
$newprice = price2num ( $newprice , 'MU' );
$newprice_min = price2num ( $val [ 'price_min' ], 'MU' );
2021-06-11 18:21:00 +02:00
$newvattx = price2num ( $val [ 'vat_tx' ]);
2015-11-07 12:19:48 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ) && $newprice_min < $maxpricesupplier ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $langs -> trans ( " MinimumPriceLimit " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )), null , 'errors' );
2019-11-12 00:15:34 +01:00
$error ++ ;
2015-11-07 12:19:48 +01:00
break ;
2015-06-10 18:42:16 +02:00
}
2015-11-07 12:19:48 +01:00
2021-06-11 19:05:05 +02:00
if ( $object -> multiprices [ $key ] != $newprice || $object -> multiprices_min [ $key ] != $newprice_min || $object -> multiprices_base_type [ $key ] != $val [ 'price_base_type' ] || $object -> multiprices_tva_tx [ $key ] != $newvattx ) {
2021-02-26 14:25:17 +01:00
$res = $object -> updatePrice ( $newprice , $val [ 'price_base_type' ], $user , $val [ 'vat_tx' ], $newprice_min , $key , $val [ 'npr' ], $psq , 0 , $val [ 'localtaxes_array' ], $val [ 'default_vat_code' ]);
} else {
$res = 0 ;
}
2018-11-22 12:38:10 +01:00
2015-11-07 12:19:48 +01:00
if ( $res < 0 ) {
2019-11-12 00:15:34 +01:00
$error ++ ;
2015-12-14 20:54:55 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-11-07 12:19:48 +01:00
break ;
2015-06-10 18:42:16 +02:00
}
2014-12-28 01:26:41 +01:00
}
2015-11-07 12:19:48 +01:00
}
2015-11-08 16:45:42 +01:00
if ( ! $error && $object -> update ( $object -> id , $user ) < 0 ) {
$error ++ ;
2015-12-14 20:54:55 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-11-08 16:45:42 +01:00
}
2015-11-07 12:19:48 +01:00
if ( empty ( $error )) {
$action = '' ;
2015-12-14 20:54:55 +01:00
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
2015-11-07 12:19:48 +01:00
$db -> commit ();
2015-06-10 18:42:16 +02:00
} else {
$action = 'edit_price' ;
2015-11-07 12:19:48 +01:00
$db -> rollback ();
2014-12-28 01:26:41 +01:00
}
2007-06-16 15:06:05 +02:00
}
2015-04-02 19:41:19 +02:00
2015-10-19 15:13:19 +02:00
2021-02-26 14:25:17 +01:00
if ( $action == 'delete' && $user -> rights -> produit -> supprimer ) {
2019-01-27 11:55:16 +01:00
$result = $object -> log_price_delete ( $user , GETPOST ( 'lineid' , 'int' ));
2015-06-10 18:42:16 +02:00
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-06-10 18:42:16 +02:00
}
2014-07-20 00:10:40 +02:00
}
2008-10-25 14:14:16 +02:00
2017-12-22 10:56:52 +01:00
// Set Price by quantity
2021-02-26 14:25:17 +01:00
if ( $action == 'activate_price_by_qty' ) {
2017-12-22 10:56:52 +01:00
// Activating product price by quantity add a new price line with price_by_qty set to 1
2019-01-27 11:55:16 +01:00
$level = GETPOST ( 'level' , 'int' );
2022-03-08 14:49:26 +01:00
$ret = $object -> updatePrice ( 0 , $object -> price_base_type , $user , $object -> tva_tx , 0 , $level , $object -> tva_npr , 1 );
if ( $ret < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2012-11-07 00:38:53 +01:00
}
2017-12-22 10:56:52 +01:00
// Unset Price by quantity
2021-02-26 14:25:17 +01:00
if ( $action == 'disable_price_by_qty' ) {
2017-12-22 10:56:52 +01:00
// Disabling product price by quantity add a new price line with price_by_qty set to 0
2019-01-27 11:55:16 +01:00
$level = GETPOST ( 'level' , 'int' );
2022-03-08 14:49:26 +01:00
$ret = $object -> updatePrice ( 0 , $object -> price_base_type , $user , $object -> tva_tx , 0 , $level , $object -> tva_npr , 0 );
if ( $ret < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-12-22 10:56:52 +01:00
}
2015-06-10 18:42:16 +02:00
2021-02-26 14:25:17 +01:00
if ( $action == 'edit_price_by_qty' ) { // Edition d'un prix par quantité
2019-01-27 11:55:16 +01:00
$rowid = GETPOST ( 'rowid' , 'int' );
2012-11-07 00:38:53 +01:00
}
2014-09-07 12:22:04 +02:00
2017-12-22 10:56:52 +01:00
// Add or update price by quantity
2021-02-26 14:25:17 +01:00
if ( $action == 'update_price_by_qty' ) {
2015-06-10 18:42:16 +02:00
// Récupération des variables
2019-01-27 11:55:16 +01:00
$rowid = GETPOST ( 'rowid' , 'int' );
$priceid = GETPOST ( 'priceid' , 'int' );
2021-09-08 22:09:02 +02:00
$newprice = price2num ( GETPOST ( " price " ), 'MU' , 2 );
2015-06-10 18:42:16 +02:00
// $newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
2021-09-08 22:09:02 +02:00
$quantity = price2num ( GETPOST ( 'quantity' ), 'MS' , 2 );
$remise_percent = price2num ( GETPOST ( 'remise_percent' ), '' , 2 );
2015-06-10 18:42:16 +02:00
$remise = 0 ; // TODO : allow discount by amount when available on documents
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
if ( empty ( $quantity )) {
2017-12-22 10:56:52 +01:00
$error ++ ;
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Qty " )), null , 'errors' );
2015-06-10 18:42:16 +02:00
}
if ( empty ( $newprice )) {
2017-12-22 10:56:52 +01:00
$error ++ ;
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Price " )), null , 'errors' );
2015-06-10 18:42:16 +02:00
}
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
2015-06-10 18:42:16 +02:00
// Calcul du prix HT et du prix unitaire
if ( $object -> price_base_type == 'TTC' ) {
$price = price2num ( $newprice ) / ( 1 + ( $object -> tva_tx / 100 ));
}
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
$price = price2num ( $newprice , 'MU' );
$unitPrice = price2num ( $price / $quantity , 'MU' );
// Ajout / mise à jour
if ( $rowid > 0 ) {
2019-11-12 00:15:34 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " product_price_by_qty SET " ;
2021-03-30 19:12:07 +02:00
$sql .= " price= " . (( float ) $price ) . " ', " ;
$sql .= " unitprice= " . (( float ) $unitPrice ) . " , " ;
$sql .= " quantity= " . (( float ) $quantity ) . " , " ;
$sql .= " remise_percent= " . (( float ) $remise_percent ) . " , " ;
$sql .= " remise= " . (( float ) $remise );
$sql .= " WHERE rowid = " . (( int ) $rowid );
2015-06-10 18:42:16 +02:00
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( ! $result ) {
dol_print_error ( $db );
}
2015-06-10 18:42:16 +02:00
} else {
2019-11-12 00:15:34 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values ( " ;
2021-03-30 19:12:07 +02:00
$sql .= (( int ) $priceid ) . ',' . (( float ) $price ) . ',' . (( float ) $unitPrice ) . ',' . (( float ) $quantity ) . ',' . (( float ) $remise_percent ) . ',' . (( float ) $remise ) . ')' ;
2015-06-10 18:42:16 +02:00
$result = $db -> query ( $sql );
2020-07-06 15:34:26 +02:00
if ( ! $result ) {
if ( $db -> lasterrno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
setEventMessages ( $langs -> trans ( " DuplicateRecord " ), null , 'errors' );
} else {
dol_print_error ( $db );
}
}
2015-06-10 18:42:16 +02:00
}
2012-11-07 00:38:53 +01:00
}
2012-10-22 17:47:15 +02:00
}
2021-02-26 14:25:17 +01:00
if ( $action == 'delete_price_by_qty' ) {
2019-01-27 11:55:16 +01:00
$rowid = GETPOST ( 'rowid' , 'int' );
2018-01-08 20:54:40 +01:00
if ( ! empty ( $rowid )) {
2019-11-12 00:15:34 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE rowid = " . (( int ) $rowid );
2014-09-07 12:22:04 +02:00
2018-01-10 20:38:06 +01:00
$result = $db -> query ( $sql );
2018-08-07 17:17:58 +02:00
} else {
2020-10-28 18:21:45 +01:00
setEventMessages (( 'delete_price_by_qty' . $langs -> transnoentities ( 'MissingIds' )), null , 'errors' );
2018-01-08 20:54:40 +01:00
}
2015-06-10 18:42:16 +02:00
}
2012-10-22 17:47:15 +02:00
2020-11-19 21:12:16 +01:00
if ( $action == 'delete_all_price_by_qty' ) {
2019-01-27 11:55:16 +01:00
$priceid = GETPOST ( 'priceid' , 'int' );
2018-01-08 20:54:40 +01:00
if ( ! empty ( $rowid )) {
2019-11-12 00:15:34 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE fk_product_price = " . (( int ) $priceid );
2014-09-07 12:22:04 +02:00
2019-10-20 11:59:21 +02:00
$result = $db -> query ( $sql );
2018-08-07 17:17:58 +02:00
} else {
2020-11-19 21:12:16 +01:00
setEventMessages (( 'delete_price_by_qty' . $langs -> transnoentities ( 'MissingIds' )), null , 'errors' );
2018-01-08 20:54:40 +01:00
}
2015-06-10 18:42:16 +02:00
}
2012-10-22 17:47:15 +02:00
2015-06-10 18:42:16 +02:00
/**
* ***************************************************
* Price by customer
* ****************************************************
*/
if ( $action == 'add_customer_price_confirm' && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2019-01-27 11:55:16 +01:00
$update_child_soc = GETPOST ( 'updatechildprice' , 'int' );
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
// add price by customer
$prodcustprice -> fk_soc = GETPOST ( 'socid' , 'int' );
2020-10-26 12:18:24 +01:00
$prodcustprice -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
2015-06-10 18:42:16 +02:00
$prodcustprice -> fk_product = $object -> id ;
$prodcustprice -> price = price2num ( GETPOST ( " price " ), 'MU' );
$prodcustprice -> price_min = price2num ( GETPOST ( " price_min " ), 'MU' );
$prodcustprice -> price_base_type = GETPOST ( " price_base_type " , 'alpha' );
2014-09-07 12:22:04 +02:00
2019-01-27 11:55:16 +01:00
$tva_tx_txt = GETPOST ( " tva_tx " , 'alpha' );
2017-06-12 16:26:25 +02:00
2017-09-25 21:41:53 +02:00
$tva_tx = $tva_tx_txt ;
2016-04-18 21:02:14 +02:00
$vatratecode = '' ;
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2017-09-25 21:41:53 +02:00
$vat_src_code = $reg [ 1 ];
2019-11-12 00:15:34 +01:00
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx_txt ); // Remove code into vatrate.
2017-09-25 21:41:53 +02:00
}
2019-11-12 00:15:34 +01:00
$tva_tx = price2num ( preg_replace ( '/\*/' , '' , $tva_tx )); // keep remove all after the numbers and dot
2017-09-25 21:41:53 +02:00
2016-02-19 02:41:00 +01:00
$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 recommanded method), we use it to find npr and local taxes
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2020-10-07 15:01:28 +02:00
// We look into database using code
$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 ) . " ' " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
2020-10-07 15:01:28 +02:00
$sql .= " AND t.code =' " . $db -> escape ( $vatratecode ) . " ' " ;
$resql = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
2022-01-20 18:09:30 +01:00
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if ( in_array ( $mysoc -> country_code , array ( 'ES' ))) {
$localtax1 = get_localtax ( $tva_tx , 1 );
$localtax2 = get_localtax ( $tva_tx , 2 );
}
}
} else {
// Get record with empty 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 = '' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
2020-10-07 15:01:28 +02:00
}
2017-06-12 16:26:25 +02:00
}
2016-04-18 21:02:14 +02:00
$prodcustprice -> default_vat_code = $vatratecode ;
2016-02-19 02:41:00 +01:00
$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 ;
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if ( ! ( $prodcustprice -> fk_soc > 0 )) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ThirdParty " )), null , 'errors' );
$error ++ ;
$action = 'add_customer_price' ;
2016-02-14 20:48:25 +01:00
}
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ) && $prodcustprice -> price_min < $maxpricesupplier ) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " MinimumPriceLimit " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )), null , 'errors' );
2015-06-10 18:42:16 +02:00
$error ++ ;
2019-11-12 00:15:34 +01:00
$action = 'add_customer_price' ;
2015-06-10 18:42:16 +02:00
}
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( ! $error ) {
2015-06-10 18:42:16 +02:00
$result = $prodcustprice -> create ( $user , 0 , $update_child_soc );
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2015-06-10 18:42:16 +02:00
} else {
2015-12-14 20:54:55 +01:00
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
2015-06-10 18:42:16 +02:00
}
$action = '' ;
}
2014-09-07 12:22:04 +02:00
}
2021-02-26 14:25:17 +01:00
if ( $action == 'delete_customer_price' && ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer )) {
2015-06-10 18:42:16 +02:00
// Delete price by customer
2021-04-25 15:55:36 +02:00
$prodcustprice -> id = GETPOST ( 'lineid' , 'int' );
2015-06-10 18:42:16 +02:00
$result = $prodcustprice -> delete ( $user );
2014-09-07 12:22:04 +02:00
2014-08-29 19:19:26 +02:00
if ( $result < 0 ) {
2016-02-19 02:41:00 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2014-08-29 19:19:26 +02:00
} else {
2016-02-19 02:41:00 +01:00
setEventMessages ( $langs -> trans ( 'RecordDeleted' ), null , 'mesgs' );
2014-08-29 19:19:26 +02:00
}
$action = '' ;
2014-02-23 16:16:47 +01:00
}
2021-02-26 14:25:17 +01:00
if ( $action == 'update_customer_price_confirm' && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2015-06-10 18:42:16 +02:00
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2019-01-27 11:55:16 +01:00
$update_child_soc = GETPOST ( 'updatechildprice' , 'int' );
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
$prodcustprice -> fetch ( GETPOST ( 'lineid' , 'int' ));
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
// update price by customer
2020-10-26 12:18:24 +01:00
$prodcustprice -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
2015-06-10 18:42:16 +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' );
2016-04-18 21:02:14 +02:00
2016-02-19 02:41:00 +01:00
$tva_tx_txt = GETPOST ( " tva_tx " );
2016-04-18 21:02:14 +02:00
2017-09-25 21:41:53 +02:00
$tva_tx = $tva_tx_txt ;
$vatratecode = '' ;
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2017-09-25 21:41:53 +02:00
$vat_src_code = $reg [ 1 ];
2019-11-12 00:15:34 +01:00
$tva_tx = preg_replace ( '/\s*\(.*\)/' , '' , $tva_tx_txt ); // Remove code into vatrate.
2017-09-25 21:41:53 +02:00
}
2019-11-12 00:15:34 +01:00
$tva_tx = price2num ( preg_replace ( '/\*/' , '' , $tva_tx )); // keep remove all after the numbers and dot
2017-09-25 21:41:53 +02:00
2016-02-19 02:41:00 +01:00
$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 recommanded method), we use it to find npr and local taxes
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg )) {
2020-10-07 15:01:28 +02:00
// We look into database using code
$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 ) . " ' " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
2020-10-07 15:01:28 +02:00
$sql .= " AND t.code =' " . $db -> escape ( $vatratecode ) . " ' " ;
$resql = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$obj = $db -> fetch_object ( $resql );
2022-01-20 18:09:30 +01:00
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
// If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
if ( in_array ( $mysoc -> country_code , array ( 'ES' ))) {
$localtax1 = get_localtax ( $tva_tx , 1 );
$localtax2 = get_localtax ( $tva_tx , 2 );
}
}
} else {
// Get record with empty 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 = '' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
2020-10-07 15:01:28 +02:00
}
2016-02-19 02:41:00 +01:00
}
2017-06-12 16:26:25 +02:00
2016-04-18 21:02:14 +02:00
$prodcustprice -> default_vat_code = $vatratecode ;
2016-02-19 02:41:00 +01:00
$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 ;
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if ( $prodcustprice -> price_min < $maxpricesupplier && ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " MinimumPriceLimit " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )), null , 'errors' );
2015-06-10 18:42:16 +02:00
$error ++ ;
2019-11-12 00:15:34 +01:00
$action = 'update_customer_price' ;
2015-06-10 18:42:16 +02:00
}
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( ! $error ) {
2015-06-10 18:42:16 +02:00
$result = $prodcustprice -> update ( $user , 0 , $update_child_soc );
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2015-06-10 18:42:16 +02:00
} else {
2020-11-23 15:12:52 +01:00
setEventMessages ( $langs -> trans ( " Save " ), null , 'mesgs' );
2015-06-10 18:42:16 +02:00
}
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
$action = '' ;
2014-08-29 19:19:26 +02:00
}
2014-02-23 16:16:47 +01:00
}
}
2015-06-10 18:42:16 +02:00
2004-07-13 10:28:37 +02:00
/*
2008-10-25 14:14:16 +02:00
* View
2004-07-13 10:28:37 +02:00
*/
2008-10-25 14:14:16 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2004-07-13 10:28:37 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $id ) || ! empty ( $ref )) {
2015-07-13 11:27:35 +02:00
// fetch updated prices
$object -> fetch ( $id , $ref );
}
2016-07-28 12:17:00 +02:00
2016-08-10 07:40:40 +02:00
$title = $langs -> trans ( 'ProductServiceCard' );
$helpurl = '' ;
2019-01-27 11:55:16 +01:00
$shortlabel = dol_trunc ( $object -> label , 16 );
2021-02-26 14:25:17 +01:00
if ( GETPOST ( " type " ) == '0' || ( $object -> type == Product :: TYPE_PRODUCT )) {
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( 'Product' ) . " " . $shortlabel . " - " . $langs -> trans ( 'SellingPrices' );
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos' ;
2016-08-10 07:40:40 +02:00
}
2021-02-26 14:25:17 +01:00
if ( GETPOST ( " type " ) == '1' || ( $object -> type == Product :: TYPE_SERVICE )) {
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( 'Service' ) . " " . $shortlabel . " - " . $langs -> trans ( 'SellingPrices' );
$helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios' ;
2016-08-10 07:40:40 +02:00
}
2016-07-28 12:17:00 +02:00
2020-12-27 16:53:15 +01:00
llxHeader ( '' , $title , $helpurl , '' , 0 , 0 , '' , '' , '' , 'classforhorizontalscrolloftabs' );
2004-07-14 12:30:37 +02:00
2015-04-07 03:00:11 +02:00
$head = product_prepare_head ( $object );
2019-11-12 00:15:34 +01:00
$titre = $langs -> trans ( " CardProduct " . $object -> type );
2015-03-30 03:14:07 +02:00
$picto = ( $object -> type == Product :: TYPE_SERVICE ? 'service' : 'product' );
2017-03-31 11:39:12 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'price' , $titre , - 1 , $picto );
2006-08-02 00:42:38 +02:00
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/product/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2019-11-12 00:15:34 +01:00
$object -> next_prev_filter = " fk_product_type = " . $object -> type ;
2016-05-17 02:16:28 +02:00
2017-06-12 16:26:25 +02:00
$shownav = 1 ;
2021-02-26 14:25:17 +01:00
if ( $user -> socid && ! in_array ( 'product' , explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL ))) {
$shownav = 0 ;
}
2017-06-12 16:26:25 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , $shownav , 'ref' );
2015-11-08 19:23:02 +01:00
2005-06-11 13:39:38 +02:00
2015-11-08 19:23:02 +01:00
print '<div class="fichecenter">' ;
2005-06-11 13:39:38 +02:00
2015-11-08 19:23:02 +01:00
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield" width="100%">' ;
2015-10-25 22:50:05 +01:00
2017-12-22 10:56:52 +01:00
// Price per customer segment/level
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2015-01-12 18:16:24 +01:00
// Price and min price are variable (depends on level of company).
2021-02-26 14:25:17 +01:00
if ( ! empty ( $socid )) {
2009-08-06 16:25:03 +02:00
$soc = new Societe ( $db );
$soc -> id = $socid ;
$soc -> fetch ( $socid );
2014-09-07 12:22:04 +02:00
2021-08-09 20:01:06 +02:00
// Type
if ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) {
$typeformat = 'select;0:' . $langs -> trans ( " Product " ) . ',1:' . $langs -> trans ( " Service " );
print '<tr><td class="">' ;
print ( empty ( $conf -> global -> PRODUCT_DENY_CHANGE_PRODUCT_TYPE )) ? $form -> editfieldkey ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat ) : $langs -> trans ( 'Type' );
print '</td><td>' ;
print $form -> editfieldval ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat );
print '</td></tr>' ;
}
2015-01-12 18:16:24 +01:00
// Selling price
2021-08-09 20:01:06 +02:00
print '<tr><td class="titlefieldcreate">' ;
2016-08-29 16:30:31 +02:00
print $langs -> trans ( " SellingPrice " );
print '</td>' ;
2015-10-18 19:34:10 +02:00
print '<td colspan="2">' ;
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $soc -> price_level ] == 'TTC' ) {
2022-01-05 19:58:08 +01:00
print '<span class="amount">' . price ( $object -> multiprices_ttc [ $soc -> price_level ]) . '</span>' ;
2014-02-23 20:10:05 +01:00
} else {
2022-01-05 19:58:08 +01:00
print '<span class="amount">' . price ( $object -> multiprices [ $soc -> price_level ]) . '</span>' ;
2008-10-25 14:14:16 +02:00
}
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $soc -> price_level ]) {
2019-11-12 00:15:34 +01:00
print ' ' . $langs -> trans ( $object -> multiprices_base_type [ $soc -> price_level ]);
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print ' ' . $langs -> trans ( $object -> price_base_type );
2008-10-25 14:14:16 +02:00
}
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2015-01-12 18:16:24 +01:00
// Price min
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " MinPrice " ) . '</td><td colspan="2">' ;
2021-02-26 14:25:17 +01:00
if ( $object -> multiprices_base_type [ $soc -> price_level ] == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print price ( $object -> multiprices_min_ttc [ $soc -> price_level ]) . ' ' . $langs -> trans ( $object -> multiprices_base_type [ $soc -> price_level ]);
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print price ( $object -> multiprices_min [ $soc -> price_level ]) . ' ' . $langs -> trans ( empty ( $object -> multiprices_base_type [ $soc -> price_level ]) ? 'HT' : $object -> multiprices_base_type [ $soc -> price_level ]);
2009-01-10 01:32:42 +01:00
}
print '</td></tr>' ;
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) { // using this option is a bug. kept for backward compatibility
2019-10-20 11:59:21 +02:00
// TVA
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td colspan="2">' ;
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $object -> multiprices_tva_tx [ $soc -> price_level ])) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> multiprices_tva_tx [ $soc -> price_level ]);
}
if ( price2num ( $object -> multiprices_localtax1_type [ $soc -> price_level ])) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> multiprices_localtax1_tx [ $soc -> price_level ]);
}
if ( price2num ( $object -> multiprices_localtax2_type [ $soc -> price_level ])) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> multiprices_localtax2_tx [ $soc -> price_level ]);
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2019-11-12 00:15:34 +01:00
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
2019-10-20 11:59:21 +02:00
//print vatrate($object->multiprices_tva_tx[$soc->price_level], true);
print '</td></tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
// TVA
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $object -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> tva_tx );
}
if ( price2num ( $object -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax1_tx );
}
if ( price2num ( $object -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2020-10-07 15:01:28 +02:00
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
2017-09-25 21:41:53 +02:00
/*
2016-04-18 21:02:14 +02:00
if ( $object -> default_vat_code )
2021-02-26 14:25:17 +01:00
{
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
}
else print vatrate ( $object -> tva_tx . ( $object -> tva_npr ? '*' : '' ), true ); */
2020-10-07 15:01:28 +02:00
print '</td></tr>' ;
2015-10-25 22:50:05 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) { // using this option is a bug. kept for backward compatibility
2021-08-09 20:01:06 +02:00
// Type
if ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) {
$typeformat = 'select;0:' . $langs -> trans ( " Product " ) . ',1:' . $langs -> trans ( " Service " );
print '<tr><td class="">' ;
print ( empty ( $conf -> global -> PRODUCT_DENY_CHANGE_PRODUCT_TYPE )) ? $form -> editfieldkey ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat ) : $langs -> trans ( 'Type' );
print '</td><td>' ;
print $form -> editfieldval ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat );
print '</td></tr>' ;
}
2019-10-20 11:59:21 +02:00
// We show only vat for level 1
2021-08-09 20:01:06 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td colspan="2">' . vatrate ( $object -> multiprices_tva_tx [ 1 ], true ) . '</td>' ;
2019-10-20 11:59:21 +02:00
print '</tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-08-09 20:01:06 +02:00
// Type
if ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) {
$typeformat = 'select;0:' . $langs -> trans ( " Product " ) . ',1:' . $langs -> trans ( " Service " );
print '<tr><td class="">' ;
print ( empty ( $conf -> global -> PRODUCT_DENY_CHANGE_PRODUCT_TYPE )) ? $form -> editfieldkey ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat ) : $langs -> trans ( 'Type' );
print '</td><td>' ;
print $form -> editfieldval ( " Type " , 'fk_product_type' , $object -> type , $object , 0 , $typeformat );
print '</td></tr>' ;
}
2020-10-07 15:01:28 +02:00
// TVA
2022-01-20 18:09:30 +01:00
print '<!-- Default VAT Rate -->' ;
2021-08-09 20:01:06 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2020-10-07 15:01:28 +02:00
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $object -> tva_tx )) {
2022-01-20 18:09:30 +01:00
$positiverates .= ( $positiverates ? '<span class="opacitymedium">/</span>' : '' ) . price2num ( $object -> tva_tx );
2021-02-26 14:25:17 +01:00
}
if ( price2num ( $object -> localtax1_type )) {
2022-01-20 18:09:30 +01:00
$positiverates .= ( $positiverates ? '<span class="opacitymedium">/</span>' : '' ) . price2num ( $object -> localtax1_tx );
2021-02-26 14:25:17 +01:00
}
if ( price2num ( $object -> localtax2_type )) {
2022-01-20 18:09:30 +01:00
$positiverates .= ( $positiverates ? '<span class="opacitymedium">/</span>' : '' ) . price2num ( $object -> localtax2_tx );
2021-02-26 14:25:17 +01:00
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2022-01-20 18:09:30 +01:00
print vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), true , $object -> tva_npr , 1 );
2020-10-07 15:01:28 +02:00
/*
2021-02-26 14:25:17 +01:00
if ( $object -> default_vat_code )
{
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
}
else print vatrate ( $object -> tva_tx . ( $object -> tva_npr ? '*' : '' ), true ); */
2020-10-07 15:01:28 +02:00
print '</td></tr>' ;
2015-10-25 22:50:05 +01:00
}
2020-10-07 15:01:28 +02:00
print '</table>' ;
2017-06-12 16:26:25 +02:00
2020-10-07 15:01:28 +02:00
print '<br>' ;
2017-06-12 16:26:25 +02:00
2020-10-07 15:01:28 +02:00
print '<table class="noborder tableforfield" width="100%">' ;
2016-09-18 13:58:17 +02:00
print '<tr class="liste_titre"><td>' ;
2016-08-29 16:30:31 +02:00
print $langs -> trans ( " PriceLevel " );
2021-02-26 14:25:17 +01:00
if ( $user -> admin ) {
2021-09-27 12:24:01 +02:00
print ' <a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editlabelsellingprice&token=' . newToken () . '&pricelevel=' . $i . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'EditSellingPriceLabel' ), 0 ) . '</a>' ;
2021-02-26 14:25:17 +01:00
}
2016-09-18 13:58:17 +02:00
print '</td>' ;
print '<td style="text-align: right">' . $langs -> trans ( " SellingPrice " ) . '</td>' ;
print '<td style="text-align: right">' . $langs -> trans ( " MinPrice " ) . '</td>' ;
print '</tr>' ;
2015-10-18 19:34:10 +02:00
2021-02-26 14:25:17 +01:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2014-09-07 12:22:04 +02:00
2014-05-01 12:19:24 +02:00
// Label of price
2016-08-29 16:30:31 +02:00
print '<td>' ;
2019-11-12 00:15:34 +01:00
$keyforlabel = 'PRODUIT_MULTIPRICES_LABEL' . $i ;
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/editlabelsellingprice/' , $action )) {
2020-10-07 15:01:28 +02:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="setlabelsellingprice">' ;
print '<input type="hidden" name="pricelevel" value="' . $i . '">' ;
print $langs -> trans ( " SellingPrice " ) . ' ' . $i . ' - ' ;
2020-12-19 16:24:32 +01:00
print '<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' . $conf -> global -> $keyforlabel . '">' ;
print ' <input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '">' ;
2020-10-07 15:01:28 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
print $langs -> trans ( " SellingPrice " ) . ' ' . $i ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> $keyforlabel )) {
print ' - ' . $langs -> trans ( $conf -> global -> $keyforlabel );
}
2016-08-29 16:30:31 +02:00
}
2014-05-01 12:19:24 +02:00
print '</td>' ;
2014-09-07 12:22:04 +02:00
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $i ] == 'TTC' ) {
2022-01-05 19:58:08 +01:00
print '<td class="right"><span class="amount">' . price ( $object -> multiprices_ttc [ $i ]);
2014-02-23 20:10:05 +01:00
} else {
2022-01-05 19:58:08 +01:00
print '<td class="right"><span class="amount">' . price ( $object -> multiprices [ $i ]);
2009-08-06 16:25:03 +02:00
}
2014-09-07 12:22:04 +02:00
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $i ]) {
2022-01-05 19:58:08 +01:00
print ' ' . $langs -> trans ( $object -> multiprices_base_type [ $i ]) . '</span></td>' ;
2014-02-23 20:10:05 +01:00
} else {
2022-01-05 19:58:08 +01:00
print ' ' . $langs -> trans ( $object -> price_base_type ) . '</span></td>' ;
2009-08-06 16:25:03 +02:00
}
2014-09-07 12:22:04 +02:00
2015-10-18 19:34:10 +02:00
// Prix min
print '<td style="text-align: right">' ;
2021-02-26 14:25:17 +01:00
if ( empty ( $object -> multiprices_base_type [ $i ])) {
$object -> multiprices_base_type [ $i ] = " HT " ;
}
if ( $object -> multiprices_base_type [ $i ] == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print price ( $object -> multiprices_min_ttc [ $i ]) . ' ' . $langs -> trans ( $object -> multiprices_base_type [ $i ]);
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print price ( $object -> multiprices_min [ $i ]) . ' ' . $langs -> trans ( $object -> multiprices_base_type [ $i ]);
2009-08-06 16:25:03 +02:00
}
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2012-10-22 17:47:15 +02:00
// Price by quantity
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) { // TODO Fix the form included into a tr instead of a td
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " PriceByQuantity " ) . ' ' . $i ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> $keyforlabel )) {
print ' - ' . $langs -> trans ( $conf -> global -> $keyforlabel );
}
2018-05-23 17:05:08 +02:00
print '</td><td colspan="2">' ;
2014-09-07 12:22:04 +02:00
2016-02-14 20:48:25 +01:00
if ( $object -> prices_by_qty [ $i ] == 1 ) {
2014-12-14 20:41:11 +01:00
print '<table width="50%" class="border" summary="List of quantities">' ;
2014-09-07 12:22:04 +02:00
2012-10-22 17:47:15 +02:00
print '<tr class="liste_titre">' ;
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " PriceByQuantityRange " ) . ' ' . $i . '</td>' ;
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " UnitPrice " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Discount " ) . '</td>' ;
2012-10-22 17:47:15 +02:00
print '<td> </td>' ;
print '</tr>' ;
2021-02-26 14:25:17 +01:00
foreach ( $object -> prices_by_qty_list [ $i ] as $ii => $prices ) {
2014-12-14 20:41:11 +01:00
if ( $action == 'edit_price_by_qty' && $rowid == $prices [ 'rowid' ] && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="priceid" value="' . $object -> prices_by_qty_id [ $i ] . '">' ;
print '<input type="hidden" value="' . $prices [ 'rowid' ] . '" name="rowid">' ;
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
print '<td><input size="5" type="text" value="' . $prices [ 'quantity' ] . '" name="quantity"></td>' ;
print '<td class="right" colspan="2"><input size="10" type="text" value="' . price2num ( $prices [ 'price' ], 'MU' ) . '" name="price"> ' . $object -> price_base_type . '</td>' ;
2020-07-06 15:34:26 +02:00
print '<td class="right nowraponall"><input size="5" type="text" value="' . $prices [ 'remise_percent' ] . '" name="remise_percent"> %</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="center"><input type="submit" value="' . $langs -> trans ( " Modify " ) . '" class="button"></td>' ;
2012-10-22 17:47:15 +02:00
print '</tr>' ;
print '</form>' ;
} else {
2019-11-12 00:15:34 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
print '<td>' . $prices [ 'quantity' ] . '</td>' ;
print '<td class="right">' . price ( $prices [ 'price' ]) . '</td>' ;
print '<td class="right">' . price ( $prices [ 'unitprice' ]) . '</td>' ;
print '<td class="right">' . price ( $prices [ 'remise_percent' ]) . ' %</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="center">' ;
2014-02-23 20:10:05 +01:00
if (( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2021-09-27 12:24:01 +02:00
print '<a class="editfielda marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit_price_by_qty&token=' . newToken () . '&rowid=' . $prices [ " rowid " ] . '">' ;
2019-11-12 00:15:34 +01:00
print img_edit () . '</a>' ;
2021-09-18 22:04:41 +02:00
print '<a class="marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete_price_by_qty&token=' . newToken () . '&rowid=' . $prices [ " rowid " ] . '">' ;
2019-11-12 00:15:34 +01:00
print img_delete () . '</a>' ;
2012-10-22 17:47:15 +02:00
} else {
print ' ' ;
}
print '</td>' ;
print '</tr>' ;
}
}
2014-02-23 20:10:05 +01:00
if ( $action != 'edit_price_by_qty' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="priceid" value="' . $object -> prices_by_qty_id [ $i ] . '">' ; // id in product_price
print '<input type="hidden" value="0" name="rowid">' ; // id in product_price
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2012-11-07 00:38:53 +01:00
print '<td><input size="5" type="text" value="1" name="quantity"></td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> ' . $object -> price_base_type . '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right"> </td>' ;
2020-07-06 15:34:26 +02:00
print '<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '" class="button"></td>' ;
2012-10-22 17:47:15 +02:00
print '</tr>' ;
print '</form>' ;
}
2014-09-07 12:22:04 +02:00
2012-10-22 17:47:15 +02:00
print '</table>' ;
2021-03-19 12:44:59 +01:00
print '<a class="editfielda marginleftonly marginrightonly" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=disable_price_by_qty&level=' . $i . '&token=' . newToken () . '">(' . $langs -> trans ( " DisablePriceByQty " ) . ')</a>' ;
2012-10-22 17:47:15 +02:00
} else {
print $langs -> trans ( " No " );
2021-03-19 12:44:59 +01:00
print ' <a class="marginleftonly marginrightonly" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=activate_price_by_qty&level=' . $i . '&token=' . newToken () . '">(' . $langs -> trans ( " Activate " ) . ')</a>' ;
2012-10-22 17:47:15 +02:00
}
print '</td></tr>' ;
}
2009-08-06 16:25:03 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2014-02-23 20:10:05 +01:00
// TVA
2019-11-12 00:15:34 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $object -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> tva_tx );
}
if ( price2num ( $object -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax1_tx );
}
if ( price2num ( $object -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2022-07-08 11:21:54 +02:00
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr , 0 , 1 );
2017-09-25 21:41:53 +02:00
/*
2016-04-18 21:02:14 +02:00
if ( $object -> default_vat_code )
{
2021-02-26 14:25:17 +01:00
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
2017-06-12 16:26:25 +02:00
}
2017-09-25 21:41:53 +02:00
else print vatrate ( $object -> tva_tx , true , $object -> tva_npr , true ); */
2016-04-18 21:02:14 +02:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
// Price
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " SellingPrice " ) . '</td><td>' ;
2014-02-23 20:10:05 +01:00
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print price ( $object -> price_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print price ( $object -> price ) . ' ' . $langs -> trans ( $object -> price_base_type );
2007-06-16 15:06:05 +02:00
}
2009-08-06 16:25:03 +02:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2010-07-22 23:16:29 +02:00
// Price minimum
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " MinPrice " ) . '</td><td>' ;
2014-02-23 20:10:05 +01:00
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print price ( $object -> price_min_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print price ( $object -> price_min ) . ' ' . $langs -> trans ( $object -> price_base_type );
2009-01-10 01:32:42 +01:00
}
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2012-10-22 17:47:15 +02:00
// Price by quantity
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) { // TODO Fix the form inside tr instead of td
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " PriceByQuantity " );
2017-12-22 10:56:52 +01:00
if ( $object -> prices_by_qty [ 0 ] == 0 ) {
2022-11-11 12:44:20 +01:00
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=activate_price_by_qty&level=1&token=' . newToken () . '">(' . $langs -> trans ( " Activate " ) . ')' ;
2020-05-21 15:05:19 +02:00
} else {
2022-11-11 12:44:20 +01:00
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=disable_price_by_qty&level=1&token=' . newToken () . '">(' . $langs -> trans ( " DisablePriceByQty " ) . ')' ;
2012-10-22 17:47:15 +02:00
}
print '</td><td>' ;
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( $object -> prices_by_qty [ 0 ] == 1 ) {
2014-12-14 20:41:11 +01:00
print '<table width="50%" class="border" summary="List of quantities">' ;
2012-10-22 17:47:15 +02:00
print '<tr class="liste_titre">' ;
2017-12-22 10:56:52 +01:00
//print '<td>' . $langs->trans("PriceByQuantityRange") . '</td>';
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " Quantity " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Price " ) . '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right"></td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="right">' . $langs -> trans ( " UnitPrice " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Discount " ) . '</td>' ;
2012-10-22 17:47:15 +02:00
print '<td> </td>' ;
print '</tr>' ;
2021-02-26 14:25:17 +01:00
if ( $action != 'edit_price_by_qty' ) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ; // FIXME a form into a table is not allowed
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-12-22 10:56:52 +01:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="priceid" value="' . $object -> prices_by_qty_id [ 0 ] . '">' ; // id in product_price
print '<input type="hidden" value="0" name="rowid">' ; // id in product_price_by_qty
2017-12-22 10:56:52 +01:00
2019-11-12 00:15:34 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2017-12-22 10:56:52 +01:00
print '<td><input size="5" type="text" value="1" name="quantity"></td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>' ;
2017-12-22 10:56:52 +01:00
print '<td>' ;
//print $object->price_base_type;
print '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right"> </td>' ;
2020-07-06 15:34:26 +02:00
print '<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '" class="button"></td>' ;
2017-12-22 10:56:52 +01:00
print '</tr>' ;
print '</form>' ;
}
2021-02-26 14:25:17 +01:00
foreach ( $object -> prices_by_qty_list [ 0 ] as $ii => $prices ) {
if ( $action == 'edit_price_by_qty' && $rowid == $prices [ 'rowid' ] && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="priceid" value="' . $object -> prices_by_qty_id [ 0 ] . '">' ; // id in product_price
print '<input type="hidden" value="' . $prices [ 'rowid' ] . '" name="rowid">' ; // id in product_price_by_qty
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
print '<td><input size="5" type="text" value="' . $prices [ 'quantity' ] . '" name="quantity"></td>' ;
print '<td class="right"><input class="width50 right" type="text" value="' . price2num ( $prices [ 'price' ], 'MU' ) . '" name="price"></td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2017-12-22 10:56:52 +01:00
//print $object->price_base_type;
print $prices [ 'price_base_type' ];
print '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right"> </td>' ;
2020-07-06 15:34:26 +02:00
print '<td class="right nowraponall"><input class="width50 right" type="text" value="' . $prices [ 'remise_percent' ] . '" name="remise_percent"> %</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="center"><input type="submit" value="' . $langs -> trans ( " Modify " ) . '" class="button"></td>' ;
2012-10-22 17:47:15 +02:00
print '</tr>' ;
print '</form>' ;
} else {
2019-11-12 00:15:34 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
print '<td>' . $prices [ 'quantity' ] . '</td>' ;
print '<td class="right">' . price ( $prices [ 'price' ]) . '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2017-12-22 10:56:52 +01:00
//print $object->price_base_type;
print $prices [ 'price_base_type' ];
print '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="right">' . price ( $prices [ 'unitprice' ]) . '</td>' ;
print '<td class="right">' . price ( $prices [ 'remise_percent' ]) . ' %</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="center">' ;
2021-02-26 14:25:17 +01:00
if (( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2021-09-27 12:24:01 +02:00
print '<a class="editfielda marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit_price_by_qty&token=' . newToken () . '&rowid=' . $prices [ " rowid " ] . '">' ;
2019-11-12 00:15:34 +01:00
print img_edit () . '</a>' ;
2021-09-18 22:04:41 +02:00
print '<a class="marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete_price_by_qty&token=' . newToken () . '&rowid=' . $prices [ " rowid " ] . '">' ;
2019-11-12 00:15:34 +01:00
print img_delete () . '</a>' ;
2012-10-22 17:47:15 +02:00
} else {
print ' ' ;
}
print '</td>' ;
print '</tr>' ;
}
}
print '</table>' ;
} else {
print $langs -> trans ( " No " );
}
print '</td></tr>' ;
}
2009-11-30 01:23:58 +01:00
}
2008-05-14 00:53:31 +02:00
2005-07-11 02:49:16 +02:00
print " </table> \n " ;
2008-10-25 14:14:16 +02:00
2015-11-08 19:23:02 +01:00
print '</div>' ;
print '<div style="clear:both"></div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2005-06-11 13:39:38 +02:00
2015-02-24 12:58:43 +01:00
2016-02-26 13:37:18 +01:00
2021-03-16 04:22:43 +01:00
/*
* Action bar
*/
2021-07-28 11:17:07 +02:00
2019-11-12 00:15:34 +01:00
if ( ! $action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'showlog_default_price' || $action == 'add_customer_price'
2021-02-26 14:25:17 +01:00
|| $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty' ) {
2019-11-12 00:15:34 +01:00
print " \n " . '<div class="tabsAction">' . " \n " ;
2014-09-07 12:22:04 +02:00
2015-11-02 10:02:09 +01:00
2021-07-28 11:17:07 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
if ( empty ( $reshook )) {
if ( $object -> isVariant ()) {
2018-10-23 13:07:09 +02:00
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2021-07-28 11:17:07 +02:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NoEditVariants " )) . '">' . $langs -> trans ( " UpdateDefaultPrice " ) . '</a></div>' ;
}
} else {
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2021-09-27 12:24:01 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_price&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " UpdateDefaultPrice " ) . '</a></div>' ;
2022-01-28 08:49:47 +01:00
} else {
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " UpdateDefaultPrice " ) . '</span></div>' ;
2021-07-28 11:17:07 +02:00
}
2018-10-23 13:07:09 +02:00
}
2017-06-12 16:26:25 +02:00
2021-07-28 11:17:07 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2022-04-06 21:01:04 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=add_customer_price&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " AddCustomerPrice " ) . '</a></div>' ;
2022-01-28 08:49:47 +01:00
} else {
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " AddCustomerPrice " ) . '</span></div>' ;
2021-07-28 11:17:07 +02:00
}
2018-10-23 13:07:09 +02:00
}
2017-06-12 16:26:25 +02:00
2021-07-28 11:17:07 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2021-09-27 12:24:01 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_vat&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " UpdateVAT " ) . '</a></div>' ;
2022-01-28 08:49:47 +01:00
} else {
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " UpdateVAT " ) . '</span></div>' ;
2021-07-28 11:17:07 +02:00
}
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2021-09-27 12:24:01 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_price&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " UpdateLevelPrices " ) . '</a></div>' ;
2022-01-28 08:49:47 +01:00
} else {
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " UpdateLevelPrices " ) . '</span></div>' ;
2021-07-28 11:17:07 +02:00
}
2018-10-23 13:07:09 +02:00
}
}
2020-10-07 15:01:28 +02:00
}
2017-06-12 16:26:25 +02:00
2007-06-16 15:06:05 +02:00
print " \n </div> \n " ;
2005-06-11 13:39:38 +02:00
}
2015-10-25 22:50:05 +01:00
2005-06-11 13:39:38 +02:00
/*
2015-10-25 22:50:05 +01:00
* Edit price area
2005-06-11 13:39:38 +02:00
*/
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if ( $action == 'edit_vat' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2015-10-25 22:50:05 +01:00
print load_fiche_titre ( $langs -> trans ( " UpdateVAT " ), '' );
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-03-24 13:10:35 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2015-10-25 22:50:05 +01:00
print '<input type="hidden" name="action" value="update_vat">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2015-10-25 22:50:05 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2017-06-12 16:26:25 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
// VAT
2019-11-12 00:15:34 +01:00
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2016-04-18 21:02:14 +02:00
print $form -> load_tva ( " tva_tx " , $object -> default_vat_code ? $object -> tva_tx . ' (' . $object -> default_vat_code . ')' : $object -> tva_tx , $mysoc , '' , $object -> id , $object -> tva_npr , $object -> type , false , 1 );
2015-10-25 22:50:05 +01:00
print '</td></tr>' ;
print '</table>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-10-25 22:50:05 +01:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2015-10-25 22:50:05 +01:00
print '<br></form><br>' ;
}
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
if ( $action == 'edit_price' && $object -> getRights () -> creer ) {
2022-08-10 14:32:26 +02:00
print '<br>' ;
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " NewPrice " ), '' );
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2020-10-07 15:01:28 +02:00
print '<!-- Edit price -->' . " \n " ;
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-03-24 13:10:35 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2007-06-16 15:34:37 +02:00
print '<input type="hidden" name="action" value="update_price">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2015-08-23 07:37:38 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2017-06-12 16:26:25 +02:00
2021-03-07 18:41:07 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
// VAT
2019-11-12 00:15:34 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2016-04-18 21:02:14 +02:00
print $form -> load_tva ( " tva_tx " , $object -> default_vat_code ? $object -> tva_tx . ' (' . $object -> default_vat_code . ')' : $object -> tva_tx , $mysoc , '' , $object -> id , $object -> tva_npr , $object -> type , false , 1 );
2014-02-23 20:10:05 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2008-10-25 14:14:16 +02:00
// Price base
2017-03-04 18:17:04 +01:00
print '<tr><td>' ;
2008-10-25 14:14:16 +02:00
print $langs -> trans ( 'PriceBase' );
print '</td>' ;
2017-03-04 18:17:04 +01:00
print '<td>' ;
2015-06-06 14:21:18 +02:00
print $form -> selectPriceBaseType ( $object -> price_base_type , " price_base_type " );
2008-10-25 14:14:16 +02:00
print '</td>' ;
print '</tr>' ;
2015-02-24 12:58:43 +01:00
2021-02-26 14:25:17 +01:00
// Only show price mode and expression selector if module is enabled
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) {
2014-12-28 01:26:41 +01:00
// Price mode selector
2021-06-23 02:22:49 +02:00
print '<!-- Show price mode of dynamicprices editor -->' . " \n " ;
2017-03-04 18:17:04 +01:00
print '<tr><td>' . $langs -> trans ( " PriceMode " ) . '</td><td>' ;
2021-06-23 02:22:49 +02:00
print img_picto ( '' , 'dynamicprice' , 'class="pictofixedwidth"' );
2014-12-28 01:26:41 +01:00
$price_expression = new PriceExpression ( $db );
2021-06-23 02:22:49 +02:00
$price_expression_list = array ( 0 => $langs -> trans ( " Numeric " ) . ' <span class="opacitymedium">(' . $langs -> trans ( " NoDynamicPrice " ) . ')</span>' ); //Put the numeric mode as first option
2014-12-28 01:26:41 +01:00
foreach ( $price_expression -> list_price_expression () as $entry ) {
$price_expression_list [ $entry -> id ] = $entry -> title ;
}
$price_expression_preselection = GETPOST ( 'eid' ) ? GETPOST ( 'eid' ) : ( $object -> fk_price_expression ? $object -> fk_price_expression : '0' );
2016-03-25 15:34:37 +01:00
print $form -> selectarray ( 'eid' , $price_expression_list , $price_expression_preselection );
2021-06-23 02:22:49 +02:00
print ' <a id="expression_editor" class="classlink">' . $langs -> trans ( " PriceExpressionEditor " ) . '</a>' ;
2014-12-28 01:26:41 +01:00
print '</td></tr>' ;
2015-11-08 15:12:31 +01:00
2014-12-28 01:26:41 +01:00
// This code hides the numeric price input if is not selected, loads the editor page if editor button is pressed
2015-11-08 15:12:31 +01:00
?>
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " #expression_editor " ) . click ( function () {
2015-12-12 01:38:24 +01:00
window . location = " <?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid= " + $ ( " #eid " ) . val ();
2015-11-08 15:12:31 +01:00
});
2014-12-28 01:26:41 +01:00
jQuery ( " #eid " ) . change ( on_change );
on_change ();
2015-11-08 15:12:31 +01:00
});
2014-12-28 01:26:41 +01:00
function on_change () {
2015-12-12 01:38:24 +01:00
if ( $ ( " #eid " ) . val () == 0 ) {
2014-12-28 01:26:41 +01:00
jQuery ( " #price_numeric " ) . show ();
} else {
jQuery ( " #price_numeric " ) . hide ();
}
}
2015-11-08 15:12:31 +01:00
</ script >
< ? php
2014-12-28 01:26:41 +01:00
}
2014-09-07 12:22:04 +02:00
2008-05-14 00:53:31 +02:00
// Price
2014-12-28 01:26:41 +01:00
$product = new Product ( $db );
$product -> fetch ( $id , $ref , '' , 1 ); //Ignore the math expression when getting the price
2017-03-04 18:17:04 +01:00
print '<tr id="price_numeric"><td>' ;
2014-02-23 20:10:05 +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 );
2017-03-04 18:17:04 +01:00
print '</td><td>' ;
2014-02-23 20:10:05 +01:00
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $product -> price_ttc ) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $product -> price ) . '">' ;
2007-06-16 15:34:37 +02:00
}
2009-01-10 01:32:42 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2010-07-22 23:16:29 +02:00
// Price minimum
2014-02-23 20:10:05 +01:00
print '<tr><td>' ;
$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 );
2017-03-04 18:17:04 +01:00
print '</td><td>' ;
2014-02-23 20:10:05 +01:00
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price_min" size="10" value="' . price ( $object -> price_min_ttc ) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price_min" size="10" value="' . price ( $object -> price_min ) . '">' ;
2008-08-28 01:00:37 +02:00
}
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
2020-10-07 15:01:28 +02:00
print ' ' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
2014-08-29 19:19:26 +02:00
}
2017-03-04 18:17:04 +01:00
print '</td>' ;
2015-11-08 15:12:31 +01:00
print '</tr>' ;
2017-09-18 16:30:01 +02:00
2019-11-16 14:38:05 +01:00
$parameters = array ();
2019-11-12 00:15:34 +01:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-06-12 16:26:25 +02:00
2007-06-16 15:34:37 +02:00
print '</table>' ;
2021-03-07 18:41:07 +01:00
print '</div>' ;
2014-09-07 12:22:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-08-23 07:37:38 +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>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
print '<!-- Edit price per level -->' . " \n " ;
?>
2015-10-19 15:13:19 +02:00
< script >
var showHidePriceRules = function () {
2015-11-08 16:54:54 +01:00
var otherPrices = $ ( 'div.fiche form table tbody tr:not(:first)' );
var minPrice1 = $ ( 'div.fiche form input[name="price_min[1]"]' );
2015-10-19 15:13:19 +02:00
if ( jQuery ( 'input#usePriceRules' ) . prop ( 'checked' )) {
otherPrices . hide ();
minPrice1 . hide ();
} else {
otherPrices . show ();
minPrice1 . show ();
}
};
jQuery ( document ) . ready ( function () {
showHidePriceRules ();
jQuery ( 'input#usePriceRules' ) . click ( showHidePriceRules );
});
</ script >
< ? php
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2015-11-08 15:12:31 +01:00
print '<input type="hidden" name="action" value="update_price">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2015-11-07 12:19:48 +01:00
2020-10-22 22:50:03 +02:00
//print dol_get_fiche_head('', '', '', -1);
2017-06-12 16:26:25 +02:00
2019-11-12 00:15:34 +01:00
if (( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL )) {
print $langs -> trans ( 'UseMultipriceRules' ) . ' <input type="checkbox" id="usePriceRules" name="usePriceRules" ' . ( $object -> price_autogen ? 'checked' : '' ) . '><br><br>' ;
2015-11-08 15:12:31 +01:00
}
2015-11-07 12:19:48 +01:00
2021-03-07 18:41:07 +01:00
print '<div class="div-table-responsive-no-min">' ;
2015-11-08 15:12:31 +01:00
print '<table class="noborder">' ;
2016-04-18 21:02:14 +02:00
print '<thead><tr class="liste_titre">' ;
2017-06-12 16:26:25 +02:00
2016-04-18 21:02:14 +02:00
print '<td>' . $langs -> trans ( " PriceLevel " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) {
print '<td style="text-align: center">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
} else {
print '<td></td>' ;
}
2017-06-12 16:26:25 +02:00
2016-04-18 21:02:14 +02:00
print '<td class="center">' . $langs -> trans ( " SellingPrice " ) . '</td>' ;
2017-06-12 16:26:25 +02:00
2016-04-18 21:02:14 +02:00
print '<td class="center">' . $langs -> trans ( " MinPrice " ) . '</td>' ;
2015-11-08 15:12:31 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
print '<td></td>' ;
}
2016-02-26 13:37:18 +01:00
print '</tr></thead>' ;
2015-11-08 15:12:31 +01:00
2016-02-26 13:37:18 +01:00
print '<tbody>' ;
2017-06-12 16:26:25 +02:00
2021-02-26 14:25:17 +01:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-11-08 15:12:31 +01:00
print '<td>' ;
2019-12-11 17:05:42 +01:00
$text = $langs -> trans ( 'SellingPrice' ) . ' ' . $i ;
print $form -> textwithpicto ( $text , $langs -> trans ( " PrecisionUnitIsLimitedToXDecimals " , $conf -> global -> MAIN_MAX_DECIMALS_UNIT ), 1 , 1 );
2015-11-08 15:12:31 +01:00
print '</td>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
// VAT
2015-11-08 15:12:31 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) {
2020-10-07 15:01:28 +02:00
print '<td>' ;
print '<input type="hidden" name="tva_tx[' . $i . ']" value="' . ( $object -> default_vat_code ? $object -> tva_tx . ' (' . $object -> default_vat_code . ')' : $object -> tva_tx ) . '">' ;
print '<input type="hidden" name="tva_npr[' . $i . ']" value="' . $object -> tva_npr . '">' ;
print '<input type="hidden" name="localtax1_tx[' . $i . ']" value="' . $object -> localtax1_tx . '">' ;
print '<input type="hidden" name="localtax1_type[' . $i . ']" value="' . $object -> localtax1_type . '">' ;
print '<input type="hidden" name="localtax2_tx[' . $i . ']" value="' . $object -> localtax2_tx . '">' ;
print '<input type="hidden" name="localtax2_type[' . $i . ']" value="' . $object -> localtax2_type . '">' ;
print '</td>' ;
2015-11-08 15:12:31 +01:00
} else {
// This option is kept for backward compatibility but has no sense
print '<td style="text-align: center">' ;
2019-11-12 00:15:34 +01:00
print $form -> load_tva ( " tva_tx[ " . $i . ']' , $object -> multiprices_tva_tx [ $i ], $mysoc , '' , $object -> id , false , $object -> type , false , 1 );
2015-11-08 15:12:31 +01:00
print '</td>' ;
2014-02-23 20:10:05 +01:00
}
2015-11-08 15:12:31 +01:00
2010-07-22 23:16:29 +02:00
// Selling price
2015-11-08 15:12:31 +01:00
print '<td style="text-align: center">' ;
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $i ] == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price[' . $i . ']" size="10" value="' . price ( $object -> multiprices_ttc [ $i ]) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price[' . $i . ']" size="10" value="' . price ( $object -> multiprices [ $i ]) . '">' ;
2008-10-25 14:14:16 +02:00
}
2019-11-12 00:15:34 +01:00
print ' ' . $form -> selectPriceBaseType ( $object -> multiprices_base_type [ $i ], " multiprices_base_type[ " . $i . " ] " );
2015-11-08 15:12:31 +01:00
print '</td>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
// Min price
2015-11-08 15:12:31 +01:00
print '<td style="text-align: center">' ;
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $i ] == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price_min[' . $i . ']" size="10" value="' . price ( $object -> multiprices_min_ttc [ $i ]) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price_min[' . $i . ']" size="10" value="' . price ( $object -> multiprices_min [ $i ]) . '">' ;
2008-10-25 14:14:16 +02:00
}
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
2019-01-27 11:55:16 +01:00
print '<td class="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
2014-08-29 19:19:26 +02:00
}
2015-11-08 15:12:31 +01:00
print '</td>' ;
2015-08-23 07:37:38 +02:00
2015-11-08 15:12:31 +01:00
print '</tr>' ;
2008-08-28 01:00:37 +02:00
}
2015-11-07 12:19:48 +01:00
2016-02-26 13:37:18 +01:00
print '</tbody>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '</table>' ;
2021-03-07 18:41:07 +01:00
print '</div>' ;
2017-06-12 16:26:25 +02:00
2020-10-27 18:19:31 +01:00
//print dol_get_fiche_end();
2017-06-12 16:26:25 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2015-11-07 12:19:48 +01:00
print '</form>' ;
2008-10-25 14:14:16 +02:00
}
2005-06-11 13:39:38 +02:00
}
2016-09-18 13:58:17 +02:00
2017-03-04 14:18:04 +01:00
// List of price changes - log historic (ordered by descending date)
2016-09-18 13:58:17 +02:00
2021-02-26 14:25:17 +01:00
if (( empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) || $action == 'showlog_default_price' ) && ! in_array ( $action , array ( 'edit_price' , 'edit_vat' ))) {
2020-10-07 15:01:28 +02:00
$sql = " SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type, " ;
$sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty, " ;
$sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price as p, " ;
$sql .= " " . MAIN_DB_PREFIX . " user as u " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE fk_product = " . (( int ) $object -> id );
2020-10-07 15:01:28 +02:00
$sql .= " AND p.entity IN ( " . getEntity ( 'productprice' ) . " ) " ;
$sql .= " AND p.fk_user_author = u.rowid " ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $socid ) && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2021-03-30 19:12:07 +02:00
$sql .= " AND p.price_level = " . (( int ) $soc -> price_level );
2021-02-26 14:25:17 +01:00
}
2020-10-07 15:01:28 +02:00
$sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC " ;
// $sql .= $db->plimit();
2022-05-06 05:08:54 +02:00
//print $sql;
2020-10-07 15:01:28 +02:00
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $result ) {
2020-10-07 15:01:28 +02:00
print '<div class="divlogofpreviouscustomerprice">' ;
$num = $db -> num_rows ( $result );
2021-02-26 14:25:17 +01:00
if ( ! $num ) {
2020-10-07 15:01:28 +02:00
$db -> free ( $result );
2021-02-26 14:25:17 +01:00
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre a niveau (pb vieilles versions)
// We emulate the change of the price from interface with the same value than the one into table llx_product
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2022-03-08 14:49:26 +01:00
$ret = $object -> updatePrice (( $object -> multiprices_base_type [ 1 ] == 'TTC' ? $object -> multiprices_ttc [ 1 ] : $object -> multiprices [ 1 ]), $object -> multiprices_base_type [ 1 ], $user , ( empty ( $object -> multiprices_tva_tx [ 1 ]) ? 0 : $object -> multiprices_tva_tx [ 1 ]), ( $object -> multiprices_base_type [ 1 ] == 'TTC' ? $object -> multiprices_min_ttc [ 1 ] : $object -> multiprices_min [ 1 ]), 1 );
2021-02-26 14:25:17 +01:00
} else {
2022-03-08 14:49:26 +01:00
$ret = $object -> updatePrice (( $object -> price_base_type == 'TTC' ? $object -> price_ttc : $object -> price ), $object -> price_base_type , $user , $object -> tva_tx , ( $object -> price_base_type == 'TTC' ? $object -> price_min_ttc : $object -> price_min ));
2021-02-26 14:25:17 +01:00
}
2020-10-07 15:01:28 +02:00
2022-03-08 14:49:26 +01:00
if ( $ret < 0 ) {
dol_print_error ( $db , $object -> error , $object -> errors );
} else {
$result = $db -> query ( $sql );
$num = $db -> num_rows ( $result );
}
2020-10-07 15:01:28 +02:00
}
2020-11-01 17:58:41 +01:00
if ( $num > 0 ) {
2020-10-07 15:01:28 +02:00
// Default prices or
// Log of previous customer prices
2020-11-01 17:58:41 +01:00
$backbutton = '<a class="justalink" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' . $langs -> trans ( " Back " ) . '</a>' ;
2020-10-07 15:01:28 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
print_barre_liste ( $langs -> trans ( " DefaultPriceLog " ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , $backbutton , 0 , $num , 'title_accountancy.png' );
} else {
print_barre_liste ( $langs -> trans ( " PriceByCustomerLog " ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , 0 , $num , 'title_accountancy.png' );
}
2020-10-07 15:01:28 +02:00
2022-05-06 05:08:54 +02:00
print '<!-- List of log prices -->' . " \n " ;
print '<div class="div-table-responsive">' . " \n " ;
print '<table class="liste centpercent">' . " \n " ;
2020-10-07 15:01:28 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
print '<td class="center">' . $langs -> trans ( " PriceLevel " ) . '</td>' ;
}
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
print '<td class="center">' . $langs -> trans ( " Type " ) . '</td>' ;
}
print '<td class="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
print '<td class="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
}
2020-10-07 15:01:28 +02:00
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
2022-05-06 05:08:54 +02:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
print '<td class="right">' . $langs -> trans ( " INCT " ) . '</td>' ;
}
2020-10-07 15:01:28 +02:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) {
print '<td class="right">' . $langs -> trans ( " PriceExpressionSelected " ) . '</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-02-26 14:25:17 +01:00
if ( $user -> rights -> produit -> supprimer ) {
2020-10-07 15:01:28 +02:00
print '<td class="right"> </td>' ;
2021-02-26 14:25:17 +01:00
}
2020-10-07 15:01:28 +02:00
print '</tr>' ;
$notfirstlineforlevel = array ();
$i = 0 ;
2021-02-26 14:25:17 +01:00
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$objp = $db -> fetch_object ( $result );
print '<tr class="oddeven">' ;
// Date
2021-03-07 18:41:07 +01:00
print " <td> " . dol_print_date ( $db -> jdate ( $objp -> dp ), " dayhour " , 'tzuserrel' ) . " </td> " ;
2020-10-07 15:01:28 +02:00
// Price level
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
print '<td class="center">' . $objp -> price_level . " </td> " ;
}
// Price by quantity
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2020-10-07 15:01:28 +02:00
$type = ( $objp -> price_by_qty == 1 ) ? 'PriceByQuantity' : 'Standard' ;
print '<td class="center">' . $langs -> trans ( $type ) . " </td> " ;
}
print '<td class="center">' ;
if ( empty ( $objp -> price_by_qty )) {
print $langs -> trans ( $objp -> price_base_type );
}
print " </td> " ;
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
if ( empty ( $objp -> price_by_qty )) {
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $objp -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $objp -> tva_tx );
}
if ( price2num ( $objp -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $objp -> localtax1_tx );
}
if ( price2num ( $objp -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $objp -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2022-05-11 15:06:11 +02:00
echo vatrate ( $positiverates . ( $objp -> default_vat_code ? ' (' . $objp -> default_vat_code . ')' : '' ), '%' , ! empty ( $objp -> tva_npr ) ? $objp -> tva_npr : 0 );
2017-12-22 10:56:52 +01:00
/*
2021-02-26 14:25:17 +01:00
if ( $objp -> default_vat_code )
{
print vatrate ( $objp -> tva_tx , true ) . ' (' . $objp -> default_vat_code . ')' ;
}
else print vatrate ( $objp -> tva_tx , true , $objp -> recuperableonly ); */
2020-10-07 15:01:28 +02:00
}
print " </td> " ;
}
2022-05-06 05:08:54 +02:00
// Line for default price
2022-05-06 11:48:15 +02:00
if ( $objp -> price_base_type == 'HT' ) {
2022-05-06 05:08:54 +02:00
$pu = $objp -> price ;
} else {
$pu = $objp -> price_ttc ;
}
// Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code.
$localtaxarray = getLocalTaxesFromRate ( $objp -> tva_tx . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), 0 , $mysoc , $mysoc );
// Define part of HT, VAT, TTC
$resultarray = calcul_price_total ( 1 , $pu , 0 , $objp -> tva_tx , 1 , 1 , 0 , $objp -> price_base_type , $objp -> recuperableonly , $object -> type , $mysoc , $localtaxarray );
// Calcul du total ht sans remise
$total_ht = $resultarray [ 0 ];
$total_vat = $resultarray [ 1 ];
$total_localtax1 = $resultarray [ 9 ];
$total_localtax2 = $resultarray [ 10 ];
$total_ttc = $resultarray [ 2 ];
2020-10-07 15:01:28 +02:00
// Price
2021-02-26 14:25:17 +01:00
if ( ! empty ( $objp -> fk_price_expression ) && ! empty ( $conf -> dynamicprices -> enabled )) {
2020-10-07 15:01:28 +02:00
$price_expression = new PriceExpression ( $db );
$res = $price_expression -> fetch ( $objp -> fk_price_expression );
$title = $price_expression -> title ;
print '<td class="right"></td>' ;
print '<td class="right"></td>' ;
2022-05-06 05:08:54 +02:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
print '<td class="right"></td>' ;
}
2020-10-07 15:01:28 +02:00
print '<td class="right">' . $title . " </td> " ;
} else {
2022-05-06 05:08:54 +02:00
// Price HT
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
if ( empty ( $objp -> price_by_qty )) {
2022-06-09 11:47:29 +02:00
print '<span class="amount">' . price ( $objp -> price ) . '</span>' ;
2020-10-07 15:01:28 +02:00
}
print " </td> " ;
2022-05-06 05:08:54 +02:00
// Price TTC
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
if ( empty ( $objp -> price_by_qty )) {
2022-05-06 05:08:54 +02:00
$price_ttc = $objp -> price_ttc ;
2022-06-09 11:47:29 +02:00
print '<span class="amount">' . price ( $price_ttc ) . '<span>' ;
2020-10-07 15:01:28 +02:00
}
print " </td> " ;
2022-05-06 05:08:54 +02:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
print '<td class="right">' ;
print $resultarray [ 2 ];
print '</td>' ;
}
2020-10-07 15:01:28 +02:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) { //Only if module is enabled
print '<td class="right"></td>' ;
}
}
2022-05-06 05:08:54 +02:00
// Price min
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
if ( empty ( $objp -> price_by_qty )) {
print price ( $objp -> price_min );
}
print '</td>' ;
2022-05-06 05:08:54 +02:00
// Price min inc tax
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
if ( empty ( $objp -> price_by_qty )) {
2022-05-06 05:08:54 +02:00
$price_min_ttc = $objp -> price_min_ttc ;
print price ( $price_min_ttc );
2020-10-07 15:01:28 +02:00
}
print '</td>' ;
// User
print '<td class="right">' ;
if ( $objp -> user_id > 0 ) {
$userstatic = new User ( $db );
$userstatic -> fetch ( $objp -> user_id );
print $userstatic -> getNomUrl ( 1 , '' , 0 , 0 , 24 , 0 , 'login' );
}
print '</td>' ;
// Action
2021-02-26 14:25:17 +01:00
if ( $user -> rights -> produit -> supprimer ) {
2020-10-07 15:01:28 +02:00
$candelete = 0 ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
if ( empty ( $notfirstlineforlevel [ $objp -> price_level ])) {
$notfirstlineforlevel [ $objp -> price_level ] = 1 ;
} else {
$candelete = 1 ;
}
} elseif ( $i > 0 ) {
$candelete = 1 ;
}
2020-10-07 15:01:28 +02:00
print '<td class="right">' ;
2021-08-24 16:37:18 +02:00
if ( $candelete || ( $db -> jdate ( $objp -> dp ) >= dol_now ())) { // Test on date is to be able to delete a corrupted record with a date in future
2021-09-18 22:04:41 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete&token=' . newToken () . '&id=' . $object -> id . '&lineid=' . $objp -> rowid . '">' ;
2020-10-07 15:01:28 +02:00
print img_delete ();
print '</a>' ;
2021-02-26 14:25:17 +01:00
} else {
print ' ' ; // Can not delete last price (it's current price)
}
2020-10-07 15:01:28 +02:00
print '</td>' ;
}
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $result );
print " </table> " ;
print '</div>' ;
print " <br> " ;
}
print '</div>' ;
} else {
dol_print_error ( $db );
}
2004-07-13 10:28:37 +02:00
}
2015-02-24 12:58:43 +01:00
2015-06-19 12:13:05 +02:00
// Add area to show/add/edit a price for a dedicated customer
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2014-02-23 20:10:05 +01:00
$prodcustprice = new Productcustomerprice ( $db );
2014-09-07 12:22:04 +02:00
2020-04-20 15:06:27 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2019-11-12 00:15:34 +01:00
$page = ( GETPOST ( " page " , 'int' ) ? GETPOST ( " page " , 'int' ) : 0 );
2021-02-26 14:25:17 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2020-04-20 15:06:27 +02:00
$offset = $limit * $page ;
2014-02-23 16:16:47 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 14:25:17 +01:00
if ( ! $sortorder ) {
2014-02-23 16:16:47 +01:00
$sortorder = " ASC " ;
2021-02-26 14:25:17 +01:00
}
if ( ! $sortfield ) {
2014-02-23 16:16:47 +01:00
$sortfield = " soc.nom " ;
2021-02-26 14:25:17 +01:00
}
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Build filter to diplay only concerned lines
2014-02-23 20:10:05 +01:00
$filter = array ( 't.fk_product' => $object -> id );
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
if ( ! empty ( $search_soc )) {
2015-06-19 12:13:05 +02:00
$filter [ 'soc.nom' ] = $search_soc ;
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( $action == 'add_customer_price' ) {
2016-02-14 20:48:25 +01:00
// Form to add a new customer price
2014-08-29 19:19:26 +02:00
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2022-08-10 14:32:26 +02:00
print '<!-- add_customer_price -->' ;
print load_fiche_titre ( $langs -> trans ( 'AddCustomerPrice' ));
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $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-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2017-06-12 16:26:25 +02:00
2022-08-10 14:32:26 +02:00
print '<div class="tabBar tabBarWithBottom">' ;
print '<table class="border centpercent">' ;
2014-02-23 16:16:47 +01:00
print '<tr>' ;
2019-11-12 00:15:34 +01:00
print '<td class="fieldrequired">' . $langs -> trans ( 'ThirdParty' ) . '</td>' ;
2014-02-23 16:16:47 +01:00
print '<td>' ;
2021-03-07 18:56:16 +01:00
print img_picto ( '' , 'company' ) . $form -> select_company ( '' , 'socid' , 's.client IN (1,2,3)' , 'SelectThirdParty' , 0 , 0 , array (), 0 , 'minwidth300' );
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
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
print '<td><input name="ref_customer" size="12"></td></tr>' ;
2014-02-23 16:16:47 +01:00
// VAT
2019-11-12 00:15:34 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2017-05-12 13:12:17 +02:00
print $form -> load_tva ( " tva_tx " , $object -> default_vat_code ? $object -> tva_tx . ' (' . $object -> default_vat_code . ')' : $object -> tva_tx , $mysoc , '' , $object -> id , $object -> tva_npr , $object -> type , 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
2016-02-14 20:48:25 +01:00
print '<tr><td class="fieldrequired">' ;
2014-02-23 20:10:05 +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
2016-02-14 20:48:25 +01:00
print '<tr><td class="fieldrequired">' ;
2014-02-23 20:10:05 +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>' ;
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $object -> price_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $object -> price ) . '">' ;
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 20:10:05 +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 );
2014-02-23 16:16:47 +01:00
if ( $object -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<td><input name="price_min" size="10" value="' . price ( $object -> price_min_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<td><input name="price_min" size="10" value="' . price ( $object -> price_min ) . '">' ;
2014-02-23 16:16:47 +01:00
}
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
2019-01-27 11:55:16 +01:00
print '<td class="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
2014-08-29 19:19:26 +02:00
}
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
print '</table>' ;
2014-09-07 12:22:04 +02:00
2022-08-10 14:32:26 +02:00
print '</div>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<div class="center">' ;
2019-07-15 23:56:05 +02:00
// Update all child soc
print '<div class="marginbottomonly">' ;
2021-03-07 18:56:16 +01:00
print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ' ;
print '<label for="updatechildprice">' . $langs -> trans ( 'ForceUpdateChildPriceSoc' ) . '</label>' ;
2019-07-15 23:56:05 +02:00
print '</div>' ;
2019-09-23 21:55:30 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
print '</form>' ;
2021-02-26 14:25:17 +01:00
} elseif ( $action == 'edit_customer_price' ) {
2014-02-23 16:16:47 +01:00
// Edit mode
2014-08-29 19:19:26 +02:00
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2022-08-10 14:32:26 +02:00
print '<!-- edit_customer_price -->' ;
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 20:10:05 +01:00
$result = $prodcustprice -> fetch ( GETPOST ( 'lineid' , 'int' ));
2014-02-23 16:16:47 +01:00
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $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="update_customer_price_confirm">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="lineid" value="' . $prodcustprice -> id . '">' ;
2017-07-07 14:58:57 +02:00
2020-12-19 15:56:21 +01:00
print '<table class="liste centpercent">' ;
2014-02-23 16:16:47 +01:00
print '<tr>' ;
2021-03-07 18:56:16 +01:00
print '<td class="titlefield fieldrequired">' . $langs -> trans ( 'ThirdParty' ) . '</td>' ;
2014-02-23 20:10:05 +01:00
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( $prodcustprice -> fk_soc );
2021-03-07 18:56:16 +01:00
print " <td> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
2014-02-23 16:16:47 +01:00
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2020-10-26 12:18:24 +01:00
// Ref. Customer
print '<tr><td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
print '<td><input name="ref_customer" size="12" value="' . dol_escape_htmltag ( $prodcustprice -> ref_customer ) . '"></td></tr>' ;
2014-02-23 16:16:47 +01:00
// VAT
2021-03-07 18:56:16 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2017-05-12 13:12:17 +02:00
print $form -> load_tva ( " tva_tx " , $prodcustprice -> default_vat_code ? $prodcustprice -> tva_tx . ' (' . $prodcustprice -> default_vat_code . ')' : $prodcustprice -> tva_tx , $mysoc , '' , $object -> id , $prodcustprice -> recuperableonly , $object -> type , false , 1 );
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
2017-06-12 16:26:25 +02:00
2014-02-23 16:16:47 +01:00
// Price base
2021-03-07 18:56:16 +01:00
print '<tr><td class="fieldrequired">' ;
2014-02-23 20:10:05 +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 ( $prodcustprice -> 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
2021-03-07 18:56:16 +01:00
print '<tr><td class="fieldrequired">' ;
2014-02-23 20:10:05 +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>' ;
if ( $prodcustprice -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $prodcustprice -> price_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price" size="10" value="' . price ( $prodcustprice -> price ) . '">' ;
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 20:10:05 +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 );
2014-09-07 12:22:04 +02:00
print '</td><td>' ;
2014-02-23 16:16:47 +01:00
if ( $prodcustprice -> price_base_type == 'TTC' ) {
2019-11-12 00:15:34 +01:00
print '<input name="price_min" size="10" value="' . price ( $prodcustprice -> price_min_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2019-11-12 00:15:34 +01:00
print '<input name="price_min" size="10" value="' . price ( $prodcustprice -> price_min ) . '">' ;
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
print '</td>' ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE )) {
2019-01-27 11:55:16 +01:00
print '<td class="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
2014-08-29 19:19:26 +02:00
}
2014-09-07 12:22:04 +02:00
print '</tr>' ;
2014-02-23 16:16:47 +01:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2017-07-07 14:58:57 +02:00
print '<div class="center">' ;
2019-07-15 23:56:05 +02:00
print '<div class="marginbottomonly">' ;
2021-03-07 18:56:16 +01:00
print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ' ;
print '<label for="updatechildprice">' . $langs -> trans ( 'ForceUpdateChildPriceSoc' ) . '</label>' ;
2019-07-15 23:56:05 +02:00
print " </div> " ;
2019-09-23 21:55:30 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<br></form>' ;
2021-02-26 14:25:17 +01:00
} elseif ( $action == 'showlog_customer_price' ) {
2017-07-07 14:58:57 +02:00
// List of all log of prices by customers
2019-01-24 19:45:17 +01:00
print '<!-- list of all log of prices per customer -->' . " \n " ;
2017-07-07 14:58:57 +02:00
2020-10-07 15:01:28 +02:00
$filter = array ( 't.fk_product' => $object -> id , 't.fk_soc' => GETPOST ( 'socid' , 'int' ));
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 20:10:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
$nbtotalofrecords = $prodcustprice -> fetch_all_log ( $sortorder , $sortfield , $conf -> liste_limit , $offset , $filter );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
$result = $prodcustprice -> fetch_all_log ( $sortorder , $sortfield , $conf -> liste_limit , $offset , $filter );
2014-02-23 16:16:47 +01:00
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
$option = '&socid=' . GETPOST ( 'socid' , 'int' ) . '&id=' . $object -> id ;
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( GETPOST ( 'socid' , 'int' ));
2017-06-12 16:26:25 +02:00
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( 'PriceByCustomerLog' );
$title .= ' - ' . $staticsoc -> getNomUrl ( 1 );
2016-02-26 13:37:18 +01:00
2019-11-12 00:15:34 +01:00
$backbutton = '<a class="justalink" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' . $langs -> trans ( " Back " ) . '</a>' ;
2017-06-12 16:26:25 +02:00
2019-05-15 19:12:33 +02:00
print_barre_liste ( $title , $page , $_SERVER [ 'PHP_SELF' ], $option , $sortfield , $sortorder , $backbutton , count ( $prodcustprice -> lines ), $nbtotalofrecords , 'title_accountancy.png' );
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( count ( $prodcustprice -> lines ) > 0 ) {
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2014-09-07 12:22:04 +02:00
2021-03-07 18:41:07 +01:00
print '<div class="div-table-responsive-no-min">' ;
2020-12-19 15:56:21 +01:00
print '<table class="liste centpercent">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<tr class="liste_titre">' ;
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
2020-10-26 11:50:04 +01:00
print '<td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
2022-05-06 12:37:18 +02:00
print '<td class="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
2019-11-12 00:15:34 +01:00
print '<td class="right">' . $langs -> trans ( " INCT " ) . '</td>' ;
2017-11-13 14:02:17 +01:00
}
2019-11-12 00:15:34 +01:00
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>' ;
2014-02-23 16:16:47 +01:00
print '<td> </td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
foreach ( $prodcustprice -> lines as $line ) {
2020-10-07 15:01:28 +02:00
// Date
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( $line -> fk_soc );
2017-07-07 14:58:57 +02:00
$tva_tx = $line -> default_vat_code ? $line -> tva_tx . ' (' . $line -> default_vat_code . ')' : $line -> tva_tx ;
// Line for default price
2021-02-26 14:25:17 +01:00
if ( $line -> price_base_type == 'HT' ) {
2020-10-07 15:01:28 +02:00
$pu = $line -> price ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
$pu = $line -> price_ttc ;
2017-07-07 14:58:57 +02:00
}
// Local tax is not saved into table of product. We use value linked to VAT code.
2019-11-12 00:15:34 +01:00
$localtaxarray = getLocalTaxesFromRate ( $line -> tva_tx . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), 0 , $staticsoc , $mysoc );
2017-07-07 14:58:57 +02:00
// Define part of HT, VAT, TTC
2019-11-12 00:15:34 +01:00
$resultarray = calcul_price_total ( 1 , $pu , 0 , $line -> tva_tx , 1 , 1 , 0 , $line -> price_base_type , $line -> recuperableonly , $object -> type , $mysoc , $localtaxarray );
2017-07-07 14:58:57 +02:00
// Calcul du total ht sans remise
$total_ht = $resultarray [ 0 ];
$total_vat = $resultarray [ 1 ];
$total_localtax1 = $resultarray [ 9 ];
$total_localtax2 = $resultarray [ 10 ];
$total_ttc = $resultarray [ 2 ];
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
print " <td> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
2021-03-07 19:07:18 +01:00
print '<td>' . $line -> ref_customer . '</td>' ;
2021-03-07 18:41:07 +01:00
print " <td> " . dol_print_date ( $line -> datec , " dayhour " , 'tzuserrel' ) . " </td> " ;
2020-10-07 15:01:28 +02:00
print '<td class="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2017-11-13 14:02:17 +01:00
2019-11-12 00:15:34 +01:00
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $line -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> tva_tx );
}
if ( price2num ( $line -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> localtax1_tx );
}
if ( price2num ( $line -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2017-11-13 14:02:17 +01:00
2019-11-12 00:15:34 +01:00
echo vatrate ( $positiverates . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), '%' , ( $line -> tva_npr ? $line -> tva_npr : $line -> recuperableonly ));
2017-09-25 21:41:53 +02:00
//. vatrate($tva_tx, true, $line->recuperableonly) .
print " </td> " ;
2022-06-09 11:47:29 +02:00
print '<td class="right"><span class="amount">' . price ( $line -> price ) . " </span></td> " ;
2017-07-07 12:31:00 +02:00
2022-06-09 11:47:29 +02:00
print '<td class="right"><span class="amount">' . price ( $line -> price_ttc ) . " </span></td> " ;
2021-02-26 14:25:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
2019-11-12 00:15:34 +01:00
print '<td class="right">' . price ( $resultarray [ 2 ]) . '</td>' ;
2017-11-13 14:02:17 +01:00
}
2017-07-07 14:58:57 +02:00
2019-11-12 00:15:34 +01:00
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
2014-02-23 20:10:05 +01:00
$userstatic = new User ( $db );
2014-02-23 16:16:47 +01:00
$userstatic -> fetch ( $line -> fk_user );
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2019-11-28 16:16:55 +01:00
print $userstatic -> getNomUrl ( 1 , '' , 0 , 0 , 24 , 0 , 'login' );
//print $userstatic->getLoginUrl(1);
2014-02-23 16:16:47 +01:00
print '</td>' ;
2017-07-07 12:31:00 +02:00
print '</tr>' ;
2014-02-23 20:10:05 +01:00
}
print " </table> " ;
2021-03-07 18:41:07 +01:00
print '</div>' ;
2014-02-23 20:10:05 +01:00
} else {
print $langs -> trans ( 'None' );
2014-02-23 16:16:47 +01:00
}
2021-02-26 14:25:17 +01:00
} elseif ( $action != 'showlog_default_price' && $action != 'edit_price' ) {
2016-02-26 13:37:18 +01:00
// List of all prices by customers
2020-10-07 15:01:28 +02:00
print '<!-- list of all prices per customer -->' . " \n " ;
2017-06-12 16:26:25 +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 20:10:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2016-01-10 12:37:48 +01:00
$nbtotalofrecords = $prodcustprice -> fetch_all ( $sortorder , $sortfield , 0 , 0 , $filter );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
$result = $prodcustprice -> fetch_all ( $sortorder , $sortfield , $conf -> liste_limit , $offset , $filter );
2014-02-23 16:16:47 +01:00
if ( $result < 0 ) {
2015-12-14 20:54:55 +01:00
setEventMessages ( $prodcustprice -> error , $prodcustprice -> errors , 'errors' );
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
$option = '&search_soc=' . $search_soc . '&id=' . $object -> id ;
2014-09-07 12:22:04 +02:00
2019-05-15 19:12:33 +02:00
print_barre_liste ( $langs -> trans ( 'PriceByCustomer' ), $page , $_SERVER [ 'PHP_SELF' ], $option , $sortfield , $sortorder , '' , count ( $prodcustprice -> lines ), $nbtotalofrecords , 'title_accountancy.png' );
2014-09-07 12:22:04 +02:00
2019-11-12 00:15:34 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2020-07-06 15:34:26 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-12 00:15:34 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2014-09-07 12:22:04 +02:00
2022-05-06 05:08:54 +02:00
print '<!-- List of prices per customer -->' . " \n " ;
print '<div class="div-table-responsive-no-min">' . " \n " ;
print '<table class="liste centpercent">' . " \n " ;
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( count ( $prodcustprice -> lines ) > 0 || $search_soc ) {
2020-10-26 11:50:04 +01:00
$colspan = 9 ;
2022-05-06 05:08:54 +02:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
$colspan ++ ;
}
2017-07-07 12:31:00 +02:00
2020-10-07 15:01:28 +02:00
print '<tr class="liste_titre">' ;
2022-10-20 18:23:41 +02:00
print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="' . $search_soc . '"></td>' ;
2020-10-07 15:01:28 +02:00
print '<td class="liste_titre" colspan="' . $colspan . '"> </td>' ;
// Print the search button
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
2017-07-07 12:31:00 +02:00
}
2015-02-24 12:58:43 +01:00
print '<tr class="liste_titre">' ;
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
2022-10-20 18:23:41 +02:00
print '<td>' . $langs -> trans ( 'RefCustomer' ) . '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " HT " ) . '</td>' ;
2022-05-06 05:08:54 +02:00
print '<td class="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
2019-11-12 00:15:34 +01:00
print '<td class="right">' . $langs -> trans ( " INCT " ) . '</td>' ;
2017-11-13 14:02:17 +01:00
}
2019-11-12 00:15:34 +01:00
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-07 18:41:07 +01:00
print '<td></td>' ;
2015-02-24 12:58:43 +01:00
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2017-07-07 12:31:00 +02:00
// Line for default price
2021-02-26 14:25:17 +01:00
if ( $object -> price_base_type == 'HT' ) {
2020-10-07 15:01:28 +02:00
$pu = $object -> price ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
$pu = $object -> price_ttc ;
2015-12-20 20:24:12 +01:00
}
2017-06-12 16:26:25 +02:00
2022-05-06 05:08:54 +02:00
// Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code.
2019-11-12 00:15:34 +01:00
$localtaxarray = getLocalTaxesFromRate ( $object -> tva_tx . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), 0 , $mysoc , $mysoc );
2017-07-07 12:31:00 +02:00
// Define part of HT, VAT, TTC
2019-11-12 00:15:34 +01:00
$resultarray = calcul_price_total ( 1 , $pu , 0 , $object -> tva_tx , 1 , 1 , 0 , $object -> price_base_type , $object -> recuperableonly , $object -> type , $mysoc , $localtaxarray );
2017-07-07 12:31:00 +02:00
// Calcul du total ht sans remise
$total_ht = $resultarray [ 0 ];
$total_vat = $resultarray [ 1 ];
$total_localtax1 = $resultarray [ 9 ];
$total_localtax2 = $resultarray [ 10 ];
$total_ttc = $resultarray [ 2 ];
2017-06-12 16:26:25 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2020-10-26 11:50:04 +01:00
print '<td colspan="3">' . $langs -> trans ( 'Default' ) . '</td>' ;
2017-06-12 16:26:25 +02:00
2019-11-12 00:15:34 +01:00
print '<td class="center">' . $langs -> trans ( $object -> price_base_type ) . " </td> " ;
2022-10-20 18:23:41 +02:00
// VAT Rate
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2017-09-25 21:41:53 +02:00
2019-11-12 00:15:34 +01:00
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $object -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> tva_tx );
}
if ( price2num ( $object -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax1_tx );
}
if ( price2num ( $object -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2019-11-12 00:15:34 +01:00
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
2017-09-25 21:41:53 +02:00
//print vatrate($object->tva_tx, true, $object->tva_npr);
//print $object->default_vat_code?' ('.$object->default_vat_code.')':'';
2017-06-23 12:09:21 +02:00
print " </td> " ;
2017-07-07 12:31:00 +02:00
2022-10-20 18:23:41 +02:00
print '<td class="right"><span class="amount">' . price ( $object -> price ) . " </span></td> " ;
2017-07-07 12:31:00 +02:00
2022-10-20 18:23:41 +02:00
print '<td class="right"><span class="amount">' . price ( $object -> price_ttc ) . " </span></td> " ;
2021-02-26 14:25:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
2019-02-24 11:18:55 +01:00
//print '<td class="right">' . price($object->price_ttc) . "</td>";
2022-10-20 18:23:41 +02:00
print '<td class="right"><span class="amount">' . price ( $resultarray [ 2 ]) . '</span></td>' ;
2017-11-13 14:02:17 +01:00
}
2019-11-12 00:15:34 +01:00
print '<td class="right">' . price ( $object -> price_min ) . '</td>' ;
print '<td class="right">' . price ( $object -> price_min_ttc ) . '</td>' ;
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2016-02-26 13:37:18 +01:00
print '</td>' ;
2021-02-26 14:25:17 +01:00
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer ) {
2021-03-07 18:41:07 +01:00
print '<td class="nowraponall">' ;
2021-09-27 12:24:01 +02:00
print '<a class="marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=showlog_default_price&token=' . newToken () . '&id=' . $object -> id . '">' ;
2020-10-07 15:01:28 +02:00
print img_info ( $langs -> trans ( 'PriceByCustomerLog' ));
print '</a>' ;
print ' ' ;
2021-09-27 12:24:01 +02:00
print '<a class="marginleftonly marginrightonly editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit_price&token=' . newToken () . '&id=' . $object -> id . '">' ;
2020-10-07 15:01:28 +02:00
print img_edit ( 'default' , 0 , 'style="vertical-align: middle;"' );
print '</a>' ;
print '</td>' ;
2016-02-26 13:37:18 +01:00
}
print " </tr> \n " ;
2014-09-07 12:22:04 +02:00
2021-02-26 14:25:17 +01:00
if ( count ( $prodcustprice -> lines ) > 0 ) {
foreach ( $prodcustprice -> lines as $line ) {
2014-02-23 16:16:47 +01:00
// Date
2014-02-23 20:10:05 +01:00
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( $line -> fk_soc );
2014-09-07 12:22:04 +02:00
2017-05-12 13:12:17 +02:00
$tva_tx = $line -> default_vat_code ? $line -> tva_tx . ' (' . $line -> default_vat_code . ')' : $line -> tva_tx ;
2017-06-12 16:26:25 +02:00
2017-07-07 12:31:00 +02:00
// Line for default price
2021-02-26 14:25:17 +01:00
if ( $line -> price_base_type == 'HT' ) {
2020-10-07 15:01:28 +02:00
$pu = $line -> price ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
$pu = $line -> price_ttc ;
2017-07-07 12:31:00 +02:00
}
// Local tax is not saved into table of product. We use value linked to VAT code.
2019-11-12 00:15:34 +01:00
$localtaxarray = getLocalTaxesFromRate ( $line -> tva_tx . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), 0 , $staticsoc , $mysoc );
2017-07-07 12:31:00 +02:00
// Define part of HT, VAT, TTC
2019-11-12 00:15:34 +01:00
$resultarray = calcul_price_total ( 1 , $pu , 0 , $line -> tva_tx , 1 , 1 , 0 , $line -> price_base_type , $line -> recuperableonly , $object -> type , $mysoc , $localtaxarray );
2017-07-07 12:31:00 +02:00
// Calcul du total ht sans remise
$total_ht = $resultarray [ 0 ];
$total_vat = $resultarray [ 1 ];
$total_localtax1 = $resultarray [ 9 ];
$total_localtax2 = $resultarray [ 10 ];
$total_ttc = $resultarray [ 2 ];
2017-07-07 14:58:57 +02:00
print '<tr class="oddeven">' ;
2019-11-12 00:15:34 +01:00
print " <td> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
2022-06-09 11:47:29 +02:00
print '<td>' . dol_escape_htmltag ( $line -> ref_customer ) . '</td>' ;
2021-03-07 18:41:07 +01:00
print " <td> " . dol_print_date ( $line -> datec , " dayhour " , 'tzuserrel' ) . " </td> " ;
2019-11-12 00:15:34 +01:00
print '<td class="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
2022-10-20 18:23:41 +02:00
// VAT Rate
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2017-09-25 21:41:53 +02:00
2019-11-12 00:15:34 +01:00
$positiverates = '' ;
2021-02-26 14:25:17 +01:00
if ( price2num ( $line -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> tva_tx );
}
if ( price2num ( $line -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> localtax1_tx );
}
if ( price2num ( $line -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $line -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2021-03-07 18:41:07 +01:00
2019-11-12 00:15:34 +01:00
echo vatrate ( $positiverates . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), '%' , ( $line -> tva_npr ? $line -> tva_npr : $line -> recuperableonly ));
2017-09-25 21:41:53 +02:00
print " </td> " ;
2022-10-20 18:23:41 +02:00
2022-06-09 11:47:29 +02:00
print '<td class="right"><span class="amount">' . price ( $line -> price ) . " </span></td> " ;
2017-07-07 12:31:00 +02:00
2022-06-09 11:47:29 +02:00
print '<td class="right"><span class="amount">' . price ( $line -> price_ttc ) . " </span></td> " ;
2021-02-26 14:25:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " ) {
2019-02-24 11:18:55 +01:00
//print '<td class="right">' . price($line->price_ttc) . "</td>";
2022-10-20 18:23:41 +02:00
print '<td class="right"><span class="amount">' . price ( $resultarray [ 2 ]) . '</span></td>' ;
2017-11-13 14:02:17 +01:00
}
2017-07-07 12:31:00 +02:00
2019-11-12 00:15:34 +01:00
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
2014-02-23 20:10:05 +01:00
$userstatic = new User ( $db );
2014-02-23 16:16:47 +01:00
$userstatic -> fetch ( $line -> fk_user );
2019-02-24 11:18:55 +01:00
print '<td class="right">' ;
2019-11-28 16:16:55 +01:00
print $userstatic -> getNomUrl ( 1 , '' , 0 , 0 , 24 , 0 , 'login' );
2014-02-23 16:16:47 +01:00
print '</td>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Todo Edit or delete button
// Action
2021-02-26 14:25:17 +01:00
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer ) {
2019-07-15 23:56:05 +02:00
print '<td class="right nowraponall">' ;
2021-09-27 12:24:01 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=showlog_customer_price&token=' . newToken () . '&id=' . $object -> id . '&socid=' . $line -> fk_soc . '">' ;
2016-02-26 13:37:18 +01:00
print img_info ( $langs -> trans ( 'PriceByCustomerLog' ));
2014-02-23 16:16:47 +01:00
print '</a>' ;
2015-06-19 12:13:05 +02:00
print ' ' ;
2021-09-27 12:24:01 +02:00
print '<a class="marginleftonly editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit_customer_price&token=' . newToken () . '&id=' . $object -> id . '&lineid=' . $line -> id . '">' ;
2015-06-19 12:13:05 +02:00
print img_edit ( 'default' , 0 , 'style="vertical-align: middle;"' );
2014-02-23 16:16:47 +01:00
print '</a>' ;
2015-06-19 12:13:05 +02:00
print ' ' ;
2021-09-18 22:04:41 +02:00
print '<a class="marginleftonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete_customer_price&token=' . newToken () . '&id=' . $object -> id . '&lineid=' . $line -> id . '">' ;
2015-06-19 12:13:05 +02:00
print img_delete ( 'default' , 'style="vertical-align: middle;"' );
2014-02-23 16:16:47 +01:00
print '</a>' ;
print '</td>' ;
}
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print " </tr> \n " ;
}
2015-06-19 12:13:05 +02:00
}
2014-09-07 12:22:04 +02:00
2015-02-24 12:58:43 +01:00
print " </table> " ;
2021-03-07 18:41:07 +01:00
print '</div>' ;
2015-02-24 12:58:43 +01:00
print " </form> " ;
2014-02-23 16:16:47 +01:00
}
}
2018-08-15 12:48:13 +02:00
// End of page
2012-01-08 10:53:05 +01:00
llxFooter ();
2004-07-13 10:28:37 +02:00
$db -> close ();