2
0
forked from Wavyzz/dolibarr

Refactoring and fix

This commit is contained in:
atm-ph
2017-03-25 18:13:39 +01:00
parent e3afa06cf3
commit fce8e08b51
6 changed files with 83 additions and 87 deletions

View File

@@ -517,7 +517,7 @@ class CoreObject extends CommonObject
$this->db->begin(); $this->db->begin();
$query = $this->set_save_query(); $query = $this->set_save_query();
$query['datec'] = date("Y-m-d H:i:s", $this->datec); $query['datec'] = date("Y-m-d H:i:s", dol_now());
$res = $this->db->insert($this->table_element, $query); $res = $this->db->insert($this->table_element, $query);
if($res) if($res)

View File

@@ -19,21 +19,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
class Listview { class Listview
{
function __construct(&$db, $id ) {
function __construct(&$db, $id)
{
$this->db = &$db; $this->db = &$db;
$this->id = $id; $this->id = $id;
$this->TTotalTmp=array(); $this->TTotalTmp=array();
$this->sql = ''; $this->sql = '';
} }
private function init(&$TParam) {
private function init(&$TParam)
{
global $conf, $langs; global $conf, $langs;
if(!isset($TParam['hide']))$TParam['hide']=array(); if(!isset($TParam['hide']))$TParam['hide']=array();
@@ -574,7 +572,7 @@ class Listview {
$this->init($TParam); $this->init($TParam);
$this->parse_array($THeader, $TField, $TParam,$TField); $this->parse_array($THeader, $TField, $TParam);
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam); list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
$this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam); $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
@@ -610,7 +608,8 @@ class Listview {
return $sql; return $sql;
} }
private function parse_array(&$THeader, &$TField, &$TParam, $TField) { private function parse_array(&$THeader, &$TField, &$TParam)
{
$first = true; $first = true;
$this->THideFlip = array_flip($TParam['hide']); $this->THideFlip = array_flip($TParam['hide']);
@@ -844,7 +843,7 @@ class Listview {
$this->TTotalTmp=array(); $this->TTotalTmp=array();
$this->THideFlip = array_flip($TParam['hide']); $this->THideFlip = array_flip($TParam['hide']);
var_dump($this->sql);
$res = $this->db->query($this->sql); $res = $this->db->query($this->sql);
if($res!==false) { if($res!==false) {

View File

@@ -6,20 +6,23 @@
$get = GETPOST('get'); $get = GETPOST('get');
$put = GETPOST('put'); $put = GETPOST('put');
switch ($put) { switch ($put)
{
case 'qty': case 'qty':
if (!$user->rights->inventory->write) { echo -1; exit; } if (empty($user->rights->inventory->write)) { echo -1; exit; }
$fk_det_inventory = GETPOST('fk_det_inventory'); $fk_det_inventory = GETPOST('fk_det_inventory');
$det = new Inventorydet($db); $det = new Inventorydet($db);
if( $det->fetch( $fk_det_inventory)) { if( $det->fetch( $fk_det_inventory))
{
$det->qty_view+=GETPOST('qty'); $det->qty_view+=GETPOST('qty');
$det->update($user); $det->update($user);
echo $det->qty_view; echo $det->qty_view;
} }
else { else
{
echo -2; echo -2;
} }
@@ -31,17 +34,18 @@
$fk_det_inventory = GETPOST('fk_det_inventory'); $fk_det_inventory = GETPOST('fk_det_inventory');
$det = new Inventorydet($db); $det = new Inventorydet($db);
if( $det->fetch( $fk_det_inventory)) { if( $det->fetch( $fk_det_inventory))
{
$det->new_pmp=price2num(GETPOST('pmp')); $det->new_pmp=price2num(GETPOST('pmp'));
$det->update($user); $det->update($user);
echo $det->new_pmp; echo $det->new_pmp;
} }
else { else
{
echo -2; echo -2;
} }
break; break;
} }

View File

@@ -574,9 +574,10 @@ class Inventorydet extends CoreObject
* Get object and children from database * Get object and children from database
* *
* @param int $id id of inventorydet object * @param int $id id of inventorydet object
* @param bool $loadChild load children
* @return int * @return int
*/ */
function fetch($id) function fetch($id, $loadChild = true)
{ {
$res = parent::fetch($id); $res = parent::fetch($id);
$this->load_product(); $this->load_product();

View File

@@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
$langs->load("stock"); $langs->load("stock");
$langs->load("inventory"); $langs->load("inventory");
if(!$user->rights->inventory->read) accessforbidden(); if(empty($user->rights->inventory->read)) accessforbidden();
_action(); _action();
@@ -54,7 +54,7 @@ function _action()
switch($action) { switch($action) {
case 'create': case 'create':
if (!$user->rights->inventory->create) accessforbidden(); if (empty($user->rights->inventory->create)) accessforbidden();
$inventory = new Inventory($db); $inventory = new Inventory($db);
@@ -63,7 +63,7 @@ function _action()
break; break;
case 'confirmCreate': case 'confirmCreate':
if (!$user->rights->inventory->create) accessforbidden(); if (empty($user->rights->inventory->create)) accessforbidden();
$inventory = new Inventory($db); $inventory = new Inventory($db);
$inventory->set_values($_POST); $inventory->set_values($_POST);

View File

@@ -36,26 +36,18 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
$langs->load("stock"); $langs->load("stock");
$langs->load("inventory"); $langs->load("inventory");
if(!$user->rights->inventory->read) accessforbidden(); if (empty($user->rights->inventory->read)) accessforbidden();
_list();
function _list()
{
global $db, $conf, $langs, $user;
llxHeader('',$langs->trans('inventoryListTitle'),'',''); llxHeader('',$langs->trans('inventoryListTitle'),'','');
echo '<form name="formListInvetory" action="'.$_SERVER['PHP_SELF'].'" method="post" >'; echo '<form name="formListInvetory" action="'.$_SERVER['PHP_SELF'].'" method="post" >';
$inventory = new Inventory($db); $inventory = new Inventory($db);
$l = new ListView($db,'listInventory'); $list = new ListView($db,'listInventory');
$THide = array('label','title'); $THide = array('label','title');
echo $l->render(Inventory::getSQL('All'), array( echo $list->render(Inventory::getSQL('All'), array(
'link'=>array( 'link'=>array(
'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>' 'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>'
) )
@@ -89,7 +81,7 @@ function _list()
)); ));
if ($user->rights->inventory->create) if (!empty($user->rights->inventory->create))
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
print '<a class="butAction" href="inventory.php?action=create">'.$langs->trans('inventoryCreate').'</a>'; print '<a class="butAction" href="inventory.php?action=create">'.$langs->trans('inventoryCreate').'</a>';
@@ -99,4 +91,4 @@ function _list()
echo '</form>'; echo '</form>';
llxFooter(''); llxFooter('');
} $db->close();