2004-10-20 22:06:49 +02:00
< ? php
2017-09-18 16:30:01 +02: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 >
2017-09-18 16:30:01 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ capnetworks . com >
* 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 >
2016-12-10 23:25:13 +01:00
* Copyright ( C ) 2014 - 2016 Juanjo Menent < jmenent @ 2 byte . es >
2015-12-14 20:54:55 +01:00
* Copyright ( C ) 2014 - 2015 Philippe Grand < philippe . grand @ atoo - net . com >
2015-02-24 12:58:43 +01:00
* Copyright ( C ) 2014 Ion agorria < ion @ agorria . com >
2015-08-23 07:37:38 +02:00
* Copyright ( C ) 2015 Alexandre Spangaro < aspangaro . dolibarr @ gmail . com >
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 >
2018-02-05 17:47:29 +01:00
* Copyright ( C ) 2018 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
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// 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
*/
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2014-02-23 20:10:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2017-07-07 12:31:00 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php' ;
2014-02-23 20:10:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2015-03-14 16:50:02 +01:00
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
2014-02-23 20:10:05 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2014-02-23 16:16:47 +01:00
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
$langs -> loadLangs ( array ( 'products' , 'bills' , 'companies' ));
2004-08-02 04:00:18 +02:00
2015-06-12 13:21:21 +02:00
$mesg = '' ; $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' );
$action = GETPOST ( 'action' , 'alpha' );
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
2012-02-11 11:44:15 +01:00
$fieldvalue = ( ! empty ( $id ) ? $id : ( ! empty ( $ref ) ? $ref : '' ));
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2015-04-02 19:41:19 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2014-02-23 20:10:05 +01:00
$result = restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
2007-06-16 15:06:05 +02:00
2015-06-10 18:42:16 +02:00
if ( $id > 0 || ! empty ( $ref ))
{
$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
2018-05-23 17:05:08 +02: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
2015-06-10 18:42:16 +02:00
$hookmanager -> initHooks ( array ( 'productpricecard' , 'globalcard' ));
2014-08-29 19:19:26 +02:00
2014-12-14 16:01:25 +01:00
2005-06-11 13:39:38 +02:00
/*
* Actions
*/
2015-06-10 18:42:16 +02:00
if ( $cancel ) $action = '' ;
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02: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
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
if ( empty ( $reshook ))
{
2017-07-13 00:35:10 +02:00
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
2015-12-20 20:24:12 +01:00
{
2017-06-12 16:26:25 +02:00
$search_soc = '' ;
2015-12-20 20:24:12 +01:00
}
2017-06-12 16:26:25 +02:00
2016-08-29 16:30:31 +02:00
if ( $action == 'setlabelsellingprice' && $user -> admin )
{
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
2015-10-25 22:50:05 +01:00
if (( $action == 'update_vat' ) && ! $cancel && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
2014-05-01 12:19:24 +02:00
{
2016-04-18 21:02:14 +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)'
2016-09-02 22:37:01 +02:00
2016-02-19 02:41:00 +01:00
// We must define tva_tx, npr and local taxes
2017-09-25 21:41:53 +02:00
$tva_tx = $tva_tx_txt ;
2016-04-18 21:02:14 +02:00
$vatratecode = '' ;
2017-09-25 21:41:53 +02:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
$vat_src_code = $reg [ 1 ];
$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
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
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
2017-06-23 12:09:21 +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.
2016-02-19 02:41:00 +01:00
$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 = ' " . $mysoc -> country_code . " ' " ;
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
$sql .= " AND t.code =' " . $vatratecode . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
2016-04-18 21:02:14 +02:00
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
2016-02-19 02:41:00 +01:00
}
}
2016-04-18 21:02:14 +02:00
$object -> default_vat_code = $vatratecode ;
2016-02-19 02:41:00 +01:00
$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 ;
2016-04-18 21:02:14 +02:00
2015-10-25 22:50:05 +01:00
$db -> begin ();
2016-04-18 21:02:14 +02:00
2015-10-25 22:50:05 +01:00
$resql = $object -> update ( $object -> id , $user );
2018-05-17 21:29:15 +02:00
if ( ! $resql || $resql < 0 )
2015-10-25 22:50:05 +01:00
{
$error ++ ;
2016-04-18 21:02:14 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-10-25 22:50:05 +01:00
}
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
if ( $error )
{
2016-04-18 21:02:14 +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 retreive them.
$object -> updatePrice ( 0 , $object -> price_base_type , $user , $tva_tx , '' , 0 , $npr , 0 , 0 , $localtaxarray , $vatratecode );
2015-10-25 22:50:05 +01:00
}
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
if ( ! $error )
{
$db -> commit ();
}
else
{
$db -> rollback ();
}
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
$action = '' ;
}
2017-06-12 16:26:25 +02:00
2015-11-07 12:19:48 +01:00
if (( $action == 'update_price' ) && ! $cancel && $object -> getRights () -> creer )
2015-10-25 22:50:05 +01:00
{
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 ) {
$error ++ ;
2015-12-14 20:54:55 +01:00
setEventMessages ( $priceparser -> translatedError (), null , 'errors' );
2015-11-07 12:19:48 +01:00
}
}
}
// Multiprices
2018-05-23 17:05:08 +02: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
2017-06-12 16:26:25 +02:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ )
2016-02-19 02:41:00 +01:00
{
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 = '' ;
2017-09-25 21:41:53 +02:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
$vat_src_code = $reg [ 1 ];
$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
2016-04-18 21:02:14 +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 ];
2016-04-18 21:02:14 +02:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
// 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 = ' " . $mysoc -> country_code . " ' " ;
$sql .= " AND t.taux = " . (( float ) $tva_tx ) . " AND t.active = 1 " ;
$sql .= " AND t.code =' " . $vatratecode . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
2017-06-12 16:26:25 +02:00
}
2016-04-18 21:02:14 +02:00
}
2015-11-07 12:19:48 +01:00
$pricestoupdate [ $i ] = array (
'price' => $newprice [ $i ],
'price_min' => $newprice_min [ $i ],
'price_base_type' => $newpricebase [ $i ],
2016-04-18 21:02:14 +02:00
'default_vat_code' => $vatratecode ,
'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
'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
}
2016-04-18 21:02:14 +02:00
}
elseif ( ! $error )
{
$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 = '' ;
2017-09-25 21:41:53 +02:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
$vat_src_code = $reg [ 1 ];
$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
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
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
// 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 = ' " . $mysoc -> country_code . " ' " ;
2017-09-25 21:41:53 +02:00
$sql .= " AND t.taux = " . $tva_tx . " AND t.active = 1 " ;
2016-02-19 02:41:00 +01:00
$sql .= " AND t.code =' " . $vatratecode . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
2016-12-19 02:33:54 +01:00
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
2016-02-19 02:41:00 +01:00
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
2016-12-19 02:33:54 +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
if ( in_array ( $mysoc -> country_code , array ( 'ES' )))
{
$localtax1 = get_localtax ( $tva_tx , 1 );
$localtax2 = get_localtax ( $tva_tx , 2 );
}
2016-02-19 02:41:00 +01:00
}
}
2015-11-07 12:19:48 +01:00
$pricestoupdate [ 0 ] = array (
2016-02-19 02:41:00 +01:00
'price' => $_POST [ " price " ],
'price_min' => $_POST [ " price_min " ],
'price_base_type' => $_POST [ " price_base_type " ],
2016-04-18 21:02:14 +02:00
'default_vat_code' => $vatratecode ,
'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
'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 ) {
2015-10-19 15:13:19 +02:00
2015-11-07 12:19:48 +01:00
$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' );
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' );
2015-10-19 15:13:19 +02: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
2016-04-18 21:02:14 +02: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' ]);
2015-11-07 12:19:48 +01:00
if ( $res < 0 ) {
2015-10-19 15:13:19 +02: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
2015-06-10 18:42:16 +02:00
if ( $action == 'delete' && $user -> rights -> produit -> supprimer )
{
2017-12-22 10:56:52 +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
if ( $action == 'activate_price_by_qty' )
{
// Activating product price by quantity add a new price line with price_by_qty set to 1
$level = GETPOST ( 'level' , 'int' );
2015-06-10 18:42:16 +02:00
$object -> updatePrice ( 0 , $object -> price_base_type , $user , $object -> tva_tx , 0 , $level , $object -> tva_npr , 1 );
2012-11-07 00:38:53 +01:00
}
2017-12-22 10:56:52 +01:00
// Unset Price by quantity
if ( $action == 'disable_price_by_qty' )
{
// Disabling product price by quantity add a new price line with price_by_qty set to 0
$level = GETPOST ( 'level' , 'int' );
$object -> updatePrice ( 0 , $object -> price_base_type , $user , $object -> tva_tx , 0 , $level , $object -> tva_npr , 0 );
}
2015-06-10 18:42:16 +02:00
2015-06-19 12:13:05 +02:00
if ( $action == 'edit_price_by_qty' )
{ // Edition d'un prix par quantité
2017-12-22 10:56:52 +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
2015-06-19 12:13:05 +02:00
if ( $action == 'update_price_by_qty' )
2017-12-22 10:56:52 +01:00
{
2015-06-10 18:42:16 +02:00
// Récupération des variables
2018-01-08 20:54:40 +01:00
$rowid = GETPOST ( 'rowid' , 'int' );
$priceid = GETPOST ( 'priceid' , 'int' );
2018-01-11 00:40:33 +01:00
$newprice = price2num ( GETPOST ( " price " , 'alpha' ), 'MU' );
2015-06-10 18:42:16 +02:00
// $newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
2018-01-08 20:54:40 +01:00
$quantity = GETPOST ( 'quantity' , 'int' );
2018-01-11 00:40:33 +01:00
$remise_percent = price2num ( GETPOST ( 'remise_percent' , 'alpha' ));
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
}
if ( ! $error ) {
// 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 ) {
$sql = " UPDATE " . MAIN_DB_PREFIX . " product_price_by_qty SET " ;
$sql .= " price=' " . $price . " ', " ;
$sql .= " unitprice= " . $unitPrice . " , " ;
$sql .= " quantity= " . $quantity . " , " ;
$sql .= " remise_percent= " . $remise_percent . " , " ;
$sql .= " remise= " . $remise ;
2018-01-08 20:54:40 +01:00
$sql .= " WHERE rowid = " . $rowid ;
2015-06-10 18:42:16 +02:00
$result = $db -> query ( $sql );
2017-12-22 10:56:52 +01:00
if ( ! $result ) dol_print_error ( $db );
2015-06-10 18:42:16 +02:00
} else {
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values ( " ;
$sql .= $priceid . ',' . $price . ',' . $unitPrice . ',' . $quantity . ',' . $remise_percent . ',' . $remise . ')' ;
$result = $db -> query ( $sql );
2017-12-22 10:56:52 +01:00
if ( ! $result ) 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
}
2015-06-19 12:13:05 +02:00
if ( $action == 'delete_price_by_qty' )
{
2018-01-08 20:54:40 +01:00
$rowid = GETPOST ( 'rowid' , 'int' );
if ( ! empty ( $rowid )) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
$sql .= " WHERE rowid = " . $rowid ;
2014-09-07 12:22:04 +02:00
2018-01-10 20:38:06 +01:00
$result = $db -> query ( $sql );
2018-01-08 20:54:40 +01:00
} else {
setEventMessage ( 'delete_price_by_qty Missing Ids' , 'errors' );
}
2015-06-10 18:42:16 +02:00
}
2012-10-22 17:47:15 +02:00
2015-06-19 12:13:05 +02:00
if ( $action == 'delete_all_price_by_qty' )
{
2018-01-08 20:54:40 +01:00
$priceid = GETPOST ( 'priceid' , 'int' );
if ( ! empty ( $rowid )) {
2015-06-10 18:42:16 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
$sql .= " WHERE fk_product_price = " . $priceid ;
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
$result = $db -> query ( $sql );
2018-01-08 20:54:40 +01:00
} else {
setEventMessage ( 'delete_all_price_by_qty Missing Ids' , 'errors' );
}
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 )) {
2014-08-29 19:19:26 +02:00
2015-06-10 18:42:16 +02:00
$maxpricesupplier = $object -> min_recommended_price ();
2014-09-07 12:22:04 +02:00
2018-01-08 20:54:40 +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' );
$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
2017-09-25 21:41:53 +02: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 = '' ;
2017-09-25 21:41:53 +02:00
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
$vat_src_code = $reg [ 1 ];
$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
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
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
// 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 = ' " . $mysoc -> country_code . " ' " ;
2017-09-25 21:41:53 +02:00
$sql .= " AND t.taux = " . $tva_tx . " AND t.active = 1 " ;
2016-02-19 02:41:00 +01:00
$sql .= " AND t.code =' " . $vatratecode . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
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
2016-02-14 20:48:25 +01:00
if ( ! ( $prodcustprice -> fk_soc > 0 ))
{
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ThirdParty " )), null , 'errors' );
$error ++ ;
$action = 'add_customer_price' ;
}
2016-04-18 21:02:14 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ) && $prodcustprice -> price_min < $maxpricesupplier )
2015-06-10 18:42:16 +02:00
{
2016-02-14 20:48:25 +01:00
$langs -> load ( " errors " );
2015-12-14 20:54:55 +01:00
setEventMessages ( $langs -> trans ( " MinimumPriceLimit " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )), null , 'errors' );
2015-06-10 18:42:16 +02:00
$error ++ ;
$action = 'add_customer_price' ;
}
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
if ( ! $error )
{
$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
}
2015-06-19 12:13:05 +02: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
$prodcustprice -> id = GETPOST ( 'lineid' );
$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
}
2015-06-19 12:13:05 +02: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
2018-01-08 20:54:40 +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
$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 = '' ;
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
$vat_src_code = $reg [ 1 ];
$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
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
if ( preg_match ( '/\((.*)\)/' , $tva_tx_txt , $reg ))
{
// 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 = ' " . $mysoc -> country_code . " ' " ;
2017-09-25 21:41:53 +02:00
$sql .= " AND t.taux = " . $tva_tx . " AND t.active = 1 " ;
2016-02-19 02:41:00 +01:00
$sql .= " AND t.code =' " . $vatratecode . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$npr = $obj -> recuperableonly ;
$localtax1 = $obj -> localtax1 ;
$localtax2 = $obj -> localtax2 ;
$localtax1_type = $obj -> localtax1_type ;
$localtax2_type = $obj -> localtax2_type ;
}
}
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
2016-04-18 21:02:14 +02:00
if ( $prodcustprice -> price_min < $maxpricesupplier && ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ))
2015-06-10 18:42:16 +02:00
{
2015-12-14 20:54:55 +01:00
setEventMessages ( $langs -> trans ( " MinimumPriceLimit " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )), null , 'errors' );
2015-06-10 18:42:16 +02:00
$error ++ ;
$action = 'update_customer_price' ;
}
2014-09-07 12:22:04 +02:00
2015-06-10 18:42:16 +02:00
if ( ! $error )
{
$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 {
2015-12-14 20:54:55 +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
2015-07-13 11:27:35 +02:00
if ( ! empty ( $id ) || ! empty ( $ref ))
{
// 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 = '' ;
$shortlabel = dol_trunc ( $object -> label , 16 );
if ( GETPOST ( " type " ) == '0' || ( $object -> type == Product :: TYPE_PRODUCT ))
{
$title = $langs -> trans ( 'Product' ) . " " . $shortlabel . " - " . $langs -> trans ( 'SellingPrices' );
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos' ;
}
if ( GETPOST ( " type " ) == '1' || ( $object -> type == Product :: TYPE_SERVICE ))
{
$title = $langs -> trans ( 'Service' ) . " " . $shortlabel . " - " . $langs -> trans ( 'SellingPrices' );
$helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios' ;
}
2016-07-28 12:17:00 +02:00
2016-08-10 07:40:40 +02:00
llxHeader ( '' , $title , $helpurl );
2004-07-14 12:30:37 +02:00
2015-04-07 03:00:11 +02:00
$head = product_prepare_head ( $object );
2014-02-23 20:10:05 +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
dol_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>' ;
2017-03-25 10:45:01 +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 ;
if ( $user -> societe_id && ! in_array ( 'product' , explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL ))) $shownav = 0 ;
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
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2014-10-07 21:15:14 +02:00
{
2015-01-12 18:16:24 +01:00
// Price and min price are variable (depends on level of company).
2014-12-14 16:01:25 +01:00
if ( ! empty ( $socid ))
2014-10-07 21:15:14 +02:00
{
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
2015-01-12 18:16:24 +01:00
// Selling price
2016-08-29 16:30:31 +02:00
print '<tr><td class="titlefield">' ;
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' ) {
print price ( $object -> multiprices_ttc [ $soc -> price_level ]);
2014-02-23 20:10:05 +01:00
} else {
2015-11-07 12:19:48 +01:00
print price ( $object -> multiprices [ $soc -> price_level ]);
2008-10-25 14:14:16 +02:00
}
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $soc -> price_level ]) {
print ' ' . $langs -> trans ( $object -> multiprices_base_type [ $soc -> price_level ]);
2014-02-23 20:10:05 +01:00
} else {
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
2015-10-18 19:34:10 +02:00
print '<tr><td>' . $langs -> trans ( " MinPrice " ) . '</td><td colspan="2">' ;
2015-11-07 12:19:48 +01:00
if ( $object -> multiprices_base_type [ $soc -> price_level ] == 'TTC' )
2014-10-07 21:15:14 +02:00
{
2015-11-07 12:19:48 +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 {
2015-11-07 12:19:48 +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
2015-10-25 22:50:05 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) // using this option is a bug. kept for backward compatibility
{
// TVA
2017-09-26 10:47:08 +02:00
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td colspan="2">' ;
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
//print vatrate($object->multiprices_tva_tx[$soc->price_level], true);
print '</td></tr>' ;
2015-10-25 22:50:05 +01:00
}
else
{
// TVA
2017-09-26 10:47:08 +02:00
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
/*
2016-04-18 21:02:14 +02:00
if ( $object -> default_vat_code )
{
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
}
2017-09-25 21:41:53 +02:00
else print vatrate ( $object -> tva_tx . ( $object -> tva_npr ? '*' : '' ), true ); */
2016-04-18 21:02:14 +02:00
print '</td></tr>' ;
2015-10-25 22:50:05 +01:00
}
2017-06-12 16:26:25 +02:00
2014-09-07 12:22:04 +02:00
}
2014-05-01 12:19:24 +02:00
else
{
2015-10-25 22:50:05 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) // using this option is a bug. kept for backward compatibility
{
// We show only vat for level 1
2017-09-26 10:47:08 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2016-09-18 13:58:17 +02:00
print '<td colspan="2">' . vatrate ( $object -> multiprices_tva_tx [ 1 ], true ) . '</td>' ;
print '</tr>' ;
2015-10-25 22:50:05 +01:00
}
else
{
// TVA
2017-09-26 10:47:08 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
/*
2016-04-18 21:02:14 +02:00
if ( $object -> default_vat_code )
{
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
}
2017-09-25 21:41:53 +02:00
else print vatrate ( $object -> tva_tx . ( $object -> tva_npr ? '*' : '' ), true ); */
2016-04-18 21:02:14 +02:00
print '</td></tr>' ;
2015-10-25 22:50:05 +01:00
}
2016-09-18 13:58:17 +02:00
print '</table>' ;
2017-06-12 16:26:25 +02:00
2016-09-18 13:58:17 +02:00
print '<br>' ;
2017-06-12 16:26:25 +02:00
2016-09-18 13:58:17 +02:00
print '<table class="noborder tableforfield" width="100%">' ;
print '<tr class="liste_titre"><td>' ;
2016-08-29 16:30:31 +02:00
print $langs -> trans ( " PriceLevel " );
if ( $user -> admin ) print ' <a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editlabelsellingprice&pricelevel=' . $i . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'EditSellingPriceLabel' ), 0 ) . '</a>' ;
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
2016-04-18 21:02:14 +02:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ )
2014-05-01 12:19:24 +02:00
{
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>' ;
2014-05-01 12:19:24 +02:00
$keyforlabel = 'PRODUIT_MULTIPRICES_LABEL' . $i ;
2016-08-29 16:30:31 +02:00
if ( preg_match ( '/editlabelsellingprice/' , $action ))
{
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setlabelsellingprice">' ;
print '<input type="hidden" name="pricelevel" value="' . $i . '">' ;
print $langs -> trans ( " SellingPrice " ) . ' ' . $i . ' - ' ;
print '<input size="10" class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' . $conf -> global -> $keyforlabel . '">' ;
print ' <input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '">' ;
print '</form>' ;
}
else
{
print $langs -> trans ( " SellingPrice " ) . ' ' . $i ;
if ( ! empty ( $conf -> global -> $keyforlabel )) print ' - ' . $langs -> trans ( $conf -> global -> $keyforlabel );
}
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' ) {
print '<td style="text-align: right">' . price ( $object -> multiprices_ttc [ $i ]);
2014-02-23 20:10:05 +01:00
} else {
2015-11-07 12:19:48 +01:00
print '<td style="text-align: right">' . 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 ]) {
print ' ' . $langs -> trans ( $object -> multiprices_base_type [ $i ]) . '</td>' ;
2014-02-23 20:10:05 +01:00
} else {
2015-11-07 12:19:48 +01:00
print ' ' . $langs -> trans ( $object -> price_base_type ) . '</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">' ;
2015-11-07 12:19:48 +01:00
if ( empty ( $object -> multiprices_base_type [ $i ])) $object -> multiprices_base_type [ $i ] = " HT " ;
if ( $object -> multiprices_base_type [ $i ] == 'TTC' )
2014-10-11 23:55:10 +02:00
{
2015-11-07 12:19:48 +01:00
print price ( $object -> multiprices_min_ttc [ $i ]) . ' ' . $langs -> trans ( $object -> multiprices_base_type [ $i ]);
2014-12-14 16:01:25 +01:00
}
2014-10-11 23:55:10 +02:00
else
{
2015-11-07 12:19:48 +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
2018-05-23 17:05:08 +02: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
2014-12-14 20:41:11 +01:00
{
2014-02-23 20:10:05 +01:00
print '<tr><td>' . $langs -> trans ( " PriceByQuantity " ) . ' ' . $i ;
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> $keyforlabel )) print ' - ' . $langs -> trans ( $conf -> global -> $keyforlabel );
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">' ;
2014-02-23 20:10:05 +01:00
print '<td>' . $langs -> trans ( " PriceByQuantityRange " ) . ' ' . $i . '</td>' ;
print '<td align="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " UnitPrice " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Discount " ) . '</td>' ;
2012-10-22 17:47:15 +02:00
print '<td> </td>' ;
print '</tr>' ;
2017-06-12 16:26:25 +02:00
foreach ( $object -> prices_by_qty_list [ $i ] as $ii => $prices )
2016-09-18 13:58:17 +02:00
{
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 )) {
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2014-12-14 20:41:11 +01:00
print '<input type="hidden" name="priceid" value="' . $object -> prices_by_qty_id [ $i ] . '">' ;
print '<input type="hidden" value="' . $prices [ 'rowid' ] . '" name="rowid">' ;
2014-02-23 20:10:05 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2014-12-14 20:41:11 +01:00
print '<td><input size="5" type="text" value="' . $prices [ 'quantity' ] . '" name="quantity"></td>' ;
print '<td align="right" colspan="2"><input size="10" type="text" value="' . price2num ( $prices [ 'price' ], 'MU' ) . '" name="price"> ' . $object -> price_base_type . '</td>' ;
print '<td align="right"><input size="5" type="text" value="' . $prices [ 'remise_percent' ] . '" name="remise_percent"> %</td>' ;
2014-02-23 20:10:05 +01:00
print '<td align="center"><input type="submit" value="' . $langs -> trans ( " Modify " ) . '" class="button"></td>' ;
2012-10-22 17:47:15 +02:00
print '</tr>' ;
print '</form>' ;
} else {
2014-02-23 20:10:05 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2016-02-14 20:48:25 +01:00
print '<td>' . $prices [ 'quantity' ] . '</td>' ;
2014-12-14 20:41:11 +01:00
print '<td align="right">' . price ( $prices [ 'price' ]) . '</td>' ;
print '<td align="right">' . price ( $prices [ 'unitprice' ]) . '</td>' ;
print '<td align="right">' . price ( $prices [ 'remise_percent' ]) . ' %</td>' ;
2012-10-22 17:47:15 +02:00
print '<td align="center">' ;
2014-02-23 20:10:05 +01:00
if (( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )) {
2014-12-14 20:41:11 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit_price_by_qty&rowid=' . $prices [ " rowid " ] . '">' ;
2014-02-23 20:10:05 +01:00
print img_edit () . '</a>' ;
2014-12-14 20:41:11 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete_price_by_qty&rowid=' . $prices [ " rowid " ] . '">' ;
2014-02-23 20:10:05 +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 )) {
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2017-12-22 10:56:52 +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
2014-02-23 20:10:05 +01:00
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>' ;
2018-05-23 17:05:08 +02:00
print '<td align="right" class="nowrap"><input size="10" type="text" value="0" name="price"> ' . $object -> price_base_type . '</td>' ;
print '<td align="right"> </td>' ;
print '<td align="right" class="nowrap"><input size="5" type="text" value="0" name="remise_percent"> %</td>' ;
2014-02-23 20:10:05 +01:00
print '<td align="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>' ;
2018-05-29 10:52:55 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=disable_price_by_qty&level=' . $i . '">(' . $langs -> trans ( " DisablePriceByQty " ) . ')</a>' ;
2012-10-22 17:47:15 +02:00
} else {
print $langs -> trans ( " No " );
2017-12-22 10:56:52 +01:00
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=activate_price_by_qty&level=' . $i . '">(' . $langs -> trans ( " Activate " ) . ')</a>' ;
2012-10-22 17:47:15 +02:00
}
print '</td></tr>' ;
}
2009-08-06 16:25:03 +02:00
}
}
2017-06-12 16:26:25 +02:00
}
else
2015-10-25 22:50:05 +01:00
{
2014-02-23 20:10:05 +01:00
// TVA
2017-09-26 10:47:08 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
/*
2016-04-18 21:02:14 +02:00
if ( $object -> default_vat_code )
{
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
print '<tr><td>' . $langs -> trans ( " SellingPrice " ) . '</td><td>' ;
if ( $object -> price_base_type == 'TTC' ) {
print price ( $object -> price_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
} else {
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
2014-02-23 20:10:05 +01:00
print '<tr><td>' . $langs -> trans ( " MinPrice " ) . '</td><td>' ;
if ( $object -> price_base_type == 'TTC' ) {
print price ( $object -> price_min_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
} else {
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
2018-05-23 17:05:08 +02: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
2014-12-14 20:41:11 +01:00
{
2014-02-23 20:10:05 +01:00
print '<tr><td>' . $langs -> trans ( " PriceByQuantity " );
2017-12-22 10:56:52 +01:00
if ( $object -> prices_by_qty [ 0 ] == 0 ) {
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=activate_price_by_qty&level=1">(' . $langs -> trans ( " Activate " ) . ')' ;
}
else
{
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=disable_price_by_qty&level=1">(' . $langs -> trans ( " DisablePriceByQty " ) . ')' ;
2012-10-22 17:47:15 +02:00
}
print '</td><td>' ;
2014-09-07 12:22:04 +02:00
2017-12-22 10:56:52 +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>';
print '<td>' . $langs -> trans ( " Quantity " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Price " ) . '</td>' ;
print '<td align="right"></td>' ;
2014-02-23 20:10:05 +01:00
print '<td align="right">' . $langs -> trans ( " UnitPrice " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Discount " ) . '</td>' ;
2012-10-22 17:47:15 +02:00
print '<td> </td>' ;
print '</tr>' ;
2017-12-22 10:56:52 +01:00
if ( $action != 'edit_price_by_qty' )
{
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ; // FIXME a form into a table is not allowed
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
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
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
print '<td><input size="5" type="text" value="1" name="quantity"></td>' ;
print '<td align="right"><input class="width50 right" type="text" value="0" name="price"></td>' ;
print '<td>' ;
//print $object->price_base_type;
print '</td>' ;
print '<td align="right"> </td>' ;
print '<td align="right"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>' ;
print '<td align="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '" class="button"></td>' ;
print '</tr>' ;
print '</form>' ;
}
foreach ( $object -> prices_by_qty_list [ 0 ] 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 ))
{
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2012-10-22 17:47:15 +02:00
print '<input type="hidden" name="action" value="update_price_by_qty">' ;
2017-12-22 10:56:52 +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
2014-02-23 20:10:05 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2014-12-14 20:41:11 +01:00
print '<td><input size="5" type="text" value="' . $prices [ 'quantity' ] . '" name="quantity"></td>' ;
2017-12-22 10:56:52 +01:00
print '<td align="right"><input class="width50 right" type="text" value="' . price2num ( $prices [ 'price' ], 'MU' ) . '" name="price"></td>' ;
print '<td align="right">' ;
//print $object->price_base_type;
print $prices [ 'price_base_type' ];
print '</td>' ;
print '<td align="right"> </td>' ;
print '<td align="right"><input class="width50 right" type="text" value="' . $prices [ 'remise_percent' ] . '" name="remise_percent"> %</td>' ;
2014-02-23 20:10:05 +01:00
print '<td align="center"><input type="submit" value="' . $langs -> trans ( " Modify " ) . '" class="button"></td>' ;
2012-10-22 17:47:15 +02:00
print '</tr>' ;
print '</form>' ;
} else {
2014-02-23 20:10:05 +01:00
print '<tr class="' . ( $ii % 2 == 0 ? 'pair' : 'impair' ) . '">' ;
2014-12-14 20:41:11 +01:00
print '<td>' . $prices [ 'quantity' ] . '</td>' ;
print '<td align="right">' . price ( $prices [ 'price' ]) . '</td>' ;
2017-12-22 10:56:52 +01:00
print '<td align="right">' ;
//print $object->price_base_type;
print $prices [ 'price_base_type' ];
print '</td>' ;
2014-12-14 20:41:11 +01:00
print '<td align="right">' . price ( $prices [ 'unitprice' ]) . '</td>' ;
print '<td align="right">' . price ( $prices [ 'remise_percent' ]) . ' %</td>' ;
2012-10-22 17:47:15 +02:00
print '<td align="center">' ;
2017-12-22 10:56:52 +01:00
if (( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
{
2014-12-14 20:41:11 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit_price_by_qty&rowid=' . $prices [ " rowid " ] . '">' ;
2014-02-23 20:10:05 +01:00
print img_edit () . '</a>' ;
2014-12-14 20:41:11 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete_price_by_qty&rowid=' . $prices [ " rowid " ] . '">' ;
2014-02-23 20:10:05 +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>' ;
2015-06-19 12:13:05 +02:00
dol_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
2005-06-11 13:39:38 +02:00
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
2017-12-22 10:56:52 +01:00
if ( ! $action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'showlog_default_price' || $action == 'add_customer_price'
|| $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty' )
2015-02-24 12:58:43 +01:00
{
2014-02-23 20:10:05 +01:00
print " \n " . '<div class="tabsAction">' . " \n " ;
2014-09-07 12:22:04 +02:00
2018-05-23 17:05:08 +02:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2015-10-25 22:50:05 +01:00
{
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_price&id=' . $object -> id . '">' . $langs -> trans ( " UpdateDefaultPrice " ) . '</a></div>' ;
}
2008-10-25 14:14:16 +02:00
}
2015-11-02 10:02:09 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ))
{
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=add_customer_price&id=' . $object -> id . '">' . $langs -> trans ( " AddCustomerPrice " ) . '</a></div>' ;
}
}
2017-06-12 16:26:25 +02:00
2018-05-24 11:56:19 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2015-10-25 22:50:05 +01:00
{
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_vat&id=' . $object -> id . '">' . $langs -> trans ( " UpdateVAT " ) . '</a></div>' ;
}
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
2015-11-02 10:02:09 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit_price&id=' . $object -> id . '">' . $langs -> trans ( " UpdateLevelPrices " ) . '</a></div>' ;
2015-10-25 22:50:05 +01: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
2015-10-25 22:50:05 +01:00
if ( $action == 'edit_vat' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
{
print load_fiche_titre ( $langs -> trans ( " UpdateVAT " ), '' );
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="update_vat">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
dol_fiche_head ( '' );
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
print '<table class="border" width="100%">' ;
2017-06-12 16:26:25 +02:00
2015-10-25 22:50:05 +01:00
// VAT
2017-09-26 10:47:08 +02: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>' ;
dol_fiche_end ();
print '<div class="center">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</div>' ;
print '<br></form><br>' ;
}
2017-06-12 16:26:25 +02:00
2015-11-08 15:12:31 +01:00
if ( $action == 'edit_price' && $object -> getRights () -> creer )
2015-02-24 12:58:43 +01:00
{
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " NewPrice " ), '' );
2014-09-07 12:22:04 +02:00
2018-05-23 17:05:08 +02:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2015-02-24 12:58:43 +01:00
{
2017-05-17 15:25:09 +02:00
print '<!-- Edit price -->' . " \n " ;
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2014-02-23 20:10:05 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2007-06-16 15:34:37 +02:00
print '<input type="hidden" name="action" value="update_price">' ;
2014-02-23 20:10:05 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2015-08-23 07:37:38 +02:00
dol_fiche_head ( '' );
2017-06-12 16:26:25 +02:00
2007-06-16 15:34:37 +02:00
print '<table class="border" width="100%">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
// VAT
2017-09-26 10:47:08 +02: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
2015-08-23 07:37:38 +02:00
// Only show price mode and expression selector if module is enabled
2014-12-28 01:26:41 +01:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) {
// Price mode selector
2017-03-04 18:17:04 +01:00
print '<tr><td>' . $langs -> trans ( " PriceMode " ) . '</td><td>' ;
2014-12-28 01:26:41 +01:00
$price_expression = new PriceExpression ( $db );
$price_expression_list = array ( 0 => $langs -> trans ( " PriceNumeric " )); //Put the numeric mode as first option
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 );
2014-12-28 01:26:41 +01:00
print ' <div id="expression_editor" class="button">' . $langs -> trans ( " PriceExpressionEditor " ) . '</div>' ;
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' ) {
2014-12-28 01:26:41 +01:00
print '<input name="price" size="10" value="' . price ( $product -> price_ttc ) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2014-12-28 01:26:41 +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' ) {
2015-11-08 15:12:31 +01:00
print '<input name="price_min" size="10" value="' . price ( $object -> price_min_ttc ) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2015-11-08 15:12:31 +01:00
print '<input name="price_min" size="10" value="' . price ( $object -> price_min ) . '">' ;
2008-08-28 01:00:37 +02:00
}
2017-03-04 18:17:04 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ))
2014-08-29 19:19:26 +02:00
{
2017-03-04 18:17:04 +01: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
2017-07-27 17:11:15 +02:00
$parameters = array ( 'colspan' => 2 );
$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
2017-07-31 10:28:24 +02:00
$parameters = array ( 'colspan' => 2 );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2007-06-16 15:34:37 +02:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2015-08-23 07:37:38 +02:00
dol_fiche_end ();
print '<div class="center">' ;
2014-11-24 06:43:15 +01:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</div>' ;
2014-09-07 12:22:04 +02:00
2011-10-09 17:37:27 +02:00
print '<br></form>' ;
2015-02-24 12:58:43 +01:00
}
else
{
2017-05-17 15:25:09 +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
2015-11-07 12:19:48 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2015-11-08 15:12:31 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="update_price">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2015-11-07 12:19:48 +01:00
2017-05-17 15:25:09 +02:00
//dol_fiche_head('', '', '', -1);
2017-06-12 16:26:25 +02:00
2018-05-23 17:05:08 +02:00
if (( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL )) {
2015-11-08 15:12:31 +01:00
print $langs -> trans ( 'UseMultipriceRules' ) . ' <input type="checkbox" id="usePriceRules" name="usePriceRules" ' . ( $object -> price_autogen ? 'checked' : '' ) . '><br><br>' ;
}
2015-11-07 12:19:48 +01:00
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>' ;
2017-09-26 10:47:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL )) print '<td style="text-align: center">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2016-04-18 21:02:14 +02:00
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
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ )
2016-02-26 13:37:18 +01:00
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-11-08 15:12:31 +01:00
print '<td>' ;
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $langs -> trans ( 'SellingPrice' ) . ' ' . $i , $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 )) {
2016-04-18 21:02:14 +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 ) . '">' ;
2016-02-19 02:41:00 +01:00
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 . '">' ;
2016-02-19 03:59:43 +01:00
print '<input type="hidden" name="localtax2_type[' . $i . ']" value="' . $object -> localtax2_type . '">' ;
2016-04-18 21:02:14 +02:00
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">' ;
2016-02-19 02:41:00 +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' ) {
print '<input name="price[' . $i . ']" size="10" value="' . price ( $object -> multiprices_ttc [ $i ]) . '">' ;
2014-02-23 20:10:05 +01:00
} else {
2015-11-07 12:19:48 +01:00
print '<input name="price[' . $i . ']" size="10" value="' . price ( $object -> multiprices [ $i ]) . '">' ;
2008-10-25 14:14:16 +02:00
}
2015-11-07 12:19:48 +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' ) {
2015-11-08 15:12:31 +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 {
2015-11-08 15:12:31 +01:00
print '<input name="price_min[' . $i . ']" size="10" value="' . price ( $object -> multiprices_min [ $i ]) . '">' ;
2008-10-25 14:14:16 +02:00
}
2014-09-07 12:22:04 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ))
2014-08-29 19:19:26 +02:00
{
print '<td align="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
}
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>' ;
2017-06-12 16:26:25 +02:00
2017-05-17 15:25:09 +02:00
//dol_fiche_end();
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<div style="text-align: center">' ;
2015-11-07 12:19:48 +01:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></div>' ;
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
2016-02-26 13:37:18 +01:00
if (( empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) || $action == 'showlog_default_price' ) && ! in_array ( $action , array ( 'edit_price' , 'edit_vat' )))
2015-02-24 12:58:43 +01:00
{
2017-09-25 21:41:53 +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, " ;
2016-02-26 13:37:18 +01:00
$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 " ;
$sql .= " WHERE fk_product = " . $object -> id ;
2017-05-30 18:50:54 +02:00
$sql .= " AND p.entity IN ( " . getEntity ( 'productprice' ) . " ) " ;
2016-02-26 13:37:18 +01:00
$sql .= " AND p.fk_user_author = u.rowid " ;
if ( ! empty ( $socid ) && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) $sql .= " AND p.price_level = " . $soc -> price_level ;
$sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC " ;
// $sql .= $db->plimit();
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
2017-06-13 11:14:52 +02:00
print '<div class="divlogofpreviouscustomerprice">' ;
$num = $db -> num_rows ( $result );
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
if ( ! $num )
{
$db -> free ( $result );
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre a niveau (pb vieilles versions)
2018-02-05 17:47:29 +01:00
//$object->updatePrice($object->price, $object->price_base_type, $user, $newprice_min);
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2018-07-11 10:01:26 +02:00
$object -> updatePrice ( $object -> multiprices [ 1 ], $object -> multiprices_base_type [ 1 ], $user , ( empty ( $object -> multiprices_tva_tx [ 1 ]) ? 0 : $object -> multiprices_tva_tx [ 1 ]), $object -> multiprices_min [ 1 ], 1 );
2018-02-05 17:47:29 +01:00
} else {
$object -> updatePrice ( $object -> price , $object -> price_base_type , $user , $object -> tva_tx , $object -> price_min );
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
$result = $db -> query ( $sql );
$num = $db -> num_rows ( $result );
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
if ( $num > 0 )
{
2016-09-18 13:58:17 +02:00
// Default prices or
// Log of previous customer prices
2016-02-26 13:37:18 +01:00
$backbutton = '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' . $langs -> trans ( " Back " ) . '</a>' ;
2017-06-12 16:26:25 +02:00
2018-12-01 16:11:49 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) print_barre_liste ( $langs -> trans ( " DefaultPrice " ), 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' );
2017-03-04 14:34:43 +01:00
//if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print_barre_liste($langs->trans("DefaultPrice"),'','','','','',$backbutton, 0, 0, 'title_accountancy.png');
//else print_barre_liste($langs->trans("PriceByCustomerLog"),'','','','','','', 0, 0, 'title_accountancy.png');
2017-06-12 16:26:25 +02:00
2016-11-27 20:02:57 +01:00
print '<div class="div-table-responsive">' ;
2016-02-26 13:37:18 +01:00
print '<table class="noborder" width="100%">' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
2017-06-12 16:26:25 +02:00
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2016-02-26 13:37:18 +01:00
print '<td align="center">' . $langs -> trans ( " PriceLevel " ) . '</td>' ;
}
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2016-02-26 13:37:18 +01:00
print '<td align="center">' . $langs -> trans ( " Type " ) . '</td>' ;
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<td align="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
print $conf -> global -> PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL ;
2018-05-23 17:05:08 +02:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) print '<td align="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2016-02-26 13:37:18 +01:00
print '<td align="right">' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
if ( ! empty ( $conf -> dynamicprices -> enabled )) {
print '<td align="right">' . $langs -> trans ( " PriceExpressionSelected " ) . '</td>' ;
}
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " ChangedBy " ) . '</td>' ;
if ( $user -> rights -> produit -> supprimer )
print '<td align="right"> </td>' ;
print '</tr>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
$notfirstlineforlevel = array ();
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
$i = 0 ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2017-07-07 12:31:00 +02:00
print '<tr class="oddeven">' ;
2016-02-26 13:37:18 +01:00
// Date
print " <td> " . dol_print_date ( $db -> jdate ( $objp -> dp ), " dayhour " ) . " </td> " ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
// Price level
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2016-02-26 13:37:18 +01:00
print '<td align="center">' . $objp -> price_level . " </td> " ;
}
// Price by quantity
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2016-02-26 13:37:18 +01:00
{
$type = ( $objp -> price_by_qty == 1 ) ? 'PriceByQuantity' : 'Standard' ;
print '<td align="center">' . $langs -> trans ( $type ) . " </td> " ;
}
2017-06-12 16:26:25 +02:00
2017-12-22 10:56:52 +01:00
print '<td align="center">' ;
if ( empty ( $objp -> price_by_qty )) {
print $langs -> trans ( $objp -> price_base_type );
}
print " </td> " ;
2018-05-23 17:05:08 +02:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ) && empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2017-03-04 14:18:04 +01:00
{
print '<td align="right">' ;
2017-09-25 21:41:53 +02:00
2017-12-22 10:56:52 +01:00
if ( empty ( $objp -> price_by_qty )) {
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $objp -> default_vat_code ? ' (' . $objp -> default_vat_code . ')' : '' ), '%' , $objp -> tva_npr );
/*
if ( $objp -> default_vat_code )
{
print vatrate ( $objp -> tva_tx , true ) . ' (' . $objp -> default_vat_code . ')' ;
}
else print vatrate ( $objp -> tva_tx , true , $objp -> recuperableonly ); */
2017-03-04 14:18:04 +01:00
}
2017-12-22 10:56:52 +01:00
2017-03-04 14:18:04 +01:00
print " </td> " ;
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
// Price
if ( ! empty ( $objp -> fk_price_expression ) && ! empty ( $conf -> dynamicprices -> enabled ))
{
$price_expression = new PriceExpression ( $db );
$res = $price_expression -> fetch ( $objp -> fk_price_expression );
$title = $price_expression -> title ;
print '<td align="right"></td>' ;
print '<td align="right"></td>' ;
print '<td align="right">' . $title . " </td> " ;
}
else
{
2017-12-22 10:56:52 +01:00
print '<td align="right">' ;
if ( empty ( $objp -> price_by_qty )) {
print ( $objp -> price_base_type != 'TTC' ? price ( $objp -> price ) : '' );
}
print " </td> " ;
print '<td align="right">' ;
if ( empty ( $objp -> price_by_qty )) {
print ( $objp -> price_base_type == 'TTC' ? price ( $objp -> price_ttc ) : '' );
}
print " </td> " ;
2016-02-26 13:37:18 +01:00
if ( ! empty ( $conf -> dynamicprices -> enabled )) { //Only if module is enabled
print '<td align="right"></td>' ;
}
}
2017-07-07 12:31:00 +02:00
2017-12-22 10:56:52 +01:00
print '<td align="right">' ;
if ( empty ( $objp -> price_by_qty )) {
print ( $objp -> price_base_type != 'TTC' ? price ( $objp -> price_min ) : '' );
}
print '</td>' ;
2017-07-07 12:31:00 +02:00
2017-12-22 10:56:52 +01:00
print '<td align="right">' ;
if ( empty ( $objp -> price_by_qty )) {
print ( $objp -> price_base_type == 'TTC' ? price ( $objp -> price_min_ttc ) : '' );
}
print '</td>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
// User
print '<td align="right"><a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $objp -> user_id . '">' . img_object ( $langs -> trans ( " ShowUser " ), 'user' ) . ' ' . $objp -> login . '</a></td>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
// Action
if ( $user -> rights -> produit -> supprimer )
{
$candelete = 0 ;
2018-05-23 17:05:08 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))
2016-02-26 13:37:18 +01:00
{
if ( empty ( $notfirstlineforlevel [ $objp -> price_level ])) $notfirstlineforlevel [ $objp -> price_level ] = 1 ;
else $candelete = 1 ;
}
elseif ( $i > 0 ) $candelete = 1 ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<td align="right">' ;
2017-06-12 16:26:25 +02:00
if ( $candelete )
2016-02-26 13:37:18 +01:00
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete&id=' . $object -> id . '&lineid=' . $objp -> rowid . '">' ;
print img_delete ();
print '</a>' ;
} else
print ' ' ; // Can not delete last price (it's current price)
print '</td>' ;
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print " </tr> \n " ;
2016-09-18 13:58:17 +02:00
$i ++ ;
2016-02-26 13:37:18 +01:00
}
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
$db -> free ( $result );
print " </table> " ;
2016-11-27 20:02:57 +01:00
print '</div>' ;
2016-02-26 13:37:18 +01:00
print " <br> " ;
}
2017-06-13 11:14:52 +02:00
print '</div>' ;
2016-02-26 13:37:18 +01:00
} 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
2015-02-24 12:58:43 +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
2014-02-23 20:10:05 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2017-09-18 16:30:01 +02:00
$page = ( GETPOST ( " page " , 'int' ) ? GETPOST ( " page " , 'int' ) : 0 );
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2014-02-23 16:16:47 +01:00
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortorder )
$sortorder = " ASC " ;
if ( ! $sortfield )
$sortfield = " soc.nom " ;
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
2014-02-23 20:10:05 +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
2015-02-24 12:58:43 +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
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'PriceByCustomer' ));
2014-09-07 12:22:04 +02:00
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2014-02-23 16:16:47 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="add_customer_price_confirm">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
dol_fiche_head ();
2017-06-12 16:26:25 +02:00
2014-02-23 16:16:47 +01:00
print '<table class="border" width="100%">' ;
print '<tr>' ;
2016-02-14 20:48:25 +01:00
print '<td class="fieldrequired">' . $langs -> trans ( 'ThirdParty' ) . '</td>' ;
2014-02-23 16:16:47 +01:00
print '<td>' ;
2017-05-12 13:12:17 +02:00
print $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
2014-02-23 16:16:47 +01:00
// VAT
2017-09-26 10:47:08 +02: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' ) {
2014-02-23 20:10:05 +01:00
print '<input name="price" size="10" value="' . price ( $object -> price_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2014-02-23 20:10:05 +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' ) {
2014-02-23 20:10:05 +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 {
2014-02-23 20:10:05 +01:00
print '<td><input name="price_min" size="10" value="' . price ( $object -> price_min ) . '">' ;
2014-02-23 16:16:47 +01:00
}
2014-09-07 12:22:04 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ))
2014-08-29 19:19:26 +02:00
{
print '<td align="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
}
2014-02-23 16:16:47 +01:00
print '</td></tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Update all child soc
print '<tr><td width="15%">' ;
2014-02-23 20:10:05 +01:00
print $langs -> trans ( 'ForceUpdateChildPriceSoc' );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '<td>' ;
print '<input type="checkbox" name="updatechildprice" value="1">' ;
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
dol_fiche_end ();
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<div class="center">' ;
2014-11-24 06:43:15 +01:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</div>' ;
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
print '</form>' ;
2015-02-24 12:58:43 +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
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
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2014-02-23 16:16:47 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="update_customer_price_confirm">' ;
print '<input type="hidden" name="lineid" value="' . $prodcustprice -> id . '">' ;
2017-07-07 14:58:57 +02:00
dol_fiche_head ();
2014-02-23 16:16:47 +01:00
print '<table class="border" width="100%">' ;
print '<tr>' ;
2017-07-07 14:58:57 +02:00
print '<td class="titlefield">' . $langs -> trans ( 'ThirdParty' ) . '</td>' ;
2014-02-23 20:10:05 +01:00
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( $prodcustprice -> fk_soc );
2014-08-29 19:19:26 +02:00
print " <td colspan='2'> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
2014-02-23 16:16:47 +01:00
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// VAT
2017-09-26 10:47:08 +02:00
print '<tr><td>' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td colspan="2">' ;
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
2017-07-07 14:58:57 +02:00
print '<tr><td>' ;
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
2017-07-07 14:58:57 +02:00
print '<tr><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 );
2014-02-23 16:16:47 +01:00
print '</td><td>' ;
if ( $prodcustprice -> price_base_type == 'TTC' ) {
2014-02-23 20:10:05 +01:00
print '<input name="price" size="10" value="' . price ( $prodcustprice -> price_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2014-02-23 20:10:05 +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' ) {
2014-09-07 12:22:04 +02:00
print '<input name="price_min" size="10" value="' . price ( $prodcustprice -> price_min_ttc ) . '">' ;
2014-02-23 16:16:47 +01:00
} else {
2014-09-07 12:22:04 +02: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>' ;
if ( ! empty ( $conf -> global -> PRODUCT_MINIMUM_RECOMMENDED_PRICE ))
2014-08-29 19:19:26 +02:00
{
print '<td align="left">' . $langs -> trans ( " MinimumRecommendedPrice " , price ( $maxpricesupplier , 0 , '' , 1 , - 1 , - 1 , 'auto' )) . ' ' . img_warning () . '</td>' ;
}
2014-09-07 12:22:04 +02:00
print '</tr>' ;
2014-02-23 16:16:47 +01:00
// Update all child soc
2017-07-07 14:58:57 +02:00
print '<tr><td>' ;
2014-02-23 20:10:05 +01:00
print $langs -> trans ( 'ForceUpdateChildPriceSoc' );
2014-02-23 16:16:47 +01:00
print '</td>' ;
print '<td>' ;
print '<input type="checkbox" name="updatechildprice" value="1">' ;
print '</td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '</table>' ;
2014-09-07 12:22:04 +02:00
2017-07-07 14:58:57 +02:00
dol_fiche_end ();
print '<div class="center">' ;
2014-11-24 06:43:15 +01:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</div>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<br></form>' ;
2015-02-24 12:58:43 +01:00
}
elseif ( $action == 'showlog_customer_price' )
{
2017-07-07 14:58:57 +02:00
// List of all log of prices by customers
print '<!-- list of all lof of prices per customer -->' . " \n " ;
$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
2014-02-23 20:10:05 +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
2016-02-26 13:37:18 +01:00
$title = $langs -> trans ( 'PriceByCustomerLog' );
$title .= ' - ' . $staticsoc -> getNomUrl ( 1 );
$backbutton = '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' . $langs -> trans ( " Back " ) . '</a>' ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print_barre_liste ( $title , $page , $_SERVEUR [ 'PHP_SELF' ], $option , $sortfield , $sortorder , $backbutton , count ( $prodcustprice -> lines ), $nbtotalofrecords , 'title_accountancy.png' );
2014-09-07 12:22:04 +02:00
2015-06-19 12:13:05 +02:00
if ( count ( $prodcustprice -> lines ) > 0 )
{
2014-05-12 12:10:52 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
2014-02-23 16:16:47 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<table class="noborder" width="100%">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
print '<tr class="liste_titre">' ;
2014-02-23 20:10:05 +01:00
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
2017-09-26 10:47:08 +02:00
print '<td align="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2014-02-23 20:10:05 +01:00
print '<td align="right">' . $langs -> trans ( " HT " ) . '</td>' ;
2017-11-13 14:02:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " )
{
//print '<td align="right">' . $langs->trans("INCVATONLY") . '</td>';
print '<td align="right">' . $langs -> trans ( " INCT " ) . '</td>' ;
}
else
{
print '<td align="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
}
2014-02-23 20:10:05 +01:00
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td align="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
2015-06-19 12:13:05 +02:00
foreach ( $prodcustprice -> lines as $line )
{
2017-07-07 14:58:57 +02:00
// Date
$staticsoc = new Societe ( $db );
$staticsoc -> fetch ( $line -> fk_soc );
$tva_tx = $line -> default_vat_code ? $line -> tva_tx . ' (' . $line -> default_vat_code . ')' : $line -> tva_tx ;
// Line for default price
if ( $line -> price_base_type == 'HT' )
{
$pu = $line -> price ;
}
else
{
$pu = $line -> price_ttc ;
}
// Local tax is not saved into table of product. We use value linked to VAT code.
$localtaxarray = getLocalTaxesFromRate ( $line -> tva_tx . ( $line -> default_vat_code ? ' (' . $line -> default_vat_code . ')' : '' ), 0 , $staticsoc , $mysoc );
// Define part of HT, VAT, TTC
$resultarray = calcul_price_total ( 1 , $pu , 0 , $line -> tva_tx , 1 , 1 , 0 , $line -> price_base_type , $line -> 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 ];
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
print " <td> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
print " <td> " . dol_print_date ( $line -> datec , " dayhour " ) . " </td> " ;
2017-07-07 14:58:57 +02:00
print '<td align="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
2017-09-25 21:41:53 +02:00
print '<td align="right">' ;
2017-11-13 14:02:17 +01:00
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
2017-11-13 14:02: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 );
2017-09-25 21:41:53 +02:00
if ( empty ( $positiverates )) $positiverates = '0' ;
2017-11-13 14:02:17 +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> " ;
2014-02-23 20:10:05 +01:00
print '<td align="right">' . price ( $line -> price ) . " </td> " ;
2017-07-07 12:31:00 +02:00
2017-11-13 14:02:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " )
{
//print '<td align="right">' . price($line->price_ttc) . "</td>";
print '<td align="right">' . price ( $resultarray [ 2 ]) . '</td>' ;
}
else
{
print '<td align="right">' . price ( $line -> price_ttc ) . " </td> " ;
}
2017-07-07 14:58:57 +02:00
2014-02-23 20:10:05 +01:00
print '<td align="right">' . price ( $line -> price_min ) . '</td>' ;
print '<td align="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 );
print '<td align="right">' ;
print $userstatic -> getLoginUrl ( 1 );
print '</td>' ;
2017-07-07 12:31:00 +02:00
print '</tr>' ;
2014-02-23 20:10:05 +01:00
}
print " </table> " ;
} else {
print $langs -> trans ( 'None' );
2014-02-23 16:16:47 +01:00
}
2015-02-24 12:58:43 +01:00
}
2016-02-27 11:59:51 +01:00
else if ( $action != 'showlog_default_price' && $action != 'edit_price' )
2015-02-24 12:58:43 +01:00
{
2016-02-26 13:37:18 +01:00
// List of all prices by customers
2017-07-07 14:58:57 +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
2014-02-23 16:16:47 +01:00
$option = '&search_soc=' . $search_soc . '&id=' . $object -> id ;
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
print_barre_liste ( $langs -> trans ( 'PriceByCustomer' ), $page , $_SERVEUR [ 'PHP_SELF' ], $option , $sortfield , $sortorder , '' , count ( $prodcustprice -> lines ), $nbtotalofrecords , 'title_accountancy.png' );
2014-09-07 12:22:04 +02:00
2015-02-24 12:58:43 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2014-09-07 12:22:04 +02:00
2015-02-24 12:58:43 +01:00
print '<table class="noborder" width="100%">' ;
2014-09-07 12:22:04 +02:00
2017-07-07 12:31:00 +02:00
if ( count ( $prodcustprice -> lines ) > 0 || $search_soc )
{
$colspan = 8 ;
2017-11-13 14:02:17 +01:00
//if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") $colspan++;
2017-07-07 12:31:00 +02:00
print '<tr class="liste_titre">' ;
print '<td class="liste_titre"><input type="text" class="flat" name="search_soc" value="' . $search_soc . '" size="20"></td>' ;
print '<td class="liste_titre" colspan="' . $colspan . '"> </td>' ;
// Print the search button
print '<td class="liste_titre" align="right">' ;
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
}
2015-02-24 12:58:43 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
print '<td>' . $langs -> trans ( " AppliedPricesFrom " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " PriceBase " ) . '</td>' ;
2017-09-26 10:47:08 +02:00
print '<td align="right">' . $langs -> trans ( " DefaultTaxRate " ) . '</td>' ;
2015-02-24 12:58:43 +01:00
print '<td align="right">' . $langs -> trans ( " HT " ) . '</td>' ;
2017-11-13 14:02:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " )
{
//print '<td align="right">' . $langs->trans("INCVATONLY") . '</td>';
print '<td align="right">' . $langs -> trans ( " INCT " ) . '</td>' ;
}
else
{
print '<td align="right">' . $langs -> trans ( " TTC " ) . '</td>' ;
}
2015-02-24 12:58:43 +01:00
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " HT " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " MinPrice " ) . ' ' . $langs -> trans ( " TTC " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " ChangedBy " ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
2014-09-07 12:22:04 +02:00
2017-07-07 12:31:00 +02:00
// Line for default price
if ( $object -> price_base_type == 'HT' )
2015-06-19 12:13:05 +02:00
{
2017-07-07 12:31:00 +02:00
$pu = $object -> price ;
}
else
{
$pu = $object -> price_ttc ;
2015-12-20 20:24:12 +01:00
}
2017-06-12 16:26:25 +02:00
2017-07-07 12:31:00 +02:00
// Local tax is not saved into table of product. We use value linked to VAT code.
$localtaxarray = getLocalTaxesFromRate ( $object -> 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 , $object -> tva_tx , 1 , 1 , 0 , $object -> price_base_type , $object -> 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 ];
2017-06-12 16:26:25 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2016-02-26 13:37:18 +01:00
print " <td> " . $langs -> trans ( " Default " ) . " </td> " ;
print " <td> " . " </td> " ;
2017-06-12 16:26:25 +02:00
2016-02-26 13:37:18 +01:00
print '<td align="center">' . $langs -> trans ( $object -> price_base_type ) . " </td> " ;
2017-06-23 12:09:21 +02:00
print '<td align="right">' ;
2017-09-25 21:41:53 +02:00
$positiverates = '' ;
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' ;
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
//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
2016-02-26 13:37:18 +01:00
print '<td align="right">' . price ( $object -> price ) . " </td> " ;
2017-07-07 12:31:00 +02:00
2017-11-13 14:02:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " )
{
//print '<td align="right">' . price($object->price_ttc) . "</td>";
print '<td align="right">' . price ( $resultarray [ 2 ]) . '</td>' ;
}
else
{
print '<td align="right">' . price ( $object -> price_ttc ) . " </td> " ;
}
2017-07-07 12:31:00 +02:00
2016-02-26 13:37:18 +01:00
print '<td align="right">' . price ( $object -> price_min ) . '</td>' ;
print '<td align="right">' . price ( $object -> price_min_ttc ) . '</td>' ;
print '<td align="right">' ;
print '</td>' ;
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer )
2015-12-20 20:24:12 +01:00
{
2016-02-26 13:37:18 +01:00
print '<td align="right">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=showlog_default_price&id=' . $object -> id . '">' ;
print img_info ( $langs -> trans ( 'PriceByCustomerLog' ));
print '</a>' ;
print ' ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit_price&id=' . $object -> id . '">' ;
print img_edit ( 'default' , 0 , 'style="vertical-align: middle;"' );
print '</a>' ;
print ' ' ;
print '</td>' ;
}
print " </tr> \n " ;
2014-09-07 12:22:04 +02:00
2016-02-26 13:37:18 +01:00
if ( count ( $prodcustprice -> lines ) > 0 )
{
2015-06-19 12:13:05 +02:00
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
2017-07-07 14:58:57 +02:00
if ( $line -> price_base_type == 'HT' )
2017-07-07 12:31:00 +02:00
{
$pu = $line -> price ;
}
else
{
$pu = $line -> price_ttc ;
}
// Local tax is not saved into table of product. We use value linked to VAT code.
2017-07-07 14:58:57 +02: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
2017-07-07 14:58:57 +02: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">' ;
2014-02-23 20:10:05 +01:00
print " <td> " . $staticsoc -> getNomUrl ( 1 ) . " </td> " ;
print " <td> " . dol_print_date ( $line -> datec , " dayhour " ) . " </td> " ;
2014-09-07 12:22:04 +02:00
2014-02-23 20:10:05 +01:00
print '<td align="center">' . $langs -> trans ( $line -> price_base_type ) . " </td> " ;
2017-09-25 21:41:53 +02:00
print '<td align="right">' ;
$positiverates = '' ;
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
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> " ;
2014-02-23 20:10:05 +01:00
print '<td align="right">' . price ( $line -> price ) . " </td> " ;
2017-07-07 12:31:00 +02:00
2017-11-13 14:02:17 +01:00
if ( $mysoc -> localtax1_assuj == " 1 " || $mysoc -> localtax2_assuj == " 1 " )
{
//print '<td align="right">' . price($line->price_ttc) . "</td>";
print '<td align="right">' . price ( $resultarray [ 2 ]) . '</td>' ;
}
else
{
print '<td align="right">' . price ( $line -> price_ttc ) . " </td> " ;
}
2017-07-07 12:31:00 +02:00
2014-02-23 20:10:05 +01:00
print '<td align="right">' . price ( $line -> price_min ) . '</td>' ;
print '<td align="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 );
print '<td align="right">' ;
print $userstatic -> getLoginUrl ( 1 );
print '</td>' ;
2014-09-07 12:22:04 +02:00
2014-02-23 16:16:47 +01:00
// Todo Edit or delete button
// Action
2015-06-19 12:13:05 +02:00
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer )
{
2014-02-23 16:16:47 +01:00
print '<td align="right">' ;
2015-06-19 12:13:05 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=showlog_customer_price&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 ' ' ;
2014-05-12 12:10:52 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit_customer_price&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 ' ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete_customer_price&id=' . $object -> id . '&lineid=' . $line -> id . '">' ;
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
}
2016-02-27 11:59:51 +01:00
/* else
2015-06-19 12:13:05 +02:00
{
2015-02-24 12:58:43 +01:00
$colspan = 9 ;
if ( $user -> rights -> produit -> supprimer || $user -> rights -> service -> supprimer ) $colspan += 1 ;
2015-06-19 12:13:05 +02:00
print " <tr " . $bc [ false ] . " > " ;
2015-02-24 12:58:43 +01:00
print '<td colspan="' . $colspan . '">' . $langs -> trans ( 'None' ) . '</td>' ;
2015-06-19 12:13:05 +02:00
print " </tr> " ;
2016-02-27 11:59:51 +01:00
} */
2014-09-07 12:22:04 +02:00
2015-02-24 12:58:43 +01:00
print " </table> " ;
print " </form> " ;
2014-02-23 16:16:47 +01:00
}
}
2012-01-08 10:53:05 +01:00
llxFooter ();
2004-09-25 02:00:46 +02:00
2004-07-13 10:28:37 +02:00
$db -> close ();