PageRenderTime 303ms CodeModel.GetById 149ms app.highlight 11ms RepoModel.GetById 140ms app.codeStats 0ms

/htdocs/core/lib/sendings.lib.php

https://github.com/asterix14/dolibarr
PHP | 269 lines | 161 code | 42 blank | 66 comment | 20 complexity | b0a2e7dbacf818d18623d221a673c66c MD5 | raw file
  1<?php
  2/* Copyright (C) 2008-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License as published by
  6 * the Free Software Foundation; either version 2 of the License, or
  7 * (at your option) any later version.
  8 *
  9 * This program is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18/**
 19 *	\file       htdocs/core/lib/sendings.lib.php
 20 *	\ingroup    expedition
 21 *	\brief      Library for expedition module
 22 */
 23require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
 24require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php");
 25
 26
 27function shipping_prepare_head($object)
 28{
 29	global $langs, $conf, $user;
 30
 31	$langs->load("sendings");
 32	$langs->load("deliveries");
 33
 34	$h = 0;
 35	$head = array();
 36
 37	$head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->id;
 38	$head[$h][1] = $langs->trans("SendingCard");
 39	$head[$h][2] = 'shipping';
 40	$h++;
 41
 42	if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && ! empty($object->linkedObjectsIds['delivery'][0]))
 43	{
 44		$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0];
 45		$head[$h][1] = $langs->trans("DeliveryCard");
 46		$head[$h][2] = 'delivery';
 47		$h++;
 48	}
 49
 50    // Show more tabs from modules
 51    // Entries must be declared in modules descriptor with line
 52    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
 53    // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
 54    complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
 55
 56    return $head;
 57}
 58
 59
 60function delivery_prepare_head($object)
 61{
 62	global $langs, $conf, $user;
 63
 64	$langs->load("sendings");
 65	$langs->load("deliveries");
 66
 67	$h = 0;
 68	$head = array();
 69
 70	if ($conf->expedition_bon->enabled && $user->rights->expedition->lire)
 71	{
 72		$head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->origin_id;
 73		$head[$h][1] = $langs->trans("SendingCard");
 74		$head[$h][2] = 'shipping';
 75		$h++;
 76	}
 77
 78	$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->id;
 79	$head[$h][1] = $langs->trans("DeliveryCard");
 80	$head[$h][2] = 'delivery';
 81	$h++;
 82
 83    // Show more tabs from modules
 84    // Entries must be declared in modules descriptor with line
 85    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
 86    // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
 87    complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
 88
 89    return $head;
 90}
 91
 92/**
 93 * List sendings and receive receipts
 94 *
 95 * @param   string		$origin			Origin
 96 * @param	int			$origin_id		Origin id
 97 * @param	string		$filter			Filter
 98 * @return
 99 */
