Move new feature inventory into module stock.

This commit is contained in:
Laurent Destailleur
2017-04-30 02:15:13 +02:00
parent 92b5f8d85e
commit 4993a43025
11 changed files with 450 additions and 367 deletions

View File

@@ -32,7 +32,7 @@ class CoreObject extends CommonObject
/**
* @var Array $_fields Fields to synchronize with Database
*/
protected $__fields=array();
protected $fields=array();
/**
* Constructor
@@ -55,9 +55,9 @@ class CoreObject extends CommonObject
$this->datec = 0;
$this->tms = 0;
if (!empty($this->__fields))
if (!empty($this->fields))
{
foreach ($this->__fields as $field=>$info)
foreach ($this->fields as $field=>$info)
{
if ($this->is_date($info)) $this->{$field} = time();
elseif ($this->is_array($info)) $this->{$field} = array();
@@ -87,9 +87,9 @@ class CoreObject extends CommonObject
*/
private function checkFieldType($field, $type)
{
if (isset($this->__fields[$field]) && method_exists($this, 'is_'.$type))
if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type))
{
return $this->{'is_'.$type}($this->__fields[$field]);
return $this->{'is_'.$type}($this->fields[$field]);
}
else
{
@@ -214,7 +214,7 @@ class CoreObject extends CommonObject
private function set_save_query()
{
$query=array();
foreach ($this->__fields as $field=>$info)
foreach ($this->fields as $field=>$info)
{
if($this->is_date($info))
{
@@ -260,7 +260,7 @@ class CoreObject extends CommonObject
*/
private function get_field_list()
{
$keys = array_keys($this->__fields);
$keys = array_keys($this->fields);
return implode(',', $keys);
}
@@ -272,7 +272,7 @@ class CoreObject extends CommonObject
*/
private function set_vars_by_db(&$obj)
{
foreach ($this->__fields as $field => $info)
foreach ($this->fields as $field => $info)
{
if($this->is_date($info))
{

View File

@@ -294,15 +294,27 @@ class Listview
*/
public function render($sql, $TParam=array())
{
global $conf;
$TField=array();
$this->init($TParam);
$THeader = $this->initHeader($TParam);
$sql = $this->search($sql,$TParam);
$sql = $this->order_by($sql, $TParam);
$sql.= $this->db->order($TParam['param']['sortfield'], $TParam['param']['sortorder']);
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $this->db->query($sql);
$nbtotalofrecords = $this->db->num_rows($result);
}
$sql.= $this->db->plimit($TParam['param']['limit'] + 1, $TParam['param']['offset']);
$this->parse_sql($THeader, $TField, $TParam, $sql);
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
return $this->renderList($THeader, $TField, $TTotal, $TTotalGroup, $TParam);
@@ -468,6 +480,7 @@ class Listview
/**
* @return string
*/
/*
private function getJS()
{
$javaScript = '<script language="javascript">
@@ -479,6 +492,7 @@ class Listview
return $javaScript;
}
*/
/**
* @param $TParam
@@ -595,7 +609,7 @@ class Listview
$TExport = $this->setExport($TParam, $TField, $THeader);
$TField = $this->addTotalGroup($TField,$TTotalGroup);
$out = $this->getJS();
//$out = $this->getJS();
$dolibarr_decalage = $this->totalRow > $this->totalRowToShow ? 1 : 0;
ob_start();
@@ -605,6 +619,26 @@ class Listview
$out.= '<table id="'.$this->id.'" class="liste" width="100%"><thead>';
if(count($TSearch)>0)
{
$out.='<tr class="liste_titre liste_titre_search barre-recherche">';
foreach ($THeader as $field => $head)
{
if ($field === 'selectedfields')
{
$out.= '<td class="liste_titre" align="right">'.$this->form->showFilterAndCheckAddButtons(0).'</td>';
}
else
{
$moreattrib = 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"';
$out .= '<td class="liste_titre" '.$moreattrib.'>'.$TSearch[$field].'</td>';
}
}
$out.='</tr>';
}
$out.= '<tr class="liste_titre">';
foreach($THeader as $field => $head)
{
@@ -635,31 +669,11 @@ class Listview
//$out .= '<th aligne="right" class="maxwidthsearch liste_titre">--</th>';
$out .= '</tr>';
if(count($TSearch)>0)
{
$out.='<tr class="liste_titre barre-recherche">';
foreach ($THeader as $field => $head)
{
if ($field === 'selectedfields')
{
$out.= '<td class="liste_titre" align="right">'.$this->form->showFilterAndCheckAddButtons(0).'</td>';
}
else
{
$moreattrib = 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"';
$out .= '<td class="liste_titre" '.$moreattrib.'>'.$TSearch[$field].'</td>';
}
}
$out.='</tr>';
}
$out.='</thead><tbody>';
if(empty($TField))
{
if (!empty($TParam['list']['messageNothing'])) $out .= '<tr class="pair" align="center"><td colspan="'.(count($TParam['title'])+1).'">'.$TParam['list']['messageNothing'].'</td></tr>';
if (!empty($TParam['list']['messageNothing'])) $out .= '<tr class="oddeven"><td colspan="'.(count($TParam['title'])+1).'"><span class="opacitymedium">'.$TParam['list']['messageNothing'].'</span></td></tr>';
}
else
{
@@ -729,27 +743,6 @@ class Listview
}
/**
* @param $sql
* @param $TParam
* @return string
*/
private function order_by($sql, &$TParam)
{
global $db;
if (!empty($TParam['sortfield']))
{
if(strpos($sql,'LIMIT ') !== false) list($sql, $sqlLIMIT) = explode('LIMIT ', $sql);
$sql .= $db->order($TParam['sortfield'], $TParam['sortorder']);
if (!empty($sqlLIMIT)) $sql .= ' LIMIT '.$sqlLIMIT;
}
return $sql;
}
/**
* @param $THeader
* @param $TField

View File

@@ -1,3 +1,23 @@
// Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
//
// 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 <http://www.gnu.org/licenses/>.
// or see http://www.gnu.org/
//
// \file htdocs/core/js/listview.js
// \brief File that include javascript functions for lists
//
var Listview_include = true;
function Listview_OrderDown(idListe, column) {

View File

@@ -1253,6 +1253,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
}
// Inventory
if ($conf->global->MAIN_LEVEL_FEATURES >= 2)
{
if (! empty($conf->stock->enabled))
{
$langs->load("stocks");
@@ -1260,6 +1262,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/product/inventory/card.php?action=create", $langs->trans("NewInventory"), 1, $user->rights->stock->creer);
$newmenu->add("/product/inventory/list.php", $langs->trans("List"), 1, $user->rights->stock->lire);
}
}
// Expeditions
if (! empty($conf->expedition->enabled))

View File

@@ -146,9 +146,7 @@ ProductStockWarehouseUpdated=Stock limit for alert and desired optimal stock cor
ProductStockWarehouseDeleted=Stock limit for alert and desired optimal stock correctly deleted
AddNewProductStockWarehouse=Set new limit for alert and desired optimal stock
AddStockLocationLine=Decrease quantity then click to add another warehouse for this product
Module104420Name = Inventory
Module104420Desc = Create and manage your inventory
InventoryDate=Inventory date
NewInventory=New inventory
inventorySetup = Inventory Setup
inventoryCreatePermission=Create new inventory

View File

@@ -109,9 +109,9 @@ if (empty($reshook))
}
// Action to add record
if ($action == 'add')
if ($action == 'add' && ! empty($user->rights->mymodule->create))
{
if (GETPOST('cancel'))
if ($cancel)
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
header("Location: ".$urltogo);
@@ -154,7 +154,7 @@ if (empty($reshook))
}
// Action to update record
if ($action == 'update')
if ($action == 'update' && ! empty($user->rights->mymodule->create))
{
$error=0;
@@ -189,7 +189,7 @@ if (empty($reshook))
}
// Action to delete
if ($action == 'confirm_delete')
if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete))
{
$result=$object->delete($user);
if ($result > 0)
@@ -216,10 +216,10 @@ if (empty($reshook))
* Put here all code to build page
****************************************************/
llxHeader('','MyPageName','');
$form=new Form($db);
llxHeader('','MyPageName','');
// Put here content of your page

View File

@@ -1,7 +1,7 @@
<?php
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/inventory/class/inventory.class.php';
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
$get = GETPOST('get');
$put = GETPOST('put');

View File

@@ -32,116 +32,147 @@ include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$langs->load('stock');
$langs->load('inventory');
if(empty($user->rights->stock->read)) accessforbidden();
$id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha');
$action=(GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
$cancel=GETPOST('cancel');
$confirm=GETPOST('confirm','alpha');
$socid=GETPOST('socid','int');
if (! empty($user->societe_id)) $socid=$user->societe_id;
_action();
if (empty($action) && empty($id) && empty($ref)) $action='view';
function _action()
// Protection if external user
if ($user->societe_id > 0)
{
global $user, $db, $conf, $langs;
//accessforbidden();
}
$result = restrictedArea($user, 'stock', $id);
/*******************************************************************
* ACTIONS
*
* Put here all code to do according to value of "action" parameter
********************************************************************/
$action=GETPOST('action');
$object = new Inventory($db);
$extrafields = new ExtraFields($db);
switch($action) {
case 'create':
if (empty($user->rights->stock->create)) accessforbidden();
// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$inventory = new Inventory($db);
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
card_warehouse( $inventory);
// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('inventory'));
break;
case 'confirmCreate':
if (empty($user->rights->stock->create)) accessforbidden();
$inventory = new Inventory($db);
$inventory->setValues($_POST);
/*
* Actions
*/
$fk_inventory = $inventory->create($user);
if($fk_inventory>0) {
$parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
$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');
if (empty($reshook))
{
if ($cancel)
{
if ($action != 'addlink')
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
header("Location: ".$urltogo);
exit;
}
if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref);
$action='';
}
if ($action == 'confirmCreate')
{
if (empty($user->rights->stock->creer)) accessforbidden();
if ($cancel)
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
header("Location: ".$urltogo);
exit;
}
$error=0;
$object->setValues($_POST);
$fk_inventory = $object->create($user);
if ($fk_inventory>0)
{
$fk_category = (int) GETPOST('fk_category');
$fk_supplier = (int) GETPOST('fk_supplier');
$fk_warehouse = (int) GETPOST('fk_warehouse');
$only_prods_in_stock = (int) GETPOST('OnlyProdsInStock');
$inventory->addProductsFor($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
$inventory->update($user);
header('Location: '.dol_buildpath('/product/inventory/card.php?id='.$inventory->id.'&action=edit', 1));
$object->addProductsFor($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
$object->update($user);
header('Location: '.dol_buildpath('/product/inventory/card.php?id='.$object->id.'&action=edit', 1));
exit;
}
else{
setEventMessage($inventory->error,'errors');
else
{
setEventMessage($object->error,'errors');
header('Location: '.dol_buildpath('/product/inventory/card.php?action=create', 1));
exit;
}
break;
}
case 'edit':
if (!$user->rights->stock->write) accessforbidden();
$inventory = new Inventory($db);
$inventory->fetch(GETPOST('id'));
card($inventory, GETPOST('action'));
break;
switch($action) {
case 'save':
if (!$user->rights->stock->write) accessforbidden();
if (!$user->rights->stock->creer) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
$object = new Inventory($db);
$object->fetch($id);
$inventory->setValues($_REQUEST);
$object->setValues($_REQUEST);
if ($inventory->errors)
if ($object->errors)
{
setEventMessage($inventory->errors, 'errors');
card( $inventory, 'edit');
setEventMessage($object->errors, 'errors');
card( $object, 'edit');
}
else
{
$inventory->udpate($user);
header('Location: '.dol_buildpath('/product/inventory/card.php?id='.$inventory->getId().'&action=view', 1));
$object->udpate($user);
header('Location: '.dol_buildpath('/product/inventory/card.php?id='.$object->getId().'&action=view', 1));
}
break;
case 'confirm_regulate':
if (!$user->rights->stock->write) accessforbidden();
if (!$user->rights->stock->creer) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
$object = new Inventory($db);
$object->fetch($id);
if($inventory->status == 0) {
$inventory->status = 1;
$inventory->update($user);
if($object->status == 0) {
$object->status = 1;
$object->update($user);
card( $inventory, 'view');
card( $object, 'view');
}
else {
card( $inventory, 'view');
card( $object, 'view');
}
break;
@@ -150,23 +181,23 @@ function _action()
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch( $id );
$object = new Inventory($db);
$object->fetch( $id );
$inventory->changePMP($user);
$object->changePMP($user);
card( $inventory, 'view');
card( $object, 'view');
break;
case 'add_line':
if (!$user->rights->stock->write) accessforbidden();
if (!$user->rights->stock->creer) accessforbidden();
$id = GETPOST('id');
$fk_warehouse = GETPOST('fk_warehouse');
$inventory = new Inventory($db);
$inventory->fetch( $id );
$object = new Inventory($db);
$object->fetch( $id );
$fk_product = GETPOST('fk_product');
if ($fk_product>0)
@@ -179,8 +210,8 @@ function _action()
//Check product not already exists
$alreadyExists = false;
if(!empty($inventory->Inventorydet)) {
foreach ($inventory->Inventorydet as $invdet)
if(!empty($object->Inventorydet)) {
foreach ($object->Inventorydet as $invdet)
{
if ($invdet->fk_product == $product->id
&& $invdet->fk_warehouse == $fk_warehouse)
@@ -192,7 +223,7 @@ function _action()
}
if (!$alreadyExists)
{
if($inventory->addProduct($product->id, $fk_warehouse)) {
if($object->addProduct($product->id, $fk_warehouse)) {
setEventMessage($langs->trans('ProductAdded'));
}
}
@@ -203,59 +234,59 @@ function _action()
}
$inventory->update($user);
$inventory->sortDet();
$object->update($user);
$object->sortDet();
}
card( $inventory, 'edit');
card( $object, 'edit');
break;
case 'confirm_delete_line':
if (!$user->rights->stock->write) accessforbidden();
if (!$user->rights->stock->creer) accessforbidden();
//Cette action devrais se faire uniquement si le status de l'inventaire est à 0 mais aucune vérif
$rowid = GETPOST('rowid');
$Inventorydet = new Inventorydet($db);
if($Inventorydet->fetch($rowid)>0) {
$Inventorydet->delete($user);
$objectdet = new Inventorydet($db);
if($objectdet->fetch($rowid)>0) {
$objectdet->delete($user);
setEventMessage("ProductDeletedFromInventory");
}
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch( $id);
$object = new Inventory($db);
$object->fetch( $id);
card($inventory, 'edit');
card($object, 'edit');
break;
case 'confirm_flush':
if (!$user->rights->stock->create) accessforbidden();
if (!$user->rights->stock->creer) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
$object = new Inventory($db);
$object->fetch($id);
$inventory->deleteAllLine($user);
$object->deleteAllLine($user);
setEventMessage($langs->trans('InventoryFlushed'));
card( $inventory, 'edit');
card( $object, 'edit');
break;
case 'confirm_delete':
if (!$user->rights->stock->create) accessforbidden();
if (!$user->rights->stock->supprimer) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
$object = new Inventory($db);
$object->fetch($id);
$inventory->delete($user);
$object->delete($user);
setEventMessage($langs->trans('InventoryDeleted'));
@@ -263,46 +294,41 @@ function _action()
exit;
break;
case 'exportCSV':
/*case 'exportCSV':
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
$object = new Inventory($db);
$object->fetch($id);
_exportCSV($inventory);
_exportCSV($object);
exit;
break;
default:
if (!$user->rights->stock->write) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch($id);
card($inventory, $action );
break;
*/
}
}
}
function card_warehouse(&$inventory)
/*
* Views
*/
$form=new Form($db);
llxHeader('',$langs->trans('Inventory'),'','');
if ($action == 'create')
{
global $langs,$conf,$db, $user, $form;
if (empty($user->rights->stock->creer)) accessforbidden();
dol_include_once('/categories/class/categorie.class.php');
llxHeader('',$langs->trans('inventorySelectWarehouse'),'','');
print dol_get_fiche_head(inventoryPrepareHead($inventory));
print load_fiche_titre($langs->trans("NewInventory"));
echo '<form name="confirmCreate" action="'.$_SERVER['PHP_SELF'].'" method="post" />';
echo '<input type="hidden" name="action" value="confirmCreate" />';
dol_fiche_head();
$formproduct = new FormProduct($db);
?>
@@ -337,61 +363,63 @@ function card_warehouse(&$inventory)
</table>
<?php
print '<div class="tabsAction">';
print '<input type="submit" class="butAction" value="'.$langs->trans('inventoryConfirmCreate').'" />';
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans('inventoryConfirmCreate').'" />';
print ' &nbsp; &nbsp; ';
print '<input type="submit" class="button" value="'.$langs->trans('inventoryConfirmCreate').'" />';
print '</div>';
echo '</form>';
llxFooter('');
}
function card(&$inventory, $action='edit')
if ($action == 'view' || $action == 'edit' || empty($action))
{
global $langs, $conf, $db, $user,$form;
llxHeader('',$langs->trans('inventoryEdit'),'','');
$object = new Inventory($db);
$object->fetch($id);
if($action == 'changePMP')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id, $langs->trans('ApplyNewPMP'), $langs->trans('ConfirmApplyNewPMP', $inventory->getTitle()), 'confirm_changePMP', array(),'no',1);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ApplyNewPMP'), $langs->trans('ConfirmApplyNewPMP', $object->getTitle()), 'confirm_changePMP', array(),'no',1);
}
else if($action == 'flush')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('FlushInventory'),$langs->trans('ConfirmFlushInventory',$inventory->getTitle()),'confirm_flush',array(),'no',1);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('FlushInventory'),$langs->trans('ConfirmFlushInventory',$object->getTitle()),'confirm_flush',array(),'no',1);
}
else if($action == 'delete')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('Delete'),$langs->trans('ConfirmDelete',$inventory->getTitle()),'confirm_delete',array(),'no',1);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('Delete'),$langs->trans('ConfirmDelete',$object->getTitle()),'confirm_delete',array(),'no',1);
}
else if($action == 'delete_line')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id.'&rowid='.GETPOST('rowid'),$langs->trans('DeleteLine'),$langs->trans('ConfirmDeleteLine',$inventory->getTitle()),'confirm_delete_line',array(),'no',1);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&rowid='.GETPOST('rowid'),$langs->trans('DeleteLine'),$langs->trans('ConfirmDeleteLine',$object->getTitle()),'confirm_delete_line',array(),'no',1);
}
else if($action == 'regulate')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('RegulateStock'),$langs->trans('ConfirmRegulateStock',$inventory->getTitle()),'confirm_regulate',array(),'no',1);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('RegulateStock'),$langs->trans('ConfirmRegulateStock',$object->getTitle()),'confirm_regulate',array(),'no',1);
}
$warehouse = new Entrepot($db);
$warehouse->fetch($inventory->fk_warehouse);
$warehouse->fetch($object->fk_warehouse);
print dol_get_fiche_head(inventoryPrepareHead($inventory, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($action) ? '': '&action='.$action));
print dol_get_fiche_head(inventoryPrepareHead($object, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($action) ? '': '&action='.$action));
$lines = array();
card_line($inventory, $lines, $action);
card_line($object, $lines, $action);
print '<b>'.$langs->trans('inventoryOnDate')." ".$inventory->getDate('date_inventory').'</b><br><br>';
print '<b>'.$langs->trans('inventoryOnDate')." ".$object->getDate('date_inventory').'</b><br><br>';
$inventoryTPL = array(
'id'=> $inventory->id
,'date_cre' => $inventory->getDate('date_cre', 'd/m/Y')
,'date_maj' => $inventory->getDate('date_maj', 'd/m/Y H:i')
,'fk_warehouse' => $inventory->fk_warehouse
,'status' => $inventory->status
,'entity' => $inventory->entity
,'amount' => price( round($inventory->amount,2) )
,'amount_actual'=>price (round($inventory->amount_actual,2))
$objectTPL = array(
'id'=> $object->id
,'date_cre' => $object->getDate('date_cre', 'd/m/Y')
,'date_maj' => $object->getDate('date_maj', 'd/m/Y H:i')
,'fk_warehouse' => $object->fk_warehouse
,'status' => $object->status
,'entity' => $object->entity
,'amount' => price( round($object->amount,2) )
,'amount_actual'=>price (round($object->amount_actual,2))
);
@@ -402,15 +430,18 @@ function card(&$inventory, $action='edit')
'mode' => $action
,'url' => dol_buildpath('/product/inventory/card.php', 1)
,'can_validate' => (int) $user->rights->stock->validate
,'is_already_validate' => (int) $inventory->status
,'is_already_validate' => (int) $object->status
,'token'=>$_SESSION['newtoken']
);
include './tpl/inventory.tpl.php';
llxFooter('');
}
// End of page
llxFooter();
$db->close();
function card_line(&$inventory, &$lines, $mode)
{
@@ -421,7 +452,6 @@ function card_line(&$inventory, &$lines, $mode)
foreach ($inventory->Inventorydet as $k => $Inventorydet)
{
$product = & $Inventorydet->product;
$stock = $Inventorydet->qty_stock;
@@ -442,7 +472,7 @@ function card_line(&$inventory, &$lines, $mode)
'produit' => $product->getNomUrl(1).'&nbsp;-&nbsp;'.$product->label,
'entrepot'=>$e->getNomUrl(1),
'barcode' => $product->barcode,
'qty' =>($mode == 'edit' ? '<input type="text" name="qty_to_add['.$k.']" value="'.$qty.'" size="8" style="text-align:center;" /> <a id="a_save_qty_'.$k.'" href="javascript:save_qty('.$k.')">'.img_picto($langs->trans('Add'), 'plus16@inventory').'</a>' : '' ),
'qty' =>($mode == 'edit' ? '<input type="text" name="qty_to_add['.$k.']" value="'.$qty.'" size="8" style="text-align:center;" /> <a id="a_save_qty_'.$k.'" href="javascript:save_qty('.$k.')">'.img_picto($langs->trans('Add'), 'edit_add').'</a>' : '' ),
'qty_view' => ($Inventorydet->qty_view ? $Inventorydet->qty_view : 0),
'qty_stock' => $stock,
'qty_regulated' => ($Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0),
@@ -461,7 +491,10 @@ function card_line(&$inventory, &$lines, $mode)
}
function _exportCSV(&$inventory) {
/*
function _exportCSV(&$inventory)
{
global $conf;
header('Content-Type: application/octet-stream');
@@ -531,8 +564,10 @@ function _exportCSV(&$inventory) {
exit;
}
*/
function _footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actual, $total_current_pa,$total_current_pa_actual) {
function _footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actual, $total_current_pa,$total_current_pa_actual)
{
global $conf,$user,$langs;
if ($view['can_validate'] == 1) { ?>
@@ -569,7 +604,10 @@ function _footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actu
</tr>
<?php }
}
function _headerList($view) {
function _headerList($view)
{
global $conf,$user,$langs;
?>

View File

@@ -67,7 +67,7 @@ class Inventory extends CoreObject
* Attribute object linked with database
* @var array
*/
protected $__fields=array(
protected $fields=array(
'fk_warehouse'=>array('type'=>'integer','index'=>true)
,'entity'=>array('type'=>'integer','index'=>true)
,'status'=>array('type'=>'integer','index'=>true)
@@ -503,6 +503,7 @@ class Inventory extends CoreObject
/**
* Function to get the sql select of inventory
*
* @param string $type 'All' to get all data
* @return string
*/
@@ -516,7 +517,7 @@ class Inventory extends CoreObject
$sql = 'SELECT i.rowid,i.title, e.label, i.date_inventory, i.fk_warehouse, i.datec, i.tms, i.status';
$sql.= ' FROM '.MAIN_DB_PREFIX.'inventory i';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot e ON (e.rowid = i.fk_warehouse)';
$sql.= ' WHERE i.entity = '.(int) $conf->entity;
$sql.= ' WHERE i.entity IN ('.getEntity('inventory', 1).')';
}
return $sql;
@@ -541,7 +542,7 @@ class Inventorydet extends CoreObject
public $pa;
public $new_pmp;
protected $__fields=array(
protected $fields=array(
'fk_inventory'=>array('type'=>'int')
,'fk_warehouse'=>array('type'=>'int')
,'fk_product'=>array('type'=>'int')

View File

@@ -36,7 +36,30 @@ require_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
$langs->load("stock");
$langs->load("inventory");
if (empty($user->rights->stock->read)) accessforbidden();
$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = (GETPOST("page",'int')?GETPOST("page", 'int'):0);
if ($page == -1) { $page = 0; }
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="i.title";
if (! $sortorder) $sortorder="ASC";
if (empty($user->rights->stock->lire)) accessforbidden();
/*
* Actions
*/
// None
/*
* View
*/
llxHeader('',$langs->trans('inventoryListTitle'),'','');
@@ -48,8 +71,15 @@ $list = new ListView($db, 'listInventory');
$THide = array('label','title');
echo $list->render(Inventory::getSQL('All'), array(
'param' => array(
'limit' => $limit,
'offset' => $offset,
'sortfield' => $sortfield,
'sortorder'=> $sortorder,
'page'=>$page
),
'limit' => array(
'nbLine' => GETPOST('limit')
'nbLine' => $limit,
),
'allow-field-select' => true,
'link'=>array(
@@ -65,14 +95,14 @@ echo $list->render(Inventory::getSQL('All'), array(
'list'=>array(
'title'=>$langs->trans('inventoryListTitle'),
'messageNothing'=>$langs->trans('inventoryListEmpty'),
'image' => 'inventory.png@inventory'
'image' => 'title_products.png'
),
'title'=>array(
'rowid'=>$langs->trans('Title'),
'date_inventory'=>$langs->trans('InventoryDate'),
'datec'=>$langs->trans('DateCreation'),
'fk_warehouse'=>$langs->trans('Warehouse'),
'tms'=>$langs->trans('DateUpdate'),
'datec'=>$langs->trans('DateCreation'),
'tms'=>$langs->trans('DateModification'),
'status'=>$langs->trans('Status')
),
'eval'=>array(

View File

@@ -71,15 +71,15 @@
}
</script>
<?php if ($inventory->status != 1) { ?>
<?php if ($object->status != 1) { ?>
<strong><?php echo $langs->trans('AddInventoryProduct'); ?> : </strong>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="action" value="add_line" />
<input type="hidden" name="id" value="<?php echo $inventory->id; ?>" />
<input type="hidden" name="id" value="<?php echo $object->id; ?>" />
<?php echo inventorySelectProducts($inventory); ?>
<?php echo inventorySelectProducts($object); ?>
<input class="butAction" type="submit" value="<?php echo $langs->trans('AddProduct'); ?>" />
<input class="button" type="submit" value="<?php echo $langs->trans('AddProduct'); ?>" />
</form>
<?php } ?>
@@ -90,7 +90,7 @@
<?php } ?>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="id" value="<?php echo $inventory->id; ?>" />
<input type="hidden" name="id" value="<?php echo $object->id; ?>" />
<table width="100%" class="border workstation">
<?php
@@ -163,43 +163,43 @@
?>
</table>
<?php if ($inventory->status != 1) { ?>
<?php if ($object->status != 1) { ?>
<div class="tabsAction" style="height:30px;">
<?php if ($action!= 'edit') { ?>
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a>
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=edit" class="butAction"><?php echo $langs->trans('Modify') ?></a>
<!-- <a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a> -->
<a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=edit" class="butAction"><?php echo $langs->trans('Modify') ?></a>
<?php
if(!empty($user->rights->stock->changePMP)) {
echo '<a href="'.$view_url.'?id='.$inventory->id.'&action=changePMP" class="butAction">'.$langs->trans('ApplyPMP').'</a>';
echo '<a href="'.$view_url.'?id='.$object->id.'&action=changePMP" class="butAction">'.$langs->trans('ApplyPMP').'</a>';
}
if ($can_validate == 1) { ?>
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=regulate&token=" class="butAction"><?php echo $langs->trans('RegulateStock') ?></a>
<a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=regulate&token=" class="butAction"><?php echo $langs->trans('RegulateStock') ?></a>
<?php } ?>
<?php } ?>
<?php if ($action == 'edit') { ?>
<input name="back" type="button" class="butAction" value="<?php echo $langs->trans('ExitEditMode'); ?>" onclick="document.location='?id=<?php echo $inventory->id; ?>&action=view';" />
<input name="back" type="button" class="butAction" value="<?php echo $langs->trans('ExitEditMode'); ?>" onclick="document.location='?id=<?php echo $object->id; ?>&action=view';" />
<?php } ?>
<?php if ($can_validate == 1) { ?>
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=flush" class="butActionDelete"><?php echo $langs->trans('Flush'); ?></a>
<a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=flush" class="butActionDelete"><?php echo $langs->trans('Flush'); ?></a>
&nbsp;&nbsp;&nbsp;
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=delete" class="butActionDelete"><?php echo $langs->trans('Delete') ?></a>
<a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=delete" class="butActionDelete"><?php echo $langs->trans('Delete') ?></a>
<?php } ?>
</div>
<?php } ?>
<?php if ($inventory->status == 1) { ?>
<?php if ($object->status == 1) { ?>
<div class="tabsAction">
<?php if ($can_validate == 1) { ?>
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a>
<!-- <a href="<?php echo $view_url; ?>?id=<?php echo $object->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a> -->
<a href="#" title="<?php echo $langs->trans('InventoryAlreadyValidated'); ?>" class="butActionRefused"><?php echo $langs->trans('Delete') ?></a>
<?php } ?>
</div>
<?php } ?>
</form>
<p>Date de création : <?php echo $inventory->getDate('datec') ?>
<br />Dernière mise à jour : <?php echo $inventory->getDate('tms') ?></p>
<p>Date de création : <?php echo $object->getDate('datec') ?>
<br />Dernière mise à jour : <?php echo $object->getDate('tms') ?></p>