Fix bad id

This commit is contained in:
Laurent Destailleur 2015-02-16 19:14:34 +01:00
parent 58fc57744a
commit 9a9a1f3983
5 changed files with 50 additions and 44 deletions

View File

@ -98,7 +98,7 @@ if (($action == 'create') || ($action == 'add'))
{ {
$langs->load("errors"); $langs->load("errors");
setEventMessage($langs->trans("WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn"),'errors'); setEventMessage($langs->trans("WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn"),'errors');
header("Location: ".DOL_URL_ROOT.'/expedition/shipment.php?id='.$id); header("Location: ".DOL_URL_ROOT.'/expedition/shipment.php?id='.$origin_id);
exit; exit;
} }
} }
@ -457,7 +457,6 @@ if ($action == 'create')
$classname = ucfirst($origin); $classname = ucfirst($origin);
$object = new $classname($db); $object = new $classname($db);
if ($object->fetch($origin_id)) // This include the fetch_lines if ($object->fetch($origin_id)) // This include the fetch_lines
{ {
//var_dump($object); //var_dump($object);
@ -837,7 +836,7 @@ if ($action == 'create')
print '<br>'; print '<br>';
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
} }

View File

@ -399,7 +399,7 @@ class Expedition extends CommonObject
* @param string $ref Ref of object * @param string $ref Ref of object
* @param string $ref_ext External reference of object * @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other object * @param string $ref_int Internal reference of other object
* @return int >0 if OK, <0 if KO * @return int >0 if OK, 0 if not found, <0 if KO
*/ */
function fetch($id, $ref='', $ref_ext='', $ref_int='') function fetch($id, $ref='', $ref_ext='', $ref_int='')
{ {
@ -496,9 +496,9 @@ class Expedition extends CommonObject
} }
else else
{ {
dol_syslog(get_class($this).'::Fetch Error -2', LOG_ERR); dol_syslog(get_class($this).'::Fetch no expedition found', LOG_ERR);
$this->error='Delivery with id '.$id.' not found sql='.$sql; $this->error='Delivery with id '.$id.' not found sql='.$sql;
return -2; return 0;
} }
} }
else else
@ -613,7 +613,7 @@ class Expedition extends CommonObject
if ($result < 0) { $error++; break; } if ($result < 0) { $error++; break; }
if (! empty($conf->productbatch->enabled)) { if (! empty($conf->productbatch->enabled)) {
$details=ExpeditionLigneBatch::FetchAll($this->db,$obj->rowid); $details=ExpeditionLigneBatch::fetchAll($this->db,$obj->rowid);
if (! empty($details)) { if (! empty($details)) {
foreach ($details as $dbatch) { foreach ($details as $dbatch) {
$result=$mouvS->livraison_batch($dbatch->fk_origin_stock,$dbatch->dluo_qty); $result=$mouvS->livraison_batch($dbatch->fk_origin_stock,$dbatch->dluo_qty);
@ -1175,9 +1175,9 @@ class Expedition extends CommonObject
*/ */
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
if ($originline != $obj->fk_origin_line) { if ($originline != $obj->fk_origin_line) {
$line->detail_batch = ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id); $line->detail_batch = ExpeditionLigneBatch::fetchAll($this->db,$obj->line_id);
} else { } else {
$line->detail_batch = array_merge($line->detail_batch,ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id)); $line->detail_batch = array_merge($line->detail_batch,ExpeditionLigneBatch::fetchAll($this->db,$obj->line_id));
} }
} }
if ($originline != $obj->fk_origin_line) { if ($originline != $obj->fk_origin_line) {

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2007-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr> * Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -20,13 +20,12 @@
* \file expedition/class/productbatch.class.php * \file expedition/class/productbatch.class.php
* \ingroup productbatch * \ingroup productbatch
* \brief This file implements CRUD method for managing product's shipment * \brief This file implements CRUD method for managing product's shipment
* with batch record * with batch record
*/ */
/** /**
* CRUD class for batch number management within shipment * CRUD class for batch number management within shipment
*/ */
class ExpeditionLigneBatch extends CommonObject class ExpeditionLigneBatch extends CommonObject
{ {
var $element='expeditionlignebatch'; //!< Id that identify managed objects var $element='expeditionlignebatch'; //!< Id that identify managed objects
@ -53,18 +52,19 @@ class ExpeditionLigneBatch extends CommonObject
} }
/** /**
* Fill object based on a product-warehouse-batch's record * Fill object based on a product-warehouse-batch's record
* *
* @param int $id_stockdluo Rowid in product_batch table * @param int $id_stockdluo Rowid in product_batch table
* @return int -1 if KO, 1 if OK * @return int -1 if KO, 1 if OK
*/ */
function fetchFromStock($id_stockdluo) { function fetchFromStock($id_stockdluo)
{
$sql = "SELECT"; $sql = "SELECT";
$sql.= " t.sellby,"; $sql.= " t.sellby,";
$sql.= " t.eatby,"; $sql.= " t.eatby,";
$sql.= " t.batch,"; $sql.= " t.batch,";
$sql.= " e.fk_entrepot"; $sql.= " e.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."product_batch as t inner join "; $sql.= " FROM ".MAIN_DB_PREFIX."product_batch as t inner join ";
$sql.= MAIN_DB_PREFIX."product_stock as e on t.fk_product_stock=e.rowid "; $sql.= MAIN_DB_PREFIX."product_stock as e on t.fk_product_stock=e.rowid ";
$sql.= " WHERE t.rowid = ".(int) $id_stockdluo; $sql.= " WHERE t.rowid = ".(int) $id_stockdluo;
@ -82,7 +82,6 @@ class ExpeditionLigneBatch extends CommonObject
$this->batch = $obj->batch; $this->batch = $obj->batch;
$this->entrepot_id= $obj->fk_entrepot; $this->entrepot_id= $obj->fk_entrepot;
$this->fk_origin_stock=(int) $id_stockdluo; $this->fk_origin_stock=(int) $id_stockdluo;
} }
$this->db->free($resql); $this->db->free($resql);
@ -98,14 +97,15 @@ class ExpeditionLigneBatch extends CommonObject
/** /**
* Create an expeditiondet_batch DB record link to an expedtiondet record * Create an expeditiondet_batch DB record link to an expedtiondet record
* *
* @param int $id_line_expdet rowid of expedtiondet record * @param int $id_line_expdet rowid of expedtiondet record
* @return int <0 if KO, Id of record (>0) if OK * @return int <0 if KO, Id of record (>0) if OK
*/ */
function create($id_line_expdet) { function create($id_line_expdet)
{
$error = 0; $error = 0;
$id_line_expdet = (int) $id_line_expdet; $id_line_expdet = (int) $id_line_expdet;
$sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." (";
$sql.= "fk_expeditiondet"; $sql.= "fk_expeditiondet";
$sql.= ", sellby"; $sql.= ", sellby";
@ -115,23 +115,25 @@ class ExpeditionLigneBatch extends CommonObject
$sql.= ", fk_origin_stock"; $sql.= ", fk_origin_stock";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= $id_line_expdet.","; $sql.= $id_line_expdet.",";
$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':$this->db->idate($this->sellby)).","; $sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':"'".$this->db->idate($this->sellby))."',";
$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':$this->db->idate($this->eatby)).","; $sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby))."',";
$sql.= " ".(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").","; $sql.= " ".(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").",";
$sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).","; $sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).",";
$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock); $sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
$sql.= ")"; $sql.= ")";
dol_syslog(__METHOD__ ."", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error){ if (! $error)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
$this->fk_expeditiondet=$id_line_expdet; $this->fk_expeditiondet=$id_line_expdet;
return $this->id; return $this->id;
} else { }
else
{
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
@ -147,20 +149,22 @@ class ExpeditionLigneBatch extends CommonObject
* *
* @param object $db Database object * @param object $db Database object
* @param int $id_expedition rowid of shipment * @param int $id_expedition rowid of shipment
*
* @return int -1 if KO, 1 if OK * @return int -1 if KO, 1 if OK
*/ */
static function deletefromexp($db,$id_expedition) { static function deletefromexp($db,$id_expedition)
{
$id_expedition = (int) $id_expedition; $id_expedition = (int) $id_expedition;
$sql="DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element; $sql="DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
$sql.=" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")"; $sql.=" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")";
dol_syslog(__METHOD__ ."", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
if ( $db->query($sql) ) if ($db->query($sql))
{ {
return 1; return 1;
} else { }
else
{
return -1; return -1;
} }
} }
@ -168,12 +172,12 @@ class ExpeditionLigneBatch extends CommonObject
/** /**
* Retrieve all batch number details link to a shipment line * Retrieve all batch number details link to a shipment line
* *
* @param object $db Database object * @param object $db Database object
* @param int $id_line_expdet id of shipment line * @param int $id_line_expdet id of shipment line
* * @return variant -1 if KO, array of ExpeditionLigneBatch if OK
* @return variant -1 if KO, array of ExpeditionLigneBatch if OK
*/ */
static function FetchAll($db,$id_line_expdet) { static function fetchAll($db,$id_line_expdet)
{
$sql="SELECT rowid,"; $sql="SELECT rowid,";
$sql.= "fk_expeditiondet"; $sql.= "fk_expeditiondet";
$sql.= ", sellby"; $sql.= ", sellby";
@ -190,7 +194,8 @@ class ExpeditionLigneBatch extends CommonObject
{ {
$num=$db->num_rows($resql); $num=$db->num_rows($resql);
$i=0; $i=0;
while ($i<$num) { while ($i<$num)
{
$tmp=new self($db); $tmp=new self($db);
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
@ -208,7 +213,9 @@ class ExpeditionLigneBatch extends CommonObject
} }
$db->free($resql); $db->free($resql);
return $ret; return $ret;
} else { }
else
{
return -1; return -1;
} }
} }

View File

@ -42,7 +42,7 @@ $langs->load('propal');
$langs->load('deliveries'); $langs->load('deliveries');
$langs->load('stocks'); $langs->load('stocks');
$id=GETPOST('id','int'); $id=GETPOST('id','int'); // id of order
$ref= GETPOST('ref','alpha'); $ref= GETPOST('ref','alpha');
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
@ -634,7 +634,7 @@ if ($id > 0 || ! empty($ref))
print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/card.php">'; print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/card.php">';
print '<input type="hidden" name="action" value="create">'; print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="id" value="'.$commande->id.'">'; //print '<input type="hidden" name="id" value="'.$commande->id.'">';
print '<input type="hidden" name="shipping_method_id" value="'.$commande->shipping_method_id.'">'; print '<input type="hidden" name="shipping_method_id" value="'.$commande->shipping_method_id.'">';
print '<input type="hidden" name="origin" value="commande">'; print '<input type="hidden" name="origin" value="commande">';
print '<input type="hidden" name="origin_id" value="'.$commande->id.'">'; print '<input type="hidden" name="origin_id" value="'.$commande->id.'">';

View File

@ -10,7 +10,7 @@ batch_number=Batch/Serial number
l_eatby=Eat-by date l_eatby=Eat-by date
l_sellby=Sell-by date l_sellby=Sell-by date
DetailBatchNumber=Batch/Serial details DetailBatchNumber=Batch/Serial details
DetailBatchFormat=Batch/Serial: %s - E:%s - S: %s (Qty : %d) DetailBatchFormat=Batch/Serial: %s - Eat by: %s - Sell by: %s (Qty : %d)
printBatch=Batch: %s printBatch=Batch: %s
printEatby=Eat-by: %s printEatby=Eat-by: %s
printSellby=Sell-by: %s printSellby=Sell-by: %s