100function show_list_sending_receive($origin='commande',$origin_id,$filter='')
101{
102	global $db, $conf, $langs, $bc;
103	global $form;
104
105	$product_static=new Product($db);
106	$expedition=new Expedition($db);
107
108	$sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked";
109	$sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line";
110	$sql.= ", e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
111	//if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
112	$sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,';
113	$sql.= ' p.description as product_desc';
114	$sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
115	$sql.= ", ".MAIN_DB_PREFIX."expedition as e";
116	$sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
117    //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid  AND obj.rowid = ld.fk_origin_line";
118	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
119    $sql.= " WHERE obj.fk_".$origin." = ".$origin_id;
120	if ($filter) $sql.=$filter;
121	$sql.= " AND obj.rowid = ed.fk_origin_line";
122	$sql.= " AND ed.fk_expedition = e.rowid";
123	$sql.= " ORDER BY obj.fk_product";
124
125	dol_syslog("show_list_sending_receive sql=".$sql, LOG_DEBUG);
126	$resql = $db->query($sql);
127	if ($resql)
128	{
129		$num = $db->num_rows($resql);
130		$i = 0;
131
132		if ($num)
133		{
134			if ($somethingshown) print '<br>';
135
136			if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder"));
137			else print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
138
139			print '<table class="liste" width="100%">';
140			print '<tr class="liste_titre">';
141			//print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
142			print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
143			print '<td align="left">'.$langs->trans("Description").'</td>';
144			print '<td align="center">'.$langs->trans("DateCreation").'</td>';
145			print '<td align="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
146			print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
147			if ($conf->livraison_bon->enabled)
148            {
149                print '<td>'.$langs->trans("DeliveryOrder").'</td>';
150                //print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
151				print '<td align="right">'.$langs->trans("DeliveryDate").'</td>';
152            }
153			print "</tr>\n";
154
155			$var=True;
156			while ($i < $num)
157			{
158				$var=!$var;
159				$objp = $db->fetch_object($resql);
160				print "<tr $bc[$var]>";
161
162				// Sending id
163				print '<td align="left" nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.'<a></td>';
164
165				// Description
166				if ($objp->fk_product > 0)
167				{
168					print '<td>';
169
170					// Show product and description
171					$product_static->type=$objp->fk_product_type;
172					$product_static->id=$objp->fk_product;
173					$product_static->ref=$objp->ref;
174					$product_static->libelle=$objp->product;
175					$text=$product_static->getNomUrl(1);
176					$text.= ' - '.$objp->product;
177					$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description));
178					print $form->textwithtooltip($text,$description,3,'','',$i);
179
180					// Show range
181					print_date_range($objp->date_start,$objp->date_end);
182
183					// Add description in form
184					if ($conf->global->PRODUIT_DESC_IN_FORM)
185					{
186						print ($objp->description && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
187					}
188
189					print '</td>';
190				}
191				else
192				{
193					print "<td>";
194					if ($type==1) $text = img_object($langs->trans('Service'),'service');
195					else $text = img_object($langs->trans('Product'),'product');
196					print $text.' '.nl2br($objp->description);
197
198					// Show range
199					print_date_range($objp->date_start,$objp->date_end);
200					print "</td>\n";
201				}
202
203				//print '<td align="center">'.$objp->qty_asked.'</td>';
204
205				// Date creation
206				print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
207
208				// Date shipping creation
209				print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_delivery),'day').'</td>';
210
211				// Qty shipped
212				print '<td align="center">'.$objp->qty_shipped.'</td>';
213
214				// Informations on receipt
215				if ($conf->livraison_bon->enabled)
216				{
217					include_once(DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php');
218					$expedition->id=$objp->sendingid;
219					$expedition->fetchObjectLinked($expedition->id,$expedition->element);
220					//var_dump($expedition->linkedObjects);
221					$receiving=$expedition->linkedObjects['delivery'][0];
222
223					if (! empty($receiving))
224					{
225						// $expedition->fk_origin_line = id of det line of order
226						// $receiving->fk_origin_line = id of det line of order
227						// $receiving->origin may be 'shipping'
228						// $receiving->origin_id may be id of shipping
229
230						// Ref
231						print '<td>';
232						print $receiving->getNomUrl($db);
233						//print '<a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
234						print '</td>';
235						// Qty received
236						//print '<td align="center">';
237						// TODO No solution for the moment to link a line det of receipt with a line det of shipping,
238						// so no way to know the qty received for this line of shipping.
239						//print $langs->trans("FeatureNotYetAvailable");
240						//print '</td>';
241						// Date shipping real
242						print '<td align="right">';
243						print dol_print_date($receiving->date_delivery,'day');
244						print '</td>';
245					}
246					else
247					{
248						//print '<td>&nbsp;</td>';
249						print '<td>&nbsp;</td>';
250						print '<td>&nbsp;</td>';
251					}
252				}
253				print '</tr>';
254				$i++;
255			}
256
257			print '</table>';
258		}
259		$db->free($resql);
260	}
261	else
262	{
263		dol_print_error($db);
264	}
265
266	return 1;
267}
268
269?>