2016-07-23 16:37:21 +02:00
< ? php
2019-02-27 01:25:25 +01:00
/* Copyright ( C ) 2016 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2018 - 2019 Frédéric France < frederic . france @ netlogic . fr >
2022-03-18 15:38:44 +01:00
* Copyright ( C ) 2022 Open - Dsi < support @ open - dsi . fr >
2016-07-23 16:37:21 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2016-07-23 16:37:21 +02:00
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2017-02-08 12:37:38 +01:00
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttribute.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttributeValue.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination2ValuePair.class.php' ;
2016-07-23 16:37:21 +02:00
2018-10-01 08:22:23 +02:00
$langs -> loadLangs ( array ( " products " , " other " ));
2016-07-23 16:37:21 +02:00
$id = GETPOST ( 'id' , 'int' );
$valueid = GETPOST ( 'valueid' , 'int' );
2019-02-24 12:09:57 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
2021-08-02 20:20:52 +02:00
$weight_impact = price2num ( GETPOST ( 'weight_impact' , 'alpha' ), 2 );
2016-07-23 16:37:21 +02:00
$price_impact_percent = ( bool ) GETPOST ( 'price_impact_percent' );
2021-08-02 20:20:52 +02:00
if ( $price_impact_percent ) {
$price_impact = price2num ( GETPOST ( 'price_impact' , 'alpha' ), 2 );
} else {
$price_impact = price2num ( GETPOST ( 'price_impact' , 'alpha' ), 'MU' );
}
2020-08-12 10:14:29 +02:00
$level_price_impact = GETPOST ( 'level_price_impact' , 'array' );
$level_price_impact_percent = GETPOST ( 'level_price_impact_percent' , 'array' );
2019-11-23 17:04:14 +01:00
$reference = GETPOST ( 'reference' , 'alpha' );
2016-07-23 16:37:21 +02:00
$form = new Form ( $db );
2017-04-07 12:22:59 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-11-14 12:09:15 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' );
$show_files = GETPOST ( 'show_files' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2017-04-07 12:22:59 +02:00
$toselect = GETPOST ( 'toselect' , 'array' );
2019-01-27 11:55:16 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2019-11-23 18:03:46 +01:00
$delete_product = GETPOST ( 'delete_product' , 'alpha' );
2022-03-18 15:38:44 +01:00
$subaction = GETPOST ( 'subaction' , 'aZ09' );
2022-05-11 15:06:11 +02:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2016-07-23 16:37:21 +02:00
// Security check
2019-11-14 12:09:15 +01:00
$fieldvalue = ( ! empty ( $id ) ? $id : $ref );
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2016-07-23 16:37:21 +02:00
$prodstatic = new Product ( $db );
$prodattr = new ProductAttribute ( $db );
$prodattr_val = new ProductAttributeValue ( $db );
2017-02-08 12:52:31 +01:00
$object = new Product ( $db );
2021-02-26 13:10:10 +01:00
if ( $id > 0 || $ref ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id , $ref );
2017-02-08 12:52:31 +01:00
}
2016-07-23 16:37:21 +02:00
2022-07-24 20:13:48 +02:00
$selectedvariant = ! empty ( $_SESSION [ 'addvariant_' . $object -> id ]) ? $_SESSION [ 'addvariant_' . $object -> id ] : array ();
2017-04-07 12:22:59 +02:00
2021-03-20 18:58:34 +01:00
// Security check
if ( empty ( $conf -> variants -> enabled )) {
accessforbidden ( 'Module not enabled' );
}
if ( $user -> socid > 0 ) { // Protection if external user
accessforbidden ();
}
2021-05-21 15:54:11 +02:00
if ( $object -> id > 0 ) {
if ( $object -> type == $object :: TYPE_PRODUCT ) {
restrictedArea ( $user , 'produit' , $object -> id , 'product&product' , '' , '' );
}
if ( $object -> type == $object :: TYPE_SERVICE ) {
restrictedArea ( $user , 'service' , $object -> id , 'product&product' , '' , '' );
}
} else {
restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
}
2022-05-11 15:06:11 +02:00
$usercanread = (( $object -> type == Product :: TYPE_PRODUCT && $user -> rights -> produit -> lire ) || ( $object -> type == Product :: TYPE_SERVICE && $user -> rights -> service -> lire ));
$usercancreate = (( $object -> type == Product :: TYPE_PRODUCT && $user -> rights -> produit -> creer ) || ( $object -> type == Product :: TYPE_SERVICE && $user -> rights -> service -> creer ));
$usercandelete = (( $object -> type == Product :: TYPE_PRODUCT && $user -> rights -> produit -> supprimer ) || ( $object -> type == Product :: TYPE_SERVICE && $user -> rights -> service -> supprimer ));
2021-03-20 18:58:34 +01:00
2017-02-08 14:07:54 +01:00
2017-02-08 12:52:31 +01:00
/*
* Actions
*/
2016-07-23 16:37:21 +02:00
2017-04-07 11:01:12 +02:00
if ( $cancel ) {
2020-09-07 10:18:17 +02:00
$action = '' ;
2020-11-30 13:18:23 +01:00
$massaction = '' ;
2020-09-07 10:18:17 +02:00
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
2017-04-07 11:01:12 +02:00
}
2017-04-07 12:22:59 +02:00
2019-11-14 12:09:15 +01:00
if ( ! $object -> isProduct () && ! $object -> isService ()) {
2017-02-08 12:52:31 +01:00
header ( 'Location: ' . dol_buildpath ( '/product/card.php?id=' . $object -> id , 2 ));
exit ();
2016-07-23 16:37:21 +02:00
}
2021-02-26 13:10:10 +01:00
if ( $action == 'add' ) {
2017-11-26 18:43:43 +01:00
unset ( $selectedvariant );
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
}
2021-02-26 13:10:10 +01:00
if ( $action == 'create' && GETPOST ( 'selectvariant' , 'alpha' )) { // We click on select combination
2020-09-07 10:18:17 +02:00
$action = 'add' ;
2022-03-18 15:38:44 +01:00
$attribute_id = GETPOST ( 'attribute' , 'int' );
$attribute_value_id = GETPOST ( 'value' , 'int' );
if ( $attribute_id > 0 && $attribute_value_id > 0 ) {
$feature = $attribute_id . '-' . $attribute_value_id ;
$selectedvariant [ $feature ] = $feature ;
$_SESSION [ 'addvariant_' . $object -> id ] = $selectedvariant ;
}
}
if ( $action == 'create' && $subaction == 'delete' ) { // We click on select combination
$action = 'add' ;
$feature = GETPOST ( 'feature' , 'intcomma' );
if ( isset ( $selectedvariant [ $feature ])) {
unset ( $selectedvariant [ $feature ]);
2020-09-07 10:18:17 +02:00
$_SESSION [ 'addvariant_' . $object -> id ] = $selectedvariant ;
}
2017-04-07 12:22:59 +02:00
}
2017-02-08 12:52:31 +01:00
2016-07-23 16:37:21 +02:00
$prodcomb = new ProductCombination ( $db );
$prodcomb2val = new ProductCombination2ValuePair ( $db );
$productCombination2ValuePairs1 = array ();
2022-03-18 15:38:44 +01:00
if (( $action == 'add' || $action == 'create' ) && empty ( $massaction ) && ! GETPOST ( 'selectvariant' , 'alpha' ) && empty ( $subaction )) { // We click on Create all defined combinations
2021-02-26 13:12:30 +01:00
//$features = GETPOST('features', 'array');
2020-11-30 13:18:23 +01:00
$features = $_SESSION [ 'addvariant_' . $object -> id ];
if ( ! $features ) {
2021-02-02 13:04:41 +01:00
if ( $action == 'create' ) {
setEventMessages ( $langs -> trans ( 'ErrorFieldsRequired' ), null , 'errors' );
}
2020-11-30 13:18:23 +01:00
} else {
$reference = trim ( $reference );
if ( empty ( $reference )) {
$reference = false ;
}
$weight_impact = price2num ( $weight_impact );
$price_impact = price2num ( $price_impact );
2020-08-12 10:14:29 +02:00
2020-11-30 13:18:23 +01:00
// for conf PRODUIT_MULTIPRICES
if ( $conf -> global -> PRODUIT_MULTIPRICES ) {
$level_price_impact = array_map ( 'price2num' , $level_price_impact );
2021-02-26 13:10:10 +01:00
} else {
2020-11-30 13:18:23 +01:00
$level_price_impact = array ( 1 => $price_impact );
$level_price_impact_percent = array ( 1 => $price_impact_percent );
}
2020-08-12 10:14:29 +02:00
2020-11-30 13:18:23 +01:00
$sanit_features = array ();
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
//First, sanitize
foreach ( $features as $feature ) {
2022-03-18 15:38:44 +01:00
$explode = explode ( '-' , $feature );
if ( $prodattr -> fetch ( $explode [ 0 ]) <= 0 || $prodattr_val -> fetch ( $explode [ 1 ]) <= 0 ) {
2020-11-30 13:18:23 +01:00
continue ;
}
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
// Valuepair
$sanit_features [ $explode [ 0 ]] = $explode [ 1 ];
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
$tmp = new ProductCombination2ValuePair ( $db );
$tmp -> fk_prod_attr = $explode [ 0 ];
$tmp -> fk_prod_attr_val = $explode [ 1 ];
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
$productCombination2ValuePairs1 [] = $tmp ;
}
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
$db -> begin ();
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
// sanit_feature is an array with 1 (and only 1) value per attribute.
// For example: Color->blue, Size->Small, Option->2
//var_dump($sanit_features);
2021-02-26 13:10:10 +01:00
if ( ! $prodcomb -> fetchByProductCombination2ValuePairs ( $id , $sanit_features )) {
2020-11-30 13:18:23 +01:00
$result = $prodcomb -> createProductCombination ( $user , $object , $sanit_features , array (), $level_price_impact_percent , $level_price_impact , $weight_impact , $reference );
2021-02-26 13:10:10 +01:00
if ( $result > 0 ) {
2020-11-30 13:18:23 +01:00
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
unset ( $_SESSION [ 'addvariant_' . $object -> id ]);
$db -> commit ();
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $id , 2 ));
exit ();
2016-07-23 16:37:21 +02:00
} else {
2020-11-30 13:18:23 +01:00
$langs -> load ( " errors " );
setEventMessages ( $prodcomb -> error , $prodcomb -> errors , 'errors' );
2016-07-23 16:37:21 +02:00
}
2020-11-30 13:18:23 +01:00
} else {
setEventMessages ( $langs -> trans ( 'ErrorRecordAlreadyExists' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
2020-11-30 13:18:23 +01:00
$db -> rollback ();
}
} elseif ( ! empty ( $massaction )) {
$bulkaction = $massaction ;
$error = 0 ;
2020-01-07 14:49:25 +01:00
2020-11-30 13:18:23 +01:00
$db -> begin ();
2020-01-07 14:49:25 +01:00
2020-11-30 13:18:23 +01:00
foreach ( $toselect as $prodid ) {
// need create new of Product to prevent rename dir behavior
$prodstatic = new Product ( $db );
if ( $prodstatic -> fetch ( $prodid ) < 0 ) {
continue ;
}
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
if ( $bulkaction == 'on_sell' ) {
$prodstatic -> status = 1 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
2021-11-07 18:28:59 +01:00
if ( $res <= 0 ) {
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
$error ++ ;
break ;
}
2020-11-30 13:18:23 +01:00
} elseif ( $bulkaction == 'on_buy' ) {
$prodstatic -> status_buy = 1 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
2021-11-07 18:28:59 +01:00
if ( $res <= 0 ) {
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
$error ++ ;
break ;
}
2020-11-30 13:18:23 +01:00
} elseif ( $bulkaction == 'not_sell' ) {
$prodstatic -> status = 0 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
2021-11-07 18:28:59 +01:00
if ( $res <= 0 ) {
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
$error ++ ;
break ;
}
2020-11-30 13:18:23 +01:00
} elseif ( $bulkaction == 'not_buy' ) {
$prodstatic -> status_buy = 0 ;
$res = $prodstatic -> update ( $prodstatic -> id , $user );
2021-11-07 18:28:59 +01:00
if ( $res <= 0 ) {
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
$error ++ ;
break ;
}
2020-11-30 13:18:23 +01:00
} elseif ( $bulkaction == 'delete' ) {
$res = $prodstatic -> delete ( $user , $prodstatic -> id );
2021-11-07 18:28:59 +01:00
if ( $res <= 0 ) {
setEventMessages ( $prodstatic -> error , $prodstatic -> errors , 'errors' );
$error ++ ;
break ;
}
2020-11-30 13:18:23 +01:00
} else {
break ;
2016-07-23 16:37:21 +02:00
}
2020-11-30 13:18:23 +01:00
}
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
if ( $error ) {
$db -> rollback ();
2021-11-07 18:28:59 +01:00
if ( empty ( $prodstatic -> error )) {
2020-11-30 13:18:23 +01:00
setEventMessages ( $langs -> trans ( 'CoreErrorMessage' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
2020-11-30 13:18:23 +01:00
} else {
$db -> commit ();
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
}
2020-12-21 15:43:45 +01:00
} elseif ( $action === 'update' && $valueid > 0 ) {
2020-11-30 13:18:23 +01:00
if ( $prodcomb -> fetch ( $valueid ) < 0 ) {
dol_print_error ( $db , $langs -> trans ( 'ErrorRecordNotFound' ));
exit ();
}
2016-07-23 16:37:21 +02:00
2022-02-15 11:31:09 +01:00
$prodcomb -> variation_weight = price2num ( $weight_impact );
2016-07-23 16:37:21 +02:00
2020-11-30 13:18:23 +01:00
// for conf PRODUIT_MULTIPRICES
if ( $conf -> global -> PRODUIT_MULTIPRICES ) {
$level_price_impact = array_map ( 'price2num' , $level_price_impact );
2020-08-12 10:14:29 +02:00
2020-11-30 13:18:23 +01:00
$prodcomb -> variation_price = $level_price_impact [ 1 ];
$prodcomb -> variation_price_percentage = ( bool ) $level_price_impact_percent [ 1 ];
2021-02-26 13:10:10 +01:00
} else {
2020-11-30 13:18:23 +01:00
$level_price_impact = array ( 1 => $price_impact );
$level_price_impact_percent = array ( 1 => $price_impact_percent );
2020-09-07 12:18:00 +02:00
2020-11-30 13:18:23 +01:00
$prodcomb -> variation_price = $price_impact ;
$prodcomb -> variation_price_percentage = $price_impact_percent ;
}
2020-08-12 10:14:29 +02:00
2020-11-30 13:18:23 +01:00
if ( $conf -> global -> PRODUIT_MULTIPRICES ) {
$prodcomb -> combination_price_levels = array ();
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
$productCombinationLevel = new ProductCombinationLevel ( $db );
$productCombinationLevel -> fk_product_attribute_combination = $prodcomb -> id ;
$productCombinationLevel -> fk_price_level = $i ;
$productCombinationLevel -> variation_price = $level_price_impact [ $i ];
$productCombinationLevel -> variation_price_percentage = ( bool ) $level_price_impact_percent [ $i ];
$prodcomb -> combination_price_levels [ $i ] = $productCombinationLevel ;
2020-08-12 10:14:29 +02:00
}
2020-11-30 13:18:23 +01:00
}
2020-08-12 10:14:29 +02:00
2020-11-30 13:18:23 +01:00
if ( $prodcomb -> update ( $user ) > 0 ) {
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $id , 2 ));
exit ();
} else {
setEventMessages ( $prodcomb -> error , $prodcomb -> errors , 'errors' );
2016-07-23 16:37:21 +02:00
}
}
2020-11-30 13:18:23 +01:00
2017-04-07 12:22:59 +02:00
// Reload variants
2017-02-08 12:52:31 +01:00
$productCombinations = $prodcomb -> fetchAllByFkProductParent ( $object -> id );
2016-07-23 16:37:21 +02:00
if ( $action === 'confirm_deletecombination' ) {
if ( $prodcomb -> fetch ( $valueid ) > 0 ) {
$db -> begin ();
2019-11-23 18:03:46 +01:00
if ( $prodcomb -> delete ( $user ) > 0 && ( empty ( $delete_product ) || ( $delete_product == 'on' && $prodstatic -> fetch ( $prodcomb -> fk_product_child ) > 0 && $prodstatic -> delete ( $user ) > 0 ))) {
2016-07-23 16:37:21 +02:00
$db -> commit ();
2018-07-27 14:49:33 +02:00
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
2017-02-08 12:52:31 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $object -> id , 2 ));
exit ();
2016-07-23 16:37:21 +02:00
}
$db -> rollback ();
2018-07-27 14:49:33 +02:00
setEventMessages ( $langs -> trans ( 'ProductCombinationAlreadyUsed' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
$action = '' ;
}
} elseif ( $action === 'edit' ) {
if ( $prodcomb -> fetch ( $valueid ) < 0 ) {
dol_print_error ( $db , $langs -> trans ( 'ErrorRecordNotFound' ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
}
$weight_impact = $prodcomb -> variation_weight ;
$price_impact = $prodcomb -> variation_price ;
$price_impact_percent = $prodcomb -> variation_price_percentage ;
$productCombination2ValuePairs1 = $prodcomb2val -> fetchByFkCombination ( $valueid );
} elseif ( $action === 'confirm_copycombination' ) {
//Check destination product
$dest_product = GETPOST ( 'dest_product' );
if ( $prodstatic -> fetch ( '' , $dest_product ) > 0 ) {
//To prevent from copying to the same product
2017-02-08 12:52:31 +01:00
if ( $prodstatic -> ref != $object -> ref ) {
2019-11-17 01:25:44 +01:00
if ( $prodcomb -> copyAll ( $user , $object -> id , $prodstatic ) > 0 ) {
2017-02-08 12:37:38 +01:00
header ( 'Location: ' . dol_buildpath ( '/variants/combinations.php?id=' . $prodstatic -> id , 2 ));
2017-02-08 12:52:31 +01:00
exit ();
2016-07-23 16:37:21 +02:00
} else {
2018-07-27 14:49:33 +02:00
setEventMessages ( $langs -> trans ( 'ErrorCopyProductCombinations' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
}
} else {
2018-07-27 14:49:33 +02:00
setEventMessages ( $langs -> trans ( 'ErrorDestinationProductNotFound' ), null , 'errors' );
2016-07-23 16:37:21 +02:00
}
}
2017-02-08 12:52:31 +01:00
2016-07-23 16:37:21 +02:00
/*
* View
*/
2017-04-07 11:01:12 +02:00
$form = new Form ( $db );
2021-02-26 13:10:10 +01:00
if ( ! empty ( $id ) || ! empty ( $ref )) {
2016-07-23 16:37:21 +02:00
llxHeader ( " " , " " , $langs -> trans ( " CardProduct " . $object -> type ));
2020-09-07 10:18:17 +02:00
$showbarcode = empty ( $conf -> barcode -> enabled ) ? 0 : 1 ;
2021-02-26 13:10:10 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> barcode -> lire_advance )) {
$showbarcode = 0 ;
}
2017-07-28 09:45:23 +02:00
2020-09-07 10:18:17 +02:00
$head = product_prepare_head ( $object );
$titre = $langs -> trans ( " CardProduct " . $object -> type );
$picto = ( $object -> type == Product :: TYPE_SERVICE ? 'service' : 'product' );
2019-05-21 13:27:45 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'combinations' , $titre , - 1 , $picto );
2017-07-28 09:45:23 +02:00
2020-09-07 10:18:17 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/product/list.php?type=' . $object -> type . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$object -> next_prev_filter = " fk_product_type = " . $object -> type ;
2017-07-28 09:45:23 +02:00
2021-06-08 11:40:50 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , ( $user -> socid ? 0 : 1 ), 'ref' , '' , '' , '' , 0 , '' , '' );
2017-07-28 09:45:23 +02:00
2018-10-18 12:21:39 +02:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2021-06-08 11:40:50 +02:00
print '<table class="border centpercent tableforfield">' ;
// Type
if ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) {
$typeformat = 'select;0:' . $langs -> trans ( " Product " ) . ',1:' . $langs -> trans ( " Service " );
print '<tr><td class="titlefieldcreate">' ;
print ( empty ( $conf -> global -> PRODUCT_DENY_CHANGE_PRODUCT_TYPE )) ? $form -> editfieldkey ( " Type " , 'fk_product_type' , $object -> type , $object , $usercancreate , $typeformat ) : $langs -> trans ( 'Type' );
print '</td><td>' ;
print $form -> editfieldval ( " Type " , 'fk_product_type' , $object -> type , $object , $usercancreate , $typeformat );
print '</td></tr>' ;
}
2018-10-18 12:21:39 +02:00
2020-09-07 10:18:17 +02:00
// TVA
2021-06-08 11:40:50 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " DefaultTaxRate " ) . '</td><td>' ;
2019-11-14 12:09:15 +01:00
2020-09-07 10:18:17 +02:00
$positiverates = '' ;
2021-02-26 13:10:10 +01:00
if ( price2num ( $object -> tva_tx )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> tva_tx );
}
if ( price2num ( $object -> localtax1_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax1_tx );
}
if ( price2num ( $object -> localtax2_type )) {
$positiverates .= ( $positiverates ? '/' : '' ) . price2num ( $object -> localtax2_tx );
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2020-09-07 10:18:17 +02:00
echo vatrate ( $positiverates . ( $object -> default_vat_code ? ' (' . $object -> default_vat_code . ')' : '' ), '%' , $object -> tva_npr );
/*
2021-02-26 13:10:10 +01:00
if ( $object -> default_vat_code )
{
print vatrate ( $object -> tva_tx , true ) . ' (' . $object -> default_vat_code . ')' ;
}
else print vatrate ( $object -> tva_tx , true , $object -> tva_npr , true ); */
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
// 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 );
}
print '</td></tr>' ;
// Price minimum
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 );
}
print '</td></tr>' ;
2018-10-18 12:21:39 +02:00
// Weight
print '<tr><td>' . $langs -> trans ( " Weight " ) . '</td><td>' ;
2021-02-26 13:10:10 +01:00
if ( $object -> weight != '' ) {
2019-10-22 18:36:36 +02:00
print $object -> weight . " " . measuringUnitString ( 0 , " weight " , $object -> weight_units );
2020-05-21 09:21:30 +02:00
} else {
2018-10-18 12:21:39 +02:00
print ' ' ;
}
print " </td></tr> \n " ;
print " </table> \n " ;
print '</div>' ;
print '<div style="clear:both"></div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-07-23 16:37:21 +02:00
2019-10-12 15:27:06 +02:00
$listofvariantselected = '' ;
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
// Create or edit a varian
2016-07-23 16:37:21 +02:00
if ( $action == 'add' || ( $action == 'edit' )) {
if ( $action == 'add' ) {
$title = $langs -> trans ( 'NewProductCombination' );
2020-10-22 22:50:03 +02:00
// print dol_get_fiche_head();
2018-04-24 12:08:17 +02:00
$features = $_SESSION [ 'addvariant_' . $object -> id ];
//First, sanitize
2019-10-12 15:27:06 +02:00
$listofvariantselected = '<div id="parttoaddvariant">' ;
2019-11-14 12:09:15 +01:00
if ( ! empty ( $features )) {
2022-03-18 15:38:44 +01:00
$toprint = array ();
2018-04-24 12:08:17 +02:00
foreach ( $features as $feature ) {
2022-03-18 15:38:44 +01:00
$explode = explode ( '-' , $feature );
if ( $prodattr -> fetch ( $explode [ 0 ]) <= 0 || $prodattr_val -> fetch ( $explode [ 1 ]) <= 0 ) {
2018-04-24 12:08:17 +02:00
continue ;
}
2022-03-18 15:38:44 +01:00
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #ddd;">' . $prodattr -> label . ' : ' . $prodattr_val -> value .
' <a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=create&subaction=delete&feature=' . urlencode ( $feature ) . '">' . img_delete () . '</a></li>' ;
2018-04-24 12:08:17 +02:00
}
2022-03-18 15:38:44 +01:00
$listofvariantselected .= '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2018-04-24 12:08:17 +02:00
}
2019-10-12 15:27:06 +02:00
$listofvariantselected .= '</div>' ;
2020-10-27 18:19:31 +01:00
//print dol_get_fiche_end();
2016-07-23 16:37:21 +02:00
} else {
$title = $langs -> trans ( 'EditProductCombination' );
}
if ( $action == 'add' ) {
2022-10-08 07:49:02 +02:00
$prodattr_all = $prodattr -> fetchAll ( 1 );
2016-07-23 16:37:21 +02:00
if ( ! $selected ) {
$selected = $prodattr_all [ key ( $prodattr_all )] -> id ;
}
$prodattr_alljson = array ();
foreach ( $prodattr_all as $each ) {
$prodattr_alljson [ $each -> id ] = $each ;
}
2018-04-24 12:08:17 +02:00
?>
2016-07-23 16:37:21 +02:00
2017-04-07 12:22:59 +02:00
< script type = " text/javascript " >
2016-07-23 16:37:21 +02:00
2018-03-10 14:51:24 +01:00
variants_available = < ? php echo json_encode ( $prodattr_alljson ); ?> ;
2017-02-08 12:37:38 +01:00
variants_selected = {
2016-07-23 16:37:21 +02:00
index : [],
info : []
};
2017-07-28 09:45:23 +02:00
< ? php
2017-03-11 12:04:28 +01:00
foreach ( $productCombination2ValuePairs1 as $pc2v ) {
2020-09-07 10:18:17 +02:00
$prodattr_val -> fetch ( $pc2v -> fk_prod_attr_val );
2019-10-26 20:53:39 +02:00
?>
2021-02-26 13:10:10 +01:00
variants_selected . index . push ( < ? php echo $pc2v -> fk_prod_attr ?> );
variants_selected . info [ < ? php echo $pc2v -> fk_prod_attr ?> ] = {
attribute : variants_available [ < ? php echo $pc2v -> fk_prod_attr ?> ],
value : {
id : < ? php echo $pc2v -> fk_prod_attr_val ?> ,
label : '<?php echo $prodattr_val->value ?>'
}
};
2019-10-26 20:53:39 +02:00
< ? php
2020-09-07 10:18:17 +02:00
}
?>
2016-07-23 16:37:21 +02:00
restoreAttributes = function () {
2017-03-11 12:04:28 +01:00
jQuery ( " select[name=attribute] " ) . empty () . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
2017-02-08 12:37:38 +01:00
jQuery . each ( variants_available , function ( key , val ) {
if ( jQuery . inArray ( val . id , variants_selected . index ) == - 1 ) {
2016-07-23 16:37:21 +02:00
jQuery ( " select[name=attribute] " ) . append ( '<option value="' + val . id + '">' + val . label + '</option>' );
}
});
};
2017-07-28 09:45:23 +02:00
2016-07-23 16:37:21 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " select#attribute " ) . change ( function () {
2017-04-07 11:01:12 +02:00
console . log ( " Change of field variant attribute " );
2016-07-23 16:37:21 +02:00
var select = jQuery ( " select#value " );
2017-03-11 12:04:28 +01:00
if ( ! jQuery ( this ) . val () . length || jQuery ( this ) . val () == '-1' ) {
2016-07-23 16:37:21 +02:00
select . empty ();
2017-04-07 11:01:12 +02:00
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
return ;
}
select . empty () . append ( '<option value="">Loading...</option>' );
2018-04-11 11:44:22 +02:00
jQuery . getJSON ( " ajax/get_attribute_values.php " , {
2016-07-23 16:37:21 +02:00
id : jQuery ( this ) . val ()
}, function ( data ) {
if ( data . error ) {
2017-04-07 11:01:12 +02:00
select . empty ();
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
return alert ( data . error );
}
select . empty ();
2017-04-07 11:01:12 +02:00
select . append ( '<option value="-1"> </option>' );
2016-07-23 16:37:21 +02:00
jQuery ( data ) . each ( function ( key , val ) {
2017-03-11 12:04:28 +01:00
keyforoption = val . id
valforoption = val . value
2017-04-07 11:01:12 +02:00
select . append ( '<option value="' + keyforoption + '">' + valforoption + '</option>' );
2016-07-23 16:37:21 +02:00
});
});
});
});
</ script >
2017-07-28 09:45:23 +02:00
2019-10-26 20:53:39 +02:00
< ? php
2017-03-11 12:04:28 +01:00
}
2017-07-28 09:45:23 +02:00
2019-10-12 15:27:06 +02:00
print '<br>' ;
print load_fiche_titre ( $title );
2022-03-18 15:38:44 +01:00
print '<form method="post" id="combinationform" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-12-18 15:20:36 +01:00
print '<input type="hidden" name="action" value="' . (( $valueid > 0 ) ? " update " : " create " ) . '">' . " \n " ;
2020-09-07 10:18:17 +02:00
if ( $valueid > 0 ) {
print '<input type="hidden" name="valueid" value="' . $valueid . '">' . " \n " ;
}
2018-08-07 16:55:50 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2017-07-28 09:45:23 +02:00
2019-10-26 20:53:39 +02:00
if ( $action == 'add' ) {
2020-08-17 21:59:50 +02:00
print '<table class="border" style="width: 100%">' ;
2019-10-26 20:53:39 +02:00
print " <!-- Variant --> \n " ;
print '<tr>' ;
print '<td class="titlefieldcreate fieldrequired"><label for="attribute">' . $langs -> trans ( 'ProductAttribute' ) . '</label></td>' ;
print '<td>' ;
if ( is_array ( $prodattr_all )) {
print '<select class="flat minwidth100" id="attribute" name="attribute">' ;
print '<option value="-1"> </option>' ;
foreach ( $prodattr_all as $attr ) {
//print '<option value="'.$attr->id.'"'.($attr->id == GETPOST('attribute', 'int') ? ' selected="selected"' : '').'>'.$attr->label.'</option>';
print '<option value="' . $attr -> id . '">' . $attr -> label . '</option>' ;
2017-11-26 10:13:32 +01:00
}
2019-10-26 20:53:39 +02:00
print '</select>' ;
}
2017-11-26 10:13:32 +01:00
2019-12-18 15:20:36 +01:00
$htmltext = $langs -> trans ( " GoOnMenuToCreateVairants " , $langs -> transnoentities ( " Product " ), $langs -> transnoentities ( " VariantAttributes " ));
2019-10-26 20:53:39 +02:00
print $form -> textwithpicto ( '' , $htmltext );
2021-10-02 12:58:15 +02:00
/* print ' <a href="' . DOL_URL_ROOT . '/variants/create.php?action=create&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=add&token=' . newToken () . '&id=' . $object -> id ) . '">' ;
2019-10-26 20:53:39 +02:00
print $langs -> trans ( " Create " );
print '</a>' ; */
2017-11-26 10:13:32 +01:00
2020-08-17 21:59:50 +02:00
print '</td>' ;
print '</tr>' ;
2019-10-26 20:53:39 +02:00
?>
2017-04-07 11:01:12 +02:00
<!-- Value -->
2016-07-23 16:37:21 +02:00
< tr >
2017-03-11 12:04:28 +01:00
< td class = " fieldrequired " >< label for = " value " >< ? php echo $langs -> trans ( 'Value' ) ?> </label></td>
2017-04-07 11:01:12 +02:00
< td >
2017-03-11 12:04:28 +01:00
< select class = " flat minwidth100 " id = " value " name = " value " >
< option value = " -1 " >& nbsp ; </ option >
2016-07-23 16:37:21 +02:00
</ select >
2017-11-26 10:13:32 +01:00
< ? php
2019-11-14 12:09:15 +01:00
$htmltext = $langs -> trans ( " GoOnMenuToCreateVairants " , $langs -> transnoentities ( " Product " ), $langs -> transnoentities ( " VariantAttributes " ));
2017-11-26 10:13:32 +01:00
print $form -> textwithpicto ( '' , $htmltext );
/*
2021-10-02 12:58:15 +02:00
print ' <a href="' . DOL_URL_ROOT . '/variants/create.php?action=create&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=add&token=' . newToken () . '&id=' . $object -> id ) . '">' ;
2017-11-26 10:13:32 +01:00
print $langs -> trans ( " Create " );
print '</a>' ;
*/
?>
2016-07-23 16:37:21 +02:00
</ td >
</ tr >
< tr >
2017-04-07 11:01:12 +02:00
< td ></ td >< td >
2017-04-07 12:22:59 +02:00
< input type = " submit " class = " button " name = " selectvariant " id = " selectvariant " value = " <?php echo dol_escape_htmltag( $langs->trans ( " SelectCombination " )); ?> " >
2017-04-07 11:01:12 +02:00
</ td >
</ tr >
2020-08-17 21:59:50 +02:00
< ? php
print '<tr><td></td><td>' ;
print $listofvariantselected ;
2019-10-26 20:53:39 +02:00
print '</td>' ;
print '</tr>' ;
2020-08-17 21:59:50 +02:00
2019-10-26 20:53:39 +02:00
print '</table>' ;
2020-08-17 13:55:18 +02:00
print '<hr>' ;
2020-09-07 10:18:17 +02:00
}
2017-11-26 18:43:43 +01:00
2018-03-10 14:51:24 +01:00
if ( is_array ( $productCombination2ValuePairs1 )) {
2020-08-17 21:59:50 +02:00
print '<table class="border" style="width: 100%">' ;
2020-08-17 13:55:18 +02:00
// When in edit mode
2021-02-26 13:10:10 +01:00
if ( is_array ( $productCombination2ValuePairs1 ) && count ( $productCombination2ValuePairs1 )) {
2020-08-17 23:30:53 +02:00
?>
< tr >
< td class = " titlefieldcreate tdtop " >< label for = " features " >< ? php echo $langs -> trans ( 'Combination' ) ?> </label></td>
< td class = " tdtop " >
< div class = " inline-block valignmiddle quatrevingtpercent " >
2017-04-07 12:22:59 +02:00
< ? php
2020-08-18 00:29:13 +02:00
foreach ( $productCombination2ValuePairs1 as $key => $val ) {
$result1 = $prodattr -> fetch ( $val -> fk_prod_attr );
$result2 = $prodattr_val -> fetch ( $val -> fk_prod_attr_val );
//print 'rr'.$result1.' '.$result2;
2021-02-26 13:10:10 +01:00
if ( $result1 > 0 && $result2 > 0 ) {
2020-08-18 00:29:13 +02:00
print $prodattr -> label . ' - ' . $prodattr_val -> value . '<br>' ;
// TODO Add delete link
}
}
2017-04-07 12:22:59 +02:00
?>
2020-08-17 23:30:53 +02:00
</ div >
<!-- < div class = " inline-block valignmiddle " >
< a href = " # " class = " inline-block valignmiddle button " id = " delfeature " >< ? php echo img_edit_remove () ?> </a>
</ div >-->
</ td >
< td >
</ td >
</ tr >
< ? php
2020-08-17 13:55:18 +02:00
}
?>
2019-11-23 17:04:14 +01:00
< tr >
< td >< label for = " reference " >< ? php echo $langs -> trans ( 'Reference' ) ?> </label></td>
< td >< input type = " text " id = " reference " name = " reference " value = " <?php echo trim( $reference ) ?> " ></ td >
</ tr >
2020-08-17 21:59:50 +02:00
< ? php
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2020-08-17 23:30:53 +02:00
?>
2016-07-23 16:37:21 +02:00
< tr >
2017-03-11 12:04:28 +01:00
< td >< label for = " price_impact " >< ? php echo $langs -> trans ( 'PriceImpact' ) ?> </label></td>
2017-04-07 11:01:12 +02:00
< td >< input type = " text " id = " price_impact " name = " price_impact " value = " <?php echo price( $price_impact ) ?> " >
2020-08-12 10:14:29 +02:00
< input type = " checkbox " id = " price_impact_percent " name = " price_impact_percent " < ? php echo $price_impact_percent ? ' checked' : '' ?> > <label for="price_impact_percent"><?php echo $langs->trans('PercentageVariation') ?></label>
</ td >
2016-07-23 16:37:21 +02:00
</ tr >
2020-08-17 23:30:53 +02:00
< ? php
2020-08-17 21:59:50 +02:00
} else {
2020-08-12 10:14:29 +02:00
$prodcomb -> fetchCombinationPriceLevels ();
2021-02-26 13:10:10 +01:00
for ( $i = 1 ; $i <= $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ; $i ++ ) {
2020-08-12 10:14:29 +02:00
print '<tr>' ;
2020-08-12 10:53:24 +02:00
print '<td><label for="level_price_impact_' . $i . '">' . $langs -> trans ( 'ImpactOnPriceLevel' , $i ) . '</label>' ;
2020-09-07 10:18:17 +02:00
if ( $i === 1 ) {
2020-08-12 10:14:29 +02:00
print ' <a id="apply-price-impact-to-all-level" class="classfortooltip" href="#" title="' . $langs -> trans ( 'ApplyToAllPriceImpactLevelHelp' ) . '">(' . $langs -> trans ( 'ApplyToAllPriceImpactLevel' ) . ')</a>' ;
}
print '</td>' ;
print '<td><input type="text" class="level_price_impact" id="level_price_impact_' . $i . '" name="level_price_impact[' . $i . ']" value="' . price ( $prodcomb -> combination_price_levels [ $i ] -> variation_price ) . '">' ;
2020-09-07 10:18:17 +02:00
print '<input type="checkbox" class="level_price_impact_percent" id="level_price_impact_percent_' . $i . '" name="level_price_impact_percent[' . $i . ']" ' . ( ! empty ( $prodcomb -> combination_price_levels [ $i ] -> variation_price_percentage ) ? ' checked' : '' ) . '> <label for="level_price_impact_percent_' . $i . '">' . $langs -> trans ( 'PercentageVariation' ) . '</label>' ;
2020-08-12 10:14:29 +02:00
print '</td>' ;
print '</tr>' ;
}
}
2020-09-07 10:18:17 +02:00
if ( $object -> isProduct ()) {
2018-04-24 11:01:17 +02:00
print '<tr>' ;
print '<td><label for="weight_impact">' . $langs -> trans ( 'WeightImpact' ) . '</label></td>' ;
print '<td><input type="text" id="weight_impact" name="weight_impact" value="' . price ( $weight_impact ) . '"></td>' ;
print '</tr>' ;
}
2020-08-17 21:59:50 +02:00
2018-04-24 11:01:17 +02:00
print '</table>' ;
2017-11-26 18:43:43 +01:00
}
2020-09-07 10:18:17 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2020-08-12 10:53:24 +02:00
?>
2020-08-17 21:59:50 +02:00
< script >
$ ( document ) . ready ( function () {
// Apply level 1 impact to all prices impact levels
$ ( 'body' ) . on ( 'click' , '#apply-price-impact-to-all-level' , function ( e ) {
e . preventDefault ();
let priceImpact = $ ( " #level_price_impact_1 " ) . val ();
let priceImpactPrecent = $ ( " #level_price_impact_percent_1 " ) . prop ( " checked " );
var multipricelimit = < ? php print intval ( $conf -> global -> PRODUIT_MULTIPRICES_LIMIT ); ?>
for ( let i = 2 ; i <= multipricelimit ; i ++ ) {
$ ( " #level_price_impact_ " + i ) . val ( priceImpact );
$ ( " #level_price_impact_percent_ " + i ) . prop ( " checked " , priceImpactPrecent );
}
});
2020-08-12 10:14:29 +02:00
});
2020-08-17 21:59:50 +02:00
</ script >
2020-08-12 10:53:24 +02:00
< ? php
2020-08-12 10:14:29 +02:00
}
2017-03-11 12:04:28 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-08-12 10:53:24 +02:00
?>
2020-08-17 21:59:50 +02:00
2017-03-11 12:04:28 +01:00
< div style = " text-align: center " >
2021-02-26 13:10:10 +01:00
< input type = " submit " name = " create " < ? php if ( ! is_array ( $productCombination2ValuePairs1 )) {
print ' disabled="disabled"' ;
} ?> value="<?php echo $action == 'add' ? $langs->trans('Create') : $langs->trans("Save") ?>" class="button button-save">
2017-04-07 11:01:12 +02:00
& nbsp ;
2020-11-23 15:12:52 +01:00
< input type = " submit " name = " cancel " value = " <?php echo $langs->trans ( " Cancel " ); ?> " class = " button button-cancel " >
2017-04-07 11:01:12 +02:00
</ div >
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
< ? php
2016-07-23 16:37:21 +02:00
2020-09-07 10:18:17 +02:00
print '</form>' ;
2020-05-21 09:21:30 +02:00
} else {
2016-07-23 16:37:21 +02:00
if ( $action === 'delete' ) {
if ( $prodcomb -> fetch ( $valueid ) > 0 ) {
$prodstatic -> fetch ( $prodcomb -> fk_product_child );
print $form -> formconfirm (
2021-04-25 15:55:36 +02:00
" combinations.php?id= " . urlencode ( $id ) . " &valueid= " . urlencode ( $valueid ),
2016-07-23 16:37:21 +02:00
$langs -> trans ( 'Delete' ),
2017-02-08 12:37:38 +01:00
$langs -> trans ( 'ProductCombinationDeleteDialog' , $prodstatic -> ref ),
2016-07-23 16:37:21 +02:00
" confirm_deletecombination " ,
2020-04-10 10:59:32 +02:00
array ( array ( 'label' => $langs -> trans ( 'DeleteLinkedProduct' ), 'type' => 'checkbox' , 'name' => 'delete_product' , 'value' => false )),
2016-07-23 16:37:21 +02:00
0 ,
1
);
}
} elseif ( $action === 'copy' ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( 'combinations.php?id=' . $id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneProductCombinations' ), 'confirm_copycombination' , array ( array ( 'type' => 'text' , 'label' => $langs -> trans ( 'CloneDestinationReference' ), 'name' => 'dest_product' )), 0 , 1 );
2016-07-23 16:37:21 +02:00
}
$comb2val = new ProductCombination2ValuePair ( $db );
2021-02-26 13:10:10 +01:00
if ( $productCombinations ) {
2020-08-17 23:30:53 +02:00
?>
2016-07-23 16:37:21 +02:00
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( 'input[name="select_all"]' ) . click ( function () {
if ( jQuery ( this ) . prop ( 'checked' )) {
var checked = true ;
} else {
var checked = false ;
}
jQuery ( 'table.liste input[type="checkbox"]' ) . prop ( 'checked' , checked );
});
jQuery ( 'input[name^="select["]' ) . click ( function () {
jQuery ( 'input[name="select_all"]' ) . prop ( 'checked' , false );
});
});
</ script >
2020-08-17 23:30:53 +02:00
< ? php
2020-08-17 21:59:50 +02:00
}
2017-07-28 09:45:23 +02:00
2020-09-07 10:18:17 +02:00
// Buttons
2017-03-11 12:04:28 +01:00
print '<div class="tabsAction">' ;
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
print ' <div class="inline-block divButAction">' ;
2017-07-28 09:45:23 +02:00
2021-02-02 13:04:41 +01:00
print '<a href="combinations.php?id=' . $object -> id . '&action=add&token=' . newToken () . '" class="butAction">' . $langs -> trans ( 'NewProductCombination' ) . '</a>' ; // NewVariant
2017-07-28 09:45:23 +02:00
2021-02-26 13:10:10 +01:00
if ( $productCombinations ) {
2021-02-02 13:04:41 +01:00
print '<a href="combinations.php?id=' . $object -> id . '&action=copy&token=' . newToken () . '" class="butAction">' . $langs -> trans ( 'PropagateVariant' ) . '</a>' ;
2018-10-16 20:27:33 +02:00
}
2017-03-11 12:04:28 +01:00
print ' </div>' ;
2017-07-28 09:45:23 +02:00
2017-03-11 12:04:28 +01:00
print '</div>' ;
2017-07-28 09:45:23 +02:00
2019-11-14 12:09:15 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
// List of variants
2022-03-18 15:38:44 +01:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-11-26 18:43:43 +01:00
print '<input type="hidden" name="action" value="massaction">' ;
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
2017-07-28 09:45:23 +02:00
2017-04-07 12:22:59 +02:00
// List of mass actions available
/*
$arrayofmassactions = array (
2021-02-26 13:10:10 +01:00
'presend' => $langs -> trans ( " SendByMail " ),
'builddoc' => $langs -> trans ( " PDFMerge " ),
2017-04-07 12:22:59 +02:00
);
2019-04-09 01:22:59 +02:00
if ( $user -> rights -> product -> supprimer ) $arrayofmassactions [ 'predelete' ] = '<span class="fa fa-trash paddingrightonly"></span>' . $langs -> trans ( " Delete " );
2017-11-11 16:03:22 +01:00
if ( in_array ( $massaction , array ( 'presend' , 'predelete' ))) $arrayofmassactions = array ();
2017-04-07 12:22:59 +02:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
*/
2017-07-28 09:45:23 +02:00
2019-11-14 12:09:15 +01:00
$aaa = '' ;
2021-02-26 13:10:10 +01:00
if ( count ( $productCombinations )) {
2020-09-07 10:18:17 +02:00
$aaa = '<label for="massaction">' . $langs -> trans ( 'BulkActions' ) . '</label>' ;
$aaa .= '<select id="bulk_action" name="massaction" class="flat">' ;
$aaa .= ' <option value="nothing"> </option>' ;
$aaa .= ' <option value="not_buy">' . $langs -> trans ( 'ProductStatusNotOnBuy' ) . '</option>' ;
$aaa .= ' <option value="not_sell">' . $langs -> trans ( 'ProductStatusNotOnSell' ) . '</option>' ;
$aaa .= ' <option value="on_buy">' . $langs -> trans ( 'ProductStatusOnBuy' ) . '</option>' ;
$aaa .= ' <option value="on_sell">' . $langs -> trans ( 'ProductStatusOnSell' ) . '</option>' ;
$aaa .= ' <option value="delete">' . $langs -> trans ( 'Delete' ) . '</option>' ;
$aaa .= '</select>' ;
2021-11-07 18:28:59 +01:00
$aaa .= '<input type="submit" value="' . dol_escape_htmltag ( $langs -> trans ( " Apply " )) . '" class="button small">' ;
2017-04-07 11:01:12 +02:00
}
2017-04-07 12:22:59 +02:00
$massactionbutton = $aaa ;
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
$title = $langs -> trans ( " ProductCombinations " );
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
print_barre_liste ( $title , 0 , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , $aaa , 0 );
2017-07-28 09:45:23 +02:00
2017-04-07 11:01:12 +02:00
print '<div class="div-table-responsive">' ;
2017-03-11 12:04:28 +01:00
?>
2016-07-23 16:37:21 +02:00
< table class = " liste " >
< tr class = " liste_titre " >
2017-04-07 12:22:59 +02:00
< td class = " liste_titre " >< ? php echo $langs -> trans ( 'Product' ) ?> </td>
< td class = " liste_titre " >< ? php echo $langs -> trans ( 'Combination' ) ?> </td>
< td class = " liste_titre right " >< ? php echo $langs -> trans ( 'PriceImpact' ) ?> </td>
2021-02-26 13:10:10 +01:00
< ? php if ( $object -> isProduct ()) {
print '<td class="liste_titre right">' . $langs -> trans ( 'WeightImpact' ) . '</td>' ;
} ?>
2017-04-07 12:22:59 +02:00
< td class = " liste_titre center " >< ? php echo $langs -> trans ( 'OnSell' ) ?> </td>
< td class = " liste_titre center " >< ? php echo $langs -> trans ( 'OnBuy' ) ?> </td>
< td class = " liste_titre " ></ td >
2021-02-26 13:10:10 +01:00
< ? php
2020-09-07 10:18:17 +02:00
print '<td class="liste_titre center">' ;
$searchpicto = $form -> showCheckAddButtons ( 'checkforselect' , 1 );
print $searchpicto ;
print '</td>' ;
?>
2016-07-23 16:37:21 +02:00
</ tr >
2019-10-26 20:53:39 +02:00
< ? php
2017-07-28 09:45:23 +02:00
2021-02-26 13:10:10 +01:00
if ( count ( $productCombinations )) {
foreach ( $productCombinations as $currcomb ) {
2020-09-07 10:18:17 +02:00
$prodstatic -> fetch ( $currcomb -> fk_product_child );
print '<tr class="oddeven">' ;
print '<td>' . $prodstatic -> getNomUrl ( 1 ) . '</td>' ;
print '<td>' ;
$productCombination2ValuePairs = $comb2val -> fetchByFkCombination ( $currcomb -> id );
$iMax = count ( $productCombination2ValuePairs );
for ( $i = 0 ; $i < $iMax ; $i ++ ) {
echo dol_htmlentities ( $productCombination2ValuePairs [ $i ]);
if ( $i !== ( $iMax - 1 )) {
echo ', ' ;
}
}
print '</td>' ;
print '<td class="right">' . ( $currcomb -> variation_price >= 0 ? '+' : '' ) . price ( $currcomb -> variation_price ) . ( $currcomb -> variation_price_percentage ? ' %' : '' ) . '</td>' ;
if ( $object -> isProduct ()) {
2019-10-26 20:53:39 +02:00
print '<td class="right">' . ( $currcomb -> variation_weight >= 0 ? '+' : '' ) . price ( $currcomb -> variation_weight ) . ' ' . measuringUnitString ( 0 , 'weight' , $prodstatic -> weight_units ) . '</td>' ;
}
2020-09-07 10:18:17 +02:00
print '<td class="center">' . $prodstatic -> getLibStatut ( 2 , 0 ) . '</td>' ;
print '<td class="center">' . $prodstatic -> getLibStatut ( 2 , 1 ) . '</td>' ;
print '<td class="right">' ;
2021-09-19 14:41:46 +02:00
print '<a class="paddingleft paddingright editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id . '&action=edit&token=' . newToken () . '&valueid=' . $currcomb -> id . '">' . img_edit () . '</a>' ;
2020-10-01 10:50:54 +02:00
print '<a class="paddingleft paddingright" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id . '&action=delete&token=' . newToken () . '&valueid=' . $currcomb -> id . '">' . img_delete () . '</a>' ;
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '<td class="nowrap center">' ;
2022-06-13 14:33:23 +02:00
if ( ! empty ( $productCombinations ) || $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2020-09-07 10:18:17 +02:00
$selected = 0 ;
2021-02-26 13:10:10 +01:00
if ( in_array ( $prodstatic -> id , $arrayofselected )) {
$selected = 1 ;
}
2020-09-07 10:18:17 +02:00
print '<input id="cb' . $prodstatic -> id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $prodstatic -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
print '</td>' ;
print '</tr>' ;
}
2020-05-21 09:21:30 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<tr><td colspan="8"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2019-10-26 20:53:39 +02:00
}
print '</table>' ;
2017-04-07 11:01:12 +02:00
print '</div>' ;
print '</form>' ;
2016-07-23 16:37:21 +02:00
}
2018-04-11 12:10:58 +02:00
} else {
llxHeader ();
// not found
2016-07-23 16:37:21 +02:00
}
2018-08-04 15:58:05 +02:00
// End of page
2016-07-23 16:37:21 +02:00
llxFooter ();
2017-04-07 11:01:12 +02:00
$db -> close ();