* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Simon Tosser * Copyright (C) 2005-2014 Regis Houssin * * 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 * along with this program. If not, see . */ /** * \file htdocs/product/stock/card.php * \ingroup stock * \brief Page fiche entrepot */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; $langs->load("products"); $langs->load("stocks"); $langs->load("companies"); $action=GETPOST('action'); $cancel=GETPOST('cancel'); $confirm=GETPOST('confirm'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $id = GETPOST("id",'int'); if (! $sortfield) $sortfield="p.ref"; if (! $sortorder) $sortorder="DESC"; $backtopage=GETPOST("backtopage"); // Security check $result=restrictedArea($user,'stock'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('warehousecard','globalcard')); /* * Actions */ // Ajout entrepot if ($action == 'add' && $user->rights->stock->creer) { $object = new Entrepot($db); $object->ref = GETPOST("ref"); $object->libelle = GETPOST("libelle"); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); $object->lieu = GETPOST("lieu"); $object->address = GETPOST("address"); $object->zip = GETPOST("zipcode"); $object->town = GETPOST("town"); $object->country_id = GETPOST("country_id"); if (! empty($object->libelle)) { $id = $object->create($user); if ($id > 0) { setEventMessage($langs->trans("RecordSaved")); if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } else { header("Location: card.php?id=".$id); exit; } } else { $action = 'create'; setEventMessage($object->error, 'errors'); } } else { setEventMessage($langs->trans("ErrorWarehouseRefRequired"), 'errors'); $action="create"; // Force retour sur page creation } } // Delete warehouse if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) { $object = new Entrepot($db); $object->fetch($_REQUEST["id"]); $result=$object->delete($user); if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/product/stock/list.php'); exit; } else { setEventMessage($object->error, 'errors'); $action=''; } } // Modification entrepot if ($action == 'update' && $cancel <> $langs->trans("Cancel")) { $object = new Entrepot($db); if ($object->fetch($id)) { $object->libelle = GETPOST("libelle"); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); $object->lieu = GETPOST("lieu"); $object->address = GETPOST("address"); $object->zip = GETPOST("zipcode"); $object->town = GETPOST("town"); $object->country_id = GETPOST("country_id"); if ( $object->update($id, $user) > 0) { $action = ''; } else { $action = 'edit'; setEventMessage($object->error, 'errors'); } } else { $action = 'edit'; setEventMessage($object->error, 'errors'); } } if ($cancel == $langs->trans("Cancel")) { $action = ''; } /* * View */ $productstatic=new Product($db); $form=new Form($db); $formcompany=new FormCompany($db); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("",$langs->trans("WarehouseCard"),$help_url); if ($action == 'create') { print_fiche_titre($langs->trans("NewWarehouse")); print "
\n"; print ''; print ''; print ''; dol_fiche_head(); print ''; // Ref print ''; print ''; // Description print ''; print ''; // Zip / Town print ''; // Country print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; // Editeur wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('desc',(!empty($object->description)?$object->description:''),'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); $doleditor->Create(); print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown((!empty($object->zip)?$object->zip:''),'zipcode',array('town','selectcountry_id','state_id'),6); print ''.$langs->trans('Town').''; print $formcompany->select_ziptown((!empty($object->town)?$object->town:''),'town',array('zipcode','selectcountry_id','state_id')); print '
'.$langs->trans('Country').''; print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans("Status").''; print ''; print '
'; dol_fiche_end(); print '
'; print '
'; } else { $id=GETPOST("id",'int'); if ($id) { $object = new Entrepot($db); $result = $object->fetch($id); if ($result < 0) { dol_print_error($db); } /* * Affichage fiche */ if ($action <> 'edit' && $action <> 're-edit') { $head = stock_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); // Confirm delete third party if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$object->libelle),"confirm_delete",'',0,2); } print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; print ''; // Description print ''; // Address print ''; // Town print ''; print ''; // Country print ''; // Status print ''; $calcproductsunique=$object->nb_different_products(); $calcproducts=$object->nb_products(); // Total nb of different products print '"; // Nb of products print '"; // Value print '"; // Last movement $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " WHERE m.fk_entrepot = '".$object->id."'"; $resqlbis = $db->query($sql); if ($resqlbis) { $obj = $db->fetch_object($resqlbis); $lastmovementdate=$db->jdate($obj->datem); } else { dol_print_error($db); } print '"; print "
'.$langs->trans("Ref").''; print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'libelle'); print '
'.$langs->trans("LocationSummary").''.$object->lieu.'
'.$langs->trans("Description").''.nl2br($object->description).'
'.$langs->trans('Address').''; print $object->address; print '
'.$langs->trans('Zip').''.$object->zip.''.$langs->trans('Town').''.$object->town.'
'.$langs->trans('Country').''; if (! empty($object->country_code)) { $img=picto_from_langcode($object->country_code); print ($img?$img.' ':''); } print $object->country; print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("NumberOfDifferentProducts").''; print empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']; print "
'.$langs->trans("NumberOfProducts").''; print empty($calcproducts['nb'])?'0':$calcproducts['nb']; print "
'.$langs->trans("EstimatedStockValueShort").''; print price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency); print "
'.$langs->trans("LastMovement").''; if ($lastmovementdate) { print dol_print_date($lastmovementdate,'dayhour').' '; print '('.$langs->trans("FullList").')'; } else { print $langs->trans("None"); } print "
"; print ''; /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "
\n"; $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { if (empty($action)) { if ($user->rights->stock->creer) print "id."\">".$langs->trans("Modify").""; else print "".$langs->trans("Modify").""; if ($user->rights->stock->supprimer) print "id."\">".$langs->trans("Delete").""; else print "".$langs->trans("Delete").""; } } print "
"; /* ************************************************************************** */ /* */ /* Affichage de la liste des produits de l'entrepot */ /* */ /* ************************************************************************** */ print '
'; print ''; print ""; print_liste_field_titre($langs->trans("Product"),"", "p.ref","&id=".$id,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),"", "p.label","&id=".$id,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&id=".$id,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AverageUnitPricePMPShort"),"", "ps.pmp","&id=".$id,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("EstimatedStockValueShort"),"", "","&id=".$id,"",'align="right"',$sortfield,$sortorder); if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellPriceMin"),"", "p.price","&id=".$id,"",'align="right"',$sortfield,$sortorder); if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("EstimatedStockValueSellShort"),"", "","&id=".$id,"",'align="right"',$sortfield,$sortorder); if ($user->rights->stock->mouvement->creer) print_liste_field_titre(''); if ($user->rights->stock->creer) print_liste_field_titre(''); print "\n"; $totalunit=0; $totalvalue=$totalvaluesell=0; $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc,"; $sql.= " ps.pmp, ps.reel as value"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p"; $sql.= " WHERE ps.fk_product = p.rowid"; $sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse) $sql.= " AND ps.fk_entrepot = ".$object->id; $sql.= $db->order($sortfield,$sortorder); dol_syslog('List products', LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); // Multilangs if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { $sql = "SELECT label"; $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; $sql.= " WHERE fk_product=".$objp->rowid; $sql.= " AND lang='". $langs->getDefaultLang() ."'"; $sql.= " LIMIT 1"; $result = $db->query($sql); if ($result) { $objtp = $db->fetch_object($result); if ($objtp->label != '') $objp->produit = $objtp->label; } } $var=!$var; //print ''; print ""; print "'; print ''; print ''; $totalunit+=$objp->value; // Price buy PMP print ''; // Total PMP print ''; $totalvalue+=price2num($objp->ppmp*$objp->value,'MT'); // Price sell min if (empty($conf->global->PRODUIT_MULTIPRICES)) { $pricemin=$objp->price; print ''; // Total sell min print ''; } $totalvaluesell+=price2num($pricemin*$objp->value,'MT'); if ($user->rights->stock->mouvement->creer) { print '"; } if ($user->rights->stock->creer) { print '"; } print ""; $i++; } $db->free($resql); print ''; print ''; print ''; print ''; if (empty($conf->global->PRODUIT_MULTIPRICES)) { print ''; print ''; } print ''; print ''; print ''; } else { dol_print_error($db); } print "
'.dol_print_date($objp->datem).'
"; $productstatic->id=$objp->rowid; $productstatic->ref = $objp->ref; $productstatic->label = $objp->produit; $productstatic->type=$objp->type; print $productstatic->getNomUrl(1,'stock',16); print ''.$objp->produit.''.$objp->value.''.price(price2num($objp->ppmp,'MU')).''.price(price2num($objp->ppmp*$objp->value,'MT')).''; print price(price2num($pricemin,'MU'),1); print ''; print price(price2num($pricemin*$objp->value,'MT'),1); print ''; print img_picto($langs->trans("StockMovement"),'uparrow.png','class="hideonsmartphone"').' '.$langs->trans("StockMovement"); print "'; print $langs->trans("StockCorrection"); print "
'.$langs->trans("Total").''.$totalunit.' '.price(price2num($totalvalue,'MT')).' '.price(price2num($totalvaluesell,'MT')).'  
\n"; } /* * Edition fiche */ if (($action == 'edit' || $action == 're-edit') && 1) { $langs->trans("WarehouseEdit"); print '
'; print ''; print ''; print ''; $head = stock_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); print ''; // Ref print ''; print ''; // Description print ''; print ''; // Zip / Town print ''; // Country print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; // Editeur wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('desc',$object->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); $doleditor->Create(); print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'),6); print ''.$langs->trans('Town').''; print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id')); print '
'.$langs->trans('Country').''; print $form->select_country($object->country_id?$object->country_id:$mysoc->country_code,'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans("Status").''; print ''; print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } } } llxFooter(); $db->close();