dolibarr  7.0.0-beta
expeditionbatch.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
30 {
31  var $element='expeditionlignebatch';
32  private static $_table_element='expeditiondet_batch';
33 
34  var $sellby;
35  var $eatby;
36  var $batch;
37  var $dluo_qty;
38  var $entrepot_id;
39  var $fk_origin_stock;
40  var $fk_expeditiondet;
41 
47  function __construct($db)
48  {
49  $this->db = $db;
50  return 1;
51  }
52 
59  function fetchFromStock($id_stockdluo)
60  {
61  $sql = "SELECT";
62  $sql.= " t.sellby,";
63  $sql.= " t.eatby,";
64  $sql.= " t.batch,";
65  $sql.= " e.fk_entrepot";
66 
67  $sql.= " FROM ".MAIN_DB_PREFIX."product_batch as t inner join ";
68  $sql.= MAIN_DB_PREFIX."product_stock as e on t.fk_product_stock=e.rowid ";
69  $sql.= " WHERE t.rowid = ".(int) $id_stockdluo;
70 
71  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
72  $resql=$this->db->query($sql);
73  if ($resql)
74  {
75  if ($this->db->num_rows($resql))
76  {
77  $obj = $this->db->fetch_object($resql);
78 
79  $this->sellby = $this->db->jdate($obj->sellby);
80  $this->eatby = $this->db->jdate($obj->eatby);
81  $this->batch = $obj->batch;
82  $this->entrepot_id= $obj->fk_entrepot;
83  $this->fk_origin_stock=(int) $id_stockdluo;
84  }
85  $this->db->free($resql);
86 
87  return 1;
88  }
89  else
90  {
91  $this->error="Error ".$this->db->lasterror();
92  return -1;
93  }
94  }
95 
102  function create($id_line_expdet)
103  {
104  $error = 0;
105 
106  $id_line_expdet = (int) $id_line_expdet;
107 
108  $sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." (";
109  $sql.= "fk_expeditiondet";
110  $sql.= ", sellby";
111  $sql.= ", eatby";
112  $sql.= ", batch";
113  $sql.= ", qty";
114  $sql.= ", fk_origin_stock";
115  $sql.= ") VALUES (";
116  $sql.= $id_line_expdet.",";
117  $sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").",";
118  $sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").",";
119  $sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).",";
120  $sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).",";
121  $sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
122  $sql.= ")";
123 
124  dol_syslog(__METHOD__, LOG_DEBUG);
125  $resql=$this->db->query($sql);
126  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
127 
128  if (! $error)
129  {
130  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
131  $this->fk_expeditiondet=$id_line_expdet;
132  return $this->id;
133  }
134  else
135  {
136  foreach($this->errors as $errmsg)
137  {
138  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
139  $this->error.=($this->error?', '.$errmsg:$errmsg);
140  }
141  $this->db->rollback();
142  return -1*$error;
143  }
144  }
145 
153  static function deletefromexp($db,$id_expedition)
154  {
155  $id_expedition = (int) $id_expedition;
156 
157  $sql="DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
158  $sql.=" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")";
159 
160  dol_syslog(__METHOD__, LOG_DEBUG);
161  if ($db->query($sql))
162  {
163  return 1;
164  }
165  else
166  {
167  return -1;
168  }
169  }
170 
179  static function fetchAll($db, $id_line_expdet, $fk_product=0)
180  {
181  $sql="SELECT";
182  $sql.= " eb.rowid,";
183  $sql.= " eb.fk_expeditiondet,";
184  $sql.= " eb.sellby as oldsellby,"; // deprecated
185  $sql.= " eb.eatby as oldeatby,"; // deprecated
186  $sql.= " eb.batch,";
187  $sql.= " eb.qty,";
188  $sql.= " eb.fk_origin_stock";
189  if ($fk_product > 0)
190  {
191  $sql.= ", pl.sellby";
192  $sql.= ", pl.eatby";
193  }
194  $sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb";
195  if ($fk_product > 0)
196  {
197  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
198  }
199  $sql.= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
200 
201  dol_syslog(__METHOD__ ."", LOG_DEBUG);
202  $resql=$db->query($sql);
203  if ($resql)
204  {
205  $num=$db->num_rows($resql);
206  $i=0;
207  $ret = array();
208  while ($i<$num)
209  {
210  $tmp=new self($db);
211 
212  $obj = $db->fetch_object($resql);
213 
214  $tmp->sellby = $db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby);
215  $tmp->eatby = $db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby);
216  $tmp->batch = $obj->batch;
217  $tmp->id = $obj->rowid;
218  $tmp->fk_origin_stock = $obj->fk_origin_stock;
219  $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
220  $tmp->dluo_qty = $obj->qty;
221 
222  $ret[]=$tmp;
223  $i++;
224  }
225  $db->free($resql);
226  return $ret;
227  }
228  else
229  {
230  dol_print_error($db);
231  return -1;
232  }
233  }
234 
235 }
CRUD class for batch number management within shipment.
static $_table_element
Name of table without prefix where object is stored.
create($id_line_expdet)
Create an expeditiondet_batch DB record link to an expedtiondet record.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
static fetchAll($db, $id_line_expdet, $fk_product=0)
Retrieve all batch number detailed information of a shipment line.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
__construct($db)
Constructor.
$element
Id that identify managed objects.
fetchFromStock($id_stockdluo)
Fill object based on a product-warehouse-batch's record.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
static deletefromexp($db, $id_expedition)
Delete batch record attach to a shipment.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)