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");
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;
}
}
@ -457,7 +457,6 @@ if ($action == 'create')
$classname = ucfirst($origin);
$object = new $classname($db);
if ($object->fetch($origin_id)) // This include the fetch_lines
{
//var_dump($object);
@ -837,7 +836,7 @@ if ($action == 'create')
print '<br>';
}
else
{
{
dol_print_error($db);
}
}

View File

@ -399,7 +399,7 @@ class Expedition extends CommonObject
* @param string $ref Ref of object
* @param string $ref_ext External reference of 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='')
{
@ -496,9 +496,9 @@ class Expedition extends CommonObject
}
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;
return -2;
return 0;
}
}
else
@ -613,7 +613,7 @@ class Expedition extends CommonObject
if ($result < 0) { $error++; break; }
if (! empty($conf->productbatch->enabled)) {
$details=ExpeditionLigneBatch::FetchAll($this->db,$obj->rowid);
$details=ExpeditionLigneBatch::fetchAll($this->db,$obj->rowid);
if (! empty($details)) {
foreach ($details as $dbatch) {
$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';
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 {
$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) {

View File

@ -1,5 +1,5 @@
<?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>
*
* This program is free software; you can redistribute it and/or modify
@ -20,13 +20,12 @@
* \file expedition/class/productbatch.class.php
* \ingroup productbatch
* \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
*/
class ExpeditionLigneBatch extends CommonObject
{
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
* @return int -1 if KO, 1 if OK
*/
function fetchFromStock($id_stockdluo) {
function fetchFromStock($id_stockdluo)
{
$sql = "SELECT";
$sql.= " t.sellby,";
$sql.= " t.eatby,";
$sql.= " t.batch,";
$sql.= " e.fk_entrepot";
$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.= " WHERE t.rowid = ".(int) $id_stockdluo;
@ -82,7 +82,6 @@ class ExpeditionLigneBatch extends CommonObject
$this->batch = $obj->batch;
$this->entrepot_id= $obj->fk_entrepot;
$this->fk_origin_stock=(int) $id_stockdluo;
}
$this->db->free($resql);
@ -98,14 +97,15 @@ class ExpeditionLigneBatch extends CommonObject
/**
* Create an expeditiondet_batch DB record link to an expedtiondet record
*
* @param int $id_line_expdet rowid of expedtiondet record
* @return int <0 if KO, Id of record (>0) if OK
* @param int $id_line_expdet rowid of expedtiondet record
* @return int <0 if KO, Id of record (>0) if OK
*/
function create($id_line_expdet) {
function create($id_line_expdet)
{
$error = 0;
$id_line_expdet = (int) $id_line_expdet;
$sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." (";
$sql.= "fk_expeditiondet";
$sql.= ", sellby";
@ -115,23 +115,25 @@ class ExpeditionLigneBatch extends CommonObject
$sql.= ", fk_origin_stock";
$sql.= ") VALUES (";
$sql.= $id_line_expdet.",";
$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->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->batch)?'NULL':"'".$this->db->escape($this->batch)."'").",";
$sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).",";
$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
$sql.= ")";
dol_syslog(__METHOD__ ."", LOG_DEBUG);
dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql);
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->fk_expeditiondet=$id_line_expdet;
return $this->id;
} else {
}
else
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
@ -147,20 +149,22 @@ class ExpeditionLigneBatch extends CommonObject
*
* @param object $db Database object
* @param int $id_expedition rowid of shipment
*
* @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;
$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.")";
dol_syslog(__METHOD__ ."", LOG_DEBUG);
if ( $db->query($sql) )
dol_syslog(__METHOD__, LOG_DEBUG);
if ($db->query($sql))
{
return 1;
} else {
}
else
{
return -1;
}
}
@ -168,12 +172,12 @@ class ExpeditionLigneBatch extends CommonObject
/**
* Retrieve all batch number details link to a shipment line
*
* @param object $db Database object
* @param int $id_line_expdet id of shipment line
*
* @return variant -1 if KO, array of ExpeditionLigneBatch if OK
* @param object $db Database object
* @param int $id_line_expdet id of shipment line
* @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.= "fk_expeditiondet";
$sql.= ", sellby";
@ -190,7 +194,8 @@ class ExpeditionLigneBatch extends CommonObject
{
$num=$db->num_rows($resql);
$i=0;
while ($i<$num) {
while ($i<$num)
{
$tmp=new self($db);
$obj = $db->fetch_object($resql);
@ -208,7 +213,9 @@ class ExpeditionLigneBatch extends CommonObject
}
$db->free($resql);
return $ret;
} else {
}
else
{
return -1;
}
}

View File

@ -42,7 +42,7 @@ $langs->load('propal');
$langs->load('deliveries');
$langs->load('stocks');
$id=GETPOST('id','int');
$id=GETPOST('id','int'); // id of order
$ref= GETPOST('ref','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 '<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="origin" value="commande">';
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_sellby=Sell-by date
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
printEatby=Eat-by: %s
printSellby=Sell-by: %s