dolibarr/htdocs/product/composition/card.php

661 lines
22 KiB
PHP
Raw Normal View History

2006-03-20 09:54:48 +01:00
<?php
2015-05-23 18:52:31 +02:00
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2017-09-15 19:13:40 +02:00
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2015-05-23 18:52:31 +02:00
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
2015-05-23 18:52:31 +02:00
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
2006-03-20 09:54:48 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2006-03-20 09:54:48 +01: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/>.
2006-03-20 09:54:48 +01:00
*/
/**
* \file htdocs/product/composition/card.php
2008-09-04 17:16:30 +02:00
* \ingroup product
* \brief Page de la fiche produit
*/
2006-03-20 09:54:48 +01:00
require '../../main.inc.php';
2010-03-22 14:24:43 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2008-10-23 23:54:30 +02:00
2018-05-26 17:57:30 +02:00
// Load translation files required by the page
$langs->loadLangs(array('bills', 'products', 'stocks'));
2006-03-20 09:54:48 +01:00
2012-07-09 12:31:21 +02:00
$id=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
$cancel=GETPOST('cancel','alpha');
$key=GETPOST('key');
2012-10-08 20:44:12 +02:00
$parent=GETPOST('parent');
2012-07-09 12:31:21 +02:00
// Security check
2012-07-09 12:31:21 +02:00
if (! empty($user->societe_id)) $socid=$user->societe_id;
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
2015-03-11 14:55:45 +01:00
$object = new Product($db);
$objectid=0;
if ($id > 0 || ! empty($ref))
2008-10-23 23:54:30 +02:00
{
2015-03-11 14:55:45 +01:00
$result = $object->fetch($id,$ref);
$objectid=$object->id;
$id=$object->id;
2008-10-23 23:54:30 +02:00
}
2006-03-20 09:54:48 +01:00
/*
* Actions
*/
2015-02-24 19:55:59 +01:00
if ($cancel) $action ='';
2006-03-20 12:34:32 +01:00
// Action association d'un sousproduit
2015-02-24 19:55:59 +01:00
if ($action == 'add_prod' && ($user->rights->produit->creer || $user->rights->service->creer))
2006-03-20 09:54:48 +01:00
{
$error=0;
for ($i=0; $i<$_POST["max_prod"]; $i++)
2008-10-23 23:54:30 +02:00
{
2015-02-24 19:55:59 +01:00
if ($_POST["prod_qty_".$i] > 0)
2006-03-20 12:34:32 +01:00
{
2015-03-11 14:55:45 +01:00
if ($object->add_sousproduit($id, $_POST["prod_id_".$i], $_POST["prod_qty_".$i], $_POST["prod_incdec_".$i]) > 0)
2008-10-23 23:54:30 +02:00
{
2015-02-24 19:55:59 +01:00
//var_dump($id.' - '.$_POST["prod_id_".$i].' - '.$_POST["prod_qty_".$i]);exit;
2008-10-23 23:54:30 +02:00
$action = 'edit';
}
else
{
$error++;
2008-10-23 23:54:30 +02:00
$action = 're-edit';
2015-03-11 14:55:45 +01:00
if ($object->error == "isFatherOfThis") {
2015-12-12 10:59:02 +01:00
setEventMessages($langs->trans("ErrorAssociationIsFatherOfThis"), null, 'errors');
}
else
2015-12-12 10:59:02 +01:00
{
setEventMessages($object->error, $object->errors, 'errors');
}
2008-10-23 23:54:30 +02:00
}
}
else
{
2015-03-11 14:55:45 +01:00
if ($object->del_sousproduit($id, $_POST["prod_id_".$i]) > 0)
2008-10-23 23:54:30 +02:00
{
$action = 'edit';
}
else
{
$error++;
2008-10-23 23:54:30 +02:00
$action = 're-edit';
2015-12-12 10:59:02 +01:00
setEventMessages($object->error, $object->errors, 'errors');
2008-10-23 23:54:30 +02:00
}
}
}
if (! $error)
{
2015-03-11 14:55:45 +01:00
header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
2006-03-20 09:54:48 +01:00
}
2015-02-24 19:55:59 +01:00
else if($action==='save_composed_product')
{
$TProduct = GETPOST('TProduct', 'array');
if (!empty($TProduct))
2015-02-24 19:55:59 +01:00
{
foreach ($TProduct as $id_product => $row)
{
2015-03-11 14:55:45 +01:00
if ($row['qty'] > 0) $object->update_sousproduit($id, $id_product, $row['qty'], isset($row['incdec']) ? 1 : 0 );
else $object->del_sousproduit($id, $id_product);
}
setEventMessages('RecordSaved', null);
}
2015-02-24 19:55:59 +01:00
$action='';
}
/*
* View
*/
$product_fourn = new ProductFournisseur($db);
$productstatic = new Product($db);
$form = new Form($db);
2008-10-23 10:10:59 +02:00
// action recherche des produits par mot-cle et/ou par categorie
2011-10-05 23:49:05 +02:00
if ($action == 'search')
2006-03-20 09:54:48 +01:00
{
$current_lang = $langs->getDefaultLang();
2017-09-15 19:13:40 +02:00
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type as type, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
2014-11-15 11:59:02 +01:00
$sql.= ' p.fk_product_type, p.tms as datem';
2012-09-15 10:01:35 +02:00
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= ', pl.label as labelm, pl.description as descriptionm';
2006-03-20 09:54:48 +01:00
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product';
2012-09-15 10:01:35 +02:00
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND lang='".($current_lang)."'";
$sql.= ' WHERE p.entity IN ('.getEntity('product').')';
if ($key != "")
2006-03-20 09:54:48 +01:00
{
2014-11-15 11:59:02 +01:00
// For natural search
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
// multilang
2012-09-15 10:01:35 +02:00
if (! empty($conf->global->MAIN_MULTILANGS))
{
2014-11-15 11:59:02 +01:00
$params[] = 'pl.label';
$params[] = 'pl.description';
$params[] = 'pl.note';
}
2014-11-15 11:59:02 +01:00
if (! empty($conf->barcode->enabled)) {
$params[] = 'p.barcode';
}
2014-11-15 11:59:02 +01:00
$sql .= natural_search($params, $key);
2006-03-20 09:54:48 +01:00
}
2012-10-08 20:44:12 +02:00
if (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1)
2006-03-20 09:54:48 +01:00
{
2012-10-08 20:44:12 +02:00
$sql.= " AND cp.fk_categorie ='".$db->escape($parent)."'";
2006-03-20 09:54:48 +01:00
}
$sql.= " ORDER BY p.ref ASC";
$resql = $db->query($sql);
2006-03-20 09:54:48 +01:00
}
2008-10-23 10:10:59 +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('AssociatedProducts');
$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
}
if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
{
$title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('AssociatedProducts');
$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
}
2016-08-10 07:40:40 +02:00
llxHeader('', $title, $helpurl);
2006-03-20 09:54:48 +01:00
2015-04-07 03:00:11 +02:00
$head=product_prepare_head($object);
2015-03-11 14:55:45 +01:00
$titre=$langs->trans("CardProduct".$object->type);
$picto=($object->type==Product::TYPE_SERVICE?'service':'product');
dol_fiche_head($head, 'subproduct', $titre, -1, $picto);
2006-03-20 09:54:48 +01:00
if ($id > 0 || ! empty($ref))
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
/*
* Fiche en mode edition
*/
if ($user->rights->produit->lire || $user->rights->service->lire)
2008-10-23 23:54:30 +02:00
{
$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1;
if ($user->societe_id && ! in_array('product', explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0;
2017-09-26 10:58:24 +02:00
dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 0);
2016-10-24 20:56:48 +02:00
if ($object->type!=Product::TYPE_SERVICE || empty($conf->global->PRODUIT_MULTIPRICES))
{
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2017-06-12 18:22:51 +02:00
print '<table class="border tableforfield" width="100%">';
// Nature
if ($object->type!=Product::TYPE_SERVICE)
{
2017-09-15 19:13:40 +02:00
print '<tr><td class="titlefield">'.$langs->trans("Nature").'</td><td>';
print $object->getLibFinished();
print '</td></tr>';
}
2017-06-12 18:22:51 +02:00
if (empty($conf->global->PRODUIT_MULTIPRICES))
{
// Price
2017-09-15 19:13:40 +02:00
print '<tr><td class="titlefield">'.$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?$object->price_base_type:'HT');
}
print '</td></tr>';
2017-06-12 18:22:51 +02:00
// 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?$object->price_base_type:'HT');
}
print '</td></tr>';
}
print '</table>';
print '</div>';
2016-10-24 20:56:48 +02:00
}
2015-03-11 14:55:45 +01:00
dol_fiche_end();
2016-09-18 13:58:17 +02:00
print '<br>';
2015-03-11 14:55:45 +01:00
$prodsfather = $object->getFather(); // Parent Products
$object->get_sousproduits_arbo(); // Load $object->sousprods
$prods_arbo=$object->get_arbo_each_prod();
2015-03-11 14:55:45 +01:00
$nbofsubsubproducts=count($prods_arbo); // This include sub sub product into nb
$prodschild = $object->getChildsArbo($id,1);
$nbofsubproducts=count($prodschild); // This include only first level of childs
// Number of parent virtual products
2015-05-03 21:15:08 +02:00
//print $form->textwithpicto($langs->trans("ParentProductsNumber").': '.count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct'));
2015-03-11 14:55:45 +01:00
2015-05-03 21:15:08 +02:00
//if (count($prodsfather) > 0)
//{
print load_fiche_titre($langs->trans("ProductParentList"),'','');
2015-05-03 21:15:08 +02:00
print '<table class="centpercent noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('ParentProducts').'</td>';
2015-05-03 21:15:08 +02:00
print '<td>'.$langs->trans('Label').'</td>';
print '<td>'.$langs->trans('Qty').'</td>';
print '</td>';
if (count($prodsfather) > 0)
{
$class='pair';
foreach($prodsfather as $value)
{
$idprod= $value["id"];
$productstatic->id=$idprod;// $value["id"];
$productstatic->type=$value["fk_product_type"];
$productstatic->ref=$value['ref'];
$productstatic->label=$value['label'];
2015-10-29 12:28:28 +01:00
$productstatic->entity=$value['entity'];
2015-05-03 21:15:08 +02:00
$class=($class=='impair')?'pair':'impair';
print '<tr class="'.$class.'">';
print '<td>'.$productstatic->getNomUrl(1,'composition').'</td>';
print '<td>'.$productstatic->label.'</td>';
print '<td>'.$value['qty'].'</td>';
print '</tr>';
}
}
else
2015-03-11 14:55:45 +01:00
{
2015-06-19 06:06:46 +02:00
print '<tr class="impair">';
print '<td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td>';
2015-03-11 14:55:45 +01:00
print '</tr>';
}
print '</table>';
2015-05-03 21:15:08 +02:00
//}
2015-03-11 14:55:45 +01:00
print '<br>'."\n";
// Number of subproducts
2015-05-03 21:15:08 +02:00
//print $form->textwithpicto($langs->trans("AssociatedProductsNumber").': '.(empty($conf->global->PRODUCT_SHOW_SUB_SUB_PRODUCTS)?$nbofsubproducts:$nbofsubsubproducts), $langs->trans('IfZeroItIsNotAVirtualProduct'));
// List of subproducts
2015-05-03 21:15:08 +02:00
//if (count($prods_arbo) > 0)
//{
$atleastonenotdefined=0;
print load_fiche_titre($langs->trans("ProductAssociationList"),'','');
2015-02-24 19:55:59 +01:00
print '<form name="formComposedProduct" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="action" value="save_composed_product" />';
print '<input type="hidden" name="id" value="'.$id.'" />';
2015-02-24 19:55:59 +01:00
2015-03-11 14:55:45 +01:00
print '<table class="centpercent noborder">';
2015-02-24 19:55:59 +01:00
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('ComposedProduct').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
print '<td align="right" colspan="2">'.$langs->trans('MinSupplierPrice').'</td>';
print '<td align="right" colspan="2">'.$langs->trans('MinCustomerPrice').'</td>';
2015-02-24 19:55:59 +01:00
if (! empty($conf->stock->enabled)) print '<td align="right">'.$langs->trans('Stock').'</td>';
print '<td align="center">'.$langs->trans('Qty').'</td>';
2015-02-25 23:04:13 +01:00
print '<td align="center">'.$langs->trans('ComposedProductIncDecStock').'</td>';
2015-03-11 14:55:45 +01:00
print '</tr>'."\n";
2015-02-24 19:55:59 +01:00
2015-05-03 21:15:08 +02:00
$class='pair';
2018-06-22 15:51:26 +02:00
$totalsell=0;
2015-05-22 00:46:53 +02:00
if (count($prods_arbo))
{
2015-05-22 00:46:53 +02:00
foreach($prods_arbo as $value)
{
$productstatic->fetch($value['id']);
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
if ($value['level'] <= 1)
{
2015-05-22 00:46:53 +02:00
$class=($class=='impair')?'pair':'impair';
print '<tr class="'.$class.'">';
$notdefined=0;
$nb_of_subproduct = $value['nb'];
print '<td>'.$productstatic->getNomUrl(1,'composition').'</td>';
print '<td>'.$productstatic->label.'</td>';
// Best buying price
print '<td align="right">';
if ($product_fourn->find_min_price_product_fournisseur($productstatic->id) > 0)
{
print $langs->trans("BuyingPriceMinShort").': ';
2015-05-22 00:46:53 +02:00
if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(0,0);
else { print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++; }
}
print '</td>';
// For avoid a non-numeric value
$fourn_unitprice = (!empty($product_fourn->fourn_unitprice)?$product_fourn->fourn_unitprice:0);
$fourn_remise_percent = (!empty($product_fourn->fourn_remise_percent)?$product_fourn->fourn_remise_percent:0);
$fourn_remise = (!empty($product_fourn->fourn_remise)?$product_fourn->fourn_remise:0);
2018-06-22 15:51:26 +02:00
$totalline=price2num($value['nb'] * ($fourn_unitprice * (1 - $fourn_remise_percent/100) - $fourn_remise), 'MT');
2015-05-22 00:46:53 +02:00
$total+=$totalline;
2015-05-22 00:46:53 +02:00
print '<td align="right">';
print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : '').price($fourn_unitprice,'','',0,0,-1,$conf->currency));
2015-05-22 00:46:53 +02:00
print '</td>';
// Best selling price
$pricesell=$productstatic->price;
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
2018-06-22 15:51:26 +02:00
$pricesell='Variable';
}
else
{
$totallinesell=price2num($value['nb'] * ($pricesell), 'MT');
$totalsell+=$totallinesell;
}
print '<td align="right" colspan="2">';
2018-06-23 17:11:19 +02:00
print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : ''));
2018-06-23 12:57:41 +02:00
if (is_numeric($pricesell)) print price($pricesell,'','',0,0,-1,$conf->currency);
2018-06-22 15:51:26 +02:00
else print $langs->trans($pricesell);
print '</td>';
2015-05-22 00:46:53 +02:00
// Stock
if (! empty($conf->stock->enabled)) print '<td align="right">'.$value['stock'].'</td>'; // Real stock
// Qty + IncDec
if ($user->rights->produit->creer || $user->rights->service->creer)
{
print '<td align="center"><input type="text" value="'.$nb_of_subproduct.'" name="TProduct['.$productstatic->id.'][qty]" size="4" /></td>';
print '<td align="center"><input type="checkbox" name="TProduct['.$productstatic->id.'][incdec]" value="1" '.($value['incdec']==1?'checked':'' ).' /></td>';
}
else{
print '<td>'.$nb_of_subproduct.'</td>';
print '<td>'.($value['incdec']==1?'x':'' ).'</td>';
}
print '</tr>'."\n";
}
else
2015-05-22 00:46:53 +02:00
{
$hide='';
if (empty($conf->global->PRODUCT_SHOW_SUB_SUB_PRODUCTS)) $hide=' hideobject'; // By default, we do not show this. It makes screen very difficult to understand
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
$class=($class=='impair')?'pair':'impair';
print '<tr class="'.$class.$hide.'" id="sub-'.$value['id_parent'].'">';
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
//$productstatic->ref=$value['label'];
$productstatic->ref=$value['ref'];
print '<td>';
for ($i=0; $i < $value['level']; $i++) print ' &nbsp; &nbsp; '; // Add indentation
print $productstatic->getNomUrl(1,'composition').'</td>';
print '<td>'.$productstatic->label.'</td>';
2015-02-24 19:55:59 +01:00
// Best buying price
2015-05-22 00:46:53 +02:00
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
// Best selling price
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
2015-05-22 00:46:53 +02:00
if (! empty($conf->stock->enabled)) print '<td></td>'; // Real stock
print '<td align="center">'.$value['nb'].'</td>';
print '<td>&nbsp;</td>';
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '</tr>'."\n";
}
2015-02-24 19:55:59 +01:00
}
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '<tr class="liste_total">';
print '<td class="liste_total"></td>';
print '<td class="liste_total"></td>';
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
// Minimum buying price
print '<td class="liste_total" align="right">';
print $langs->trans("TotalBuyingPriceMinShort");
2015-05-22 00:46:53 +02:00
print '</td>';
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
print '<td class="liste_total" align="right">';
if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')';
print ($atleastonenotdefined?'':price($total,'','',0,0,-1,$conf->currency));
print '</td>';
2015-02-24 19:55:59 +01:00
// Minimum selling price
print '<td class="liste_total" align="right">';
print $langs->trans("TotalSellingPriceMinShort");
print '</td>';
print '<td class="liste_total" align="right">';
if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')';
print ($atleastonenotdefined?'':price($totalsell,'','',0,0,-1,$conf->currency));
print '</td>';
2015-05-22 00:46:53 +02:00
// Stock
if (! empty($conf->stock->enabled)) print '<td class="liste_total" align="right">&nbsp;</td>';
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '<td align="right" colspan="2">';
if ($user->rights->produit->creer || $user->rights->service->creer)
{
print '<input type="submit" class="button" value="'.$langs->trans('Save').'">';
}
2015-05-22 00:46:53 +02:00
print '</td>';
print '</tr>'."\n";
}
2015-05-22 00:46:53 +02:00
else
2015-02-24 19:55:59 +01:00
{
2018-02-28 15:29:52 +01:00
$colspan=8;
2015-05-22 00:46:53 +02:00
if (! empty($conf->stock->enabled)) $colspan++;
2015-06-19 00:36:03 +02:00
print '<tr class="impair">';
print '<td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td>';
2015-05-22 00:46:53 +02:00
print '</tr>';
2015-02-24 19:55:59 +01:00
}
2015-05-22 00:46:53 +02:00
print '</table>';
2015-02-24 19:55:59 +01:00
/*if($user->rights->produit->creer || $user->rights->service->creer) {
print '<input type="submit" class="button" value="'.$langs->trans('Save').'">';
}*/
print '</form>';
2015-05-03 21:15:08 +02:00
//}
2011-08-31 16:55:54 +02:00
// Form with product to add
if ((empty($action) || $action == 'view' || $action == 'edit' || $action == 'search' || $action == 're-edit') && ($user->rights->produit->creer || $user->rights->service->creer))
{
print '<br>';
2011-09-07 21:09:21 +02:00
$rowspan=1;
if (! empty($conf->categorie->enabled)) $rowspan++;
2011-09-07 21:09:21 +02:00
print load_fiche_titre($langs->trans("ProductToAddSearch"),'','');
print '<form action="'.DOL_URL_ROOT.'/product/composition/card.php?id='.$id.'" method="POST">';
print '<input type="hidden" name="action" value="search">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<div class="inline-block">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print $langs->trans("KeywordFilter").': ';
print '<input type="text" name="key" value="'.$key.'"> &nbsp; ';
print '</div>';
if (! empty($conf->categorie->enabled))
{
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
print '<div class="inline-block">'.$langs->trans("CategoryFilter").': ';
print $form->select_all_categories(Categorie::TYPE_PRODUCT, $parent, 'parent').' &nbsp; </div>';
print ajax_combobox('parent');
}
print '<div class="inline-block">';
print '<input type="submit" class="button" value="'.$langs->trans("Search").'">';
print '</div>';
print '</form>';
2008-10-23 23:54:30 +02:00
}
// List of products
2011-10-05 23:49:05 +02:00
if ($action == 'search')
2008-10-23 23:54:30 +02:00
{
print '<br>';
print '<form action="'.DOL_URL_ROOT.'/product/composition/card.php?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add_prod">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
2015-02-24 19:55:59 +01:00
print '<th class="liste_titre">'.$langs->trans("ComposedProduct").'</td>';
2011-09-07 21:09:21 +02:00
print '<th class="liste_titre">'.$langs->trans("Label").'</td>';
2015-02-24 19:55:59 +01:00
//print '<th class="liste_titre" align="center">'.$langs->trans("IsInPackage").'</td>';
print '<th class="liste_titre" align="right">'.$langs->trans("Qty").'</td>';
2015-02-25 23:04:13 +01:00
print '<th align="center">'.$langs->trans('ComposedProductIncDecStock').'</th>';
print '</tr>';
2008-10-23 23:54:30 +02:00
if ($resql)
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
$num = $db->num_rows($resql);
$i=0;
if($num == 0) print '<tr><td colspan="4">'.$langs->trans("NoMatchFound").'</td></tr>';
2008-10-23 23:54:30 +02:00
while ($i < $num)
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
$objp = $db->fetch_object($resql);
if($objp->rowid != $id)
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
// check if a product is not already a parent product of this one
$prod_arbo=new Product($db);
$prod_arbo->id=$objp->rowid;
2017-09-15 19:08:39 +02:00
// This type is not supported (not required to have virtual products working).
if ($prod_arbo->type == Product::TYPE_ASSEMBLYKIT || $prod_arbo->type == Product::TYPE_STOCKKIT)
2006-03-21 10:06:33 +01:00
{
2008-10-23 23:54:30 +02:00
$is_pere=0;
2011-10-05 23:49:05 +02:00
$prod_arbo->get_sousproduits_arbo();
2008-10-23 23:54:30 +02:00
// associations sousproduits
$prods_arbo = $prod_arbo->get_arbo_each_prod();
2011-09-17 21:49:50 +02:00
if (count($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
if ($value[1]==$id)
{
2008-10-23 23:54:30 +02:00
$is_pere=1;
}
}
2006-03-21 12:46:39 +01:00
}
2011-10-05 23:49:05 +02:00
if ($is_pere==1)
{
2008-10-23 23:54:30 +02:00
$i++;
continue;
2006-03-21 12:46:39 +01:00
}
2006-03-21 10:06:33 +01:00
}
2017-06-12 18:22:51 +02:00
2017-09-15 19:13:40 +02:00
print "\n".'<tr class="oddeven">';
$productstatic->id=$objp->rowid;
$productstatic->ref=$objp->ref;
$productstatic->label=$objp->label;
$productstatic->type=$objp->type;
2015-10-29 12:28:28 +01:00
$productstatic->entity=$objp->entity;
print '<td>'.$productstatic->getNomUrl(1,'',24).'</td>';
$labeltoshow=$objp->label;
if ($conf->global->MAIN_MULTILANGS && $objp->labelm) $labeltoshow=$objp->labelm;
print '<td>'.$labeltoshow.'</td>';
2015-02-24 19:55:59 +01:00
2015-03-11 14:55:45 +01:00
if($object->is_sousproduit($id, $objp->rowid))
2008-10-23 23:54:30 +02:00
{
//$addchecked = ' checked';
2015-03-11 14:55:45 +01:00
$qty=$object->is_sousproduit_qty;
$incdec=$object->is_sousproduit_incdec;
2008-10-23 23:54:30 +02:00
}
else
{
2015-02-24 19:55:59 +01:00
//$addchecked = '';
$qty=0;
$incdec=0;
2008-10-23 23:54:30 +02:00
}
2015-02-24 19:55:59 +01:00
// Contained into package
/*print '<td align="center"><input type="hidden" name="prod_id_'.$i.'" value="'.$objp->rowid.'">';
print '<input type="checkbox" '.$addchecked.'name="prod_id_chk'.$i.'" value="'.$objp->rowid.'"></td>';*/
// Qty
print '<td align="right"><input type="hidden" name="prod_id_'.$i.'" value="'.$objp->rowid.'"><input type="text" size="2" name="prod_qty_'.$i.'" value="'.($qty?$qty:'').'"></td>';
// Inc Dec
print '<td align="center">';
if ($qty) print '<input type="checkbox" name="prod_incdec_'.$i.'" value="1" '.($incdec?'checked':'').'>';
2015-02-24 19:55:59 +01:00
else
{
// TODO Hide field and show it when setting a qty
print '<input type="checkbox" name="prod_incdec_'.$i.'" value="1" checked>';
//print '<input type="checkbox" disabled name="prod_incdec_'.$i.'" value="1" checked>';
2015-02-24 19:55:59 +01:00
}
print '</td>';
2008-10-23 23:54:30 +02:00
print '</tr>';
}
$i++;
2006-03-20 09:54:48 +01:00
}
2008-10-23 23:54:30 +02:00
}
else
{
dol_print_error($db);
2006-03-20 09:54:48 +01:00
}
2008-10-23 23:54:30 +02:00
print '</table>';
print '<input type="hidden" name="max_prod" value="'.$i.'">';
2011-08-10 13:53:25 +02:00
if($num > 0)
{
2014-11-25 20:13:43 +01:00
print '<br><div class="center">';
2015-02-24 19:55:59 +01:00
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'">';
2014-11-25 20:13:43 +01:00
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
2015-02-24 19:55:59 +01:00
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
2014-11-25 20:13:43 +01:00
print '</div>';
}
print '</form>';
2008-10-23 23:54:30 +02:00
}
}
2006-03-20 09:54:48 +01:00
}
2018-08-14 09:55:58 +02:00
// End of page
2011-10-05 23:49:05 +02:00
llxFooter();
2006-03-20 09:54:48 +01:00
$db->close();