PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.0
  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. * \file htdocs/core/lib/sendings.lib.php
  19. * \ingroup expedition
  20. * \brief Library for expedition module
  21. */
  22. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  23. require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php");
  24. function shipping_prepare_head($object)
  25. {
  26. global $langs, $conf, $user;
  27. $langs->load("sendings");
  28. $langs->load("deliveries");
  29. $h = 0;
  30. $head = array();
  31. $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->id;
  32. $head[$h][1] = $langs->trans("SendingCard");
  33. $head[$h][2] = 'shipping';
  34. $h++;
  35. if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && ! empty($object->linkedObjectsIds['delivery'][0]))
  36. {
  37. $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0];
  38. $head[$h][1] = $langs->trans("DeliveryCard");
  39. $head[$h][2] = 'delivery';
  40. $h++;
  41. }
  42. // Show more tabs from modules
  43. // Entries must be declared in modules descriptor with line
  44. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  45. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  46. complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
  47. return $head;
  48. }
  49. function delivery_prepare_head($object)
  50. {
  51. global $langs, $conf, $user;
  52. $langs->load("sendings");
  53. $langs->load("deliveries");
  54. $h = 0;
  55. $head = array();
  56. if ($conf->expedition_bon->enabled && $user->rights->expedition->lire)
  57. {
  58. $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->origin_id;
  59. $head[$h][1] = $langs->trans("SendingCard");
  60. $head[$h][2] = 'shipping';
  61. $h++;
  62. }
  63. $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->id;
  64. $head[$h][1] = $langs->trans("DeliveryCard");
  65. $head[$h][2] = 'delivery';
  66. $h++;
  67. // Show more tabs from modules
  68. // Entries must be declared in modules descriptor with line
  69. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  70. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  71. complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
  72. return $head;
  73. }
  74. /**
  75. * List sendings and receive receipts
  76. *
  77. * @param string $origin Origin
  78. * @param int $origin_id Origin id
  79. * @param string $filter Filter
  80. * @return
  81. */
  82. function show_list_sending_receive($origin='commande',$origin_id,$filter='')
  83. {
  84. global $db, $conf, $langs, $bc;
  85. global $form;
  86. $product_static=new Product($db);
  87. $expedition=new Expedition($db);
  88. $sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked";
  89. $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line";
  90. $sql.= ", e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
  91. //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
  92. $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,';
  93. $sql.= ' p.description as product_desc';
  94. $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  95. $sql.= ", ".MAIN_DB_PREFIX."expedition as e";
  96. $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  97. //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";
  98. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  99. $sql.= " WHERE obj.fk_".$origin." = ".$origin_id;
  100. if ($filter) $sql.=$filter;
  101. $sql.= " AND obj.rowid = ed.fk_origin_line";
  102. $sql.= " AND ed.fk_expedition = e.rowid";
  103. $sql.= " ORDER BY obj.fk_product";
  104. dol_syslog("show_list_sending_receive sql=".$sql, LOG_DEBUG);
  105. $resql = $db->query($sql);
  106. if ($resql)
  107. {
  108. $num = $db->num_rows($resql);
  109. $i = 0;
  110. if ($num)
  111. {
  112. if ($somethingshown) print '<br>';
  113. if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder"));
  114. else print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
  115. print '<table class="liste" width="100%">';
  116. print '<tr class="liste_titre">';
  117. //print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
  118. print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
  119. print '<td align="left">'.$langs->trans("Description").'</td>';
  120. print '<td align="center">'.$langs->trans("DateCreation").'</td>';
  121. print '<td align="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
  122. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  123. if ($conf->livraison_bon->enabled)
  124. {
  125. print '<td>'.$langs->trans("DeliveryOrder").'</td>';
  126. //print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
  127. print '<td align="right">'.$langs->trans("DeliveryDate").'</td>';
  128. }
  129. print "</tr>\n";
  130. $var=True;
  131. while ($i < $num)
  132. {
  133. $var=!$var;
  134. $objp = $db->fetch_object($resql);
  135. print "<tr $bc[$var]>";
  136. // Sending id
  137. 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>';
  138. // Description
  139. if ($objp->fk_product > 0)
  140. {
  141. print '<td>';
  142. // Show product and description
  143. $product_static->type=$objp->fk_product_type;
  144. $product_static->id=$objp->fk_product;
  145. $product_static->ref=$objp->ref;
  146. $product_static->libelle=$objp->product;
  147. $text=$product_static->getNomUrl(1);
  148. $text.= ' - '.$objp->product;
  149. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description));
  150. print $form->textwithtooltip($text,$description,3,'','',$i);
  151. // Show range
  152. print_date_range($objp->date_start,$objp->date_end);
  153. // Add description in form
  154. if ($conf->global->PRODUIT_DESC_IN_FORM)
  155. {
  156. print ($objp->description && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
  157. }
  158. print '</td>';
  159. }
  160. else
  161. {
  162. print "<td>";
  163. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  164. else $text = img_object($langs->trans('Product'),'product');
  165. print $text.' '.nl2br($objp->description);
  166. // Show range
  167. print_date_range($objp->date_start,$objp->date_end);
  168. print "</td>\n";
  169. }
  170. //print '<td align="center">'.$objp->qty_asked.'</td>';
  171. // Date creation
  172. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
  173. // Date shipping creation
  174. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_delivery),'day').'</td>';
  175. // Qty shipped
  176. print '<td align="center">'.$objp->qty_shipped.'</td>';
  177. // Informations on receipt
  178. if ($conf->livraison_bon->enabled)
  179. {
  180. include_once(DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php');
  181. $expedition->id=$objp->sendingid;
  182. $expedition->fetchObjectLinked($expedition->id,$expedition->element);
  183. //var_dump($expedition->linkedObjects);
  184. $receiving=$expedition->linkedObjects['delivery'][0];
  185. if (! empty($receiving))
  186. {
  187. // $expedition->fk_origin_line = id of det line of order
  188. // $receiving->fk_origin_line = id of det line of order
  189. // $receiving->origin may be 'shipping'
  190. // $receiving->origin_id may be id of shipping
  191. // Ref
  192. print '<td>';
  193. print $receiving->getNomUrl($db);
  194. //print '<a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
  195. print '</td>';
  196. // Qty received
  197. //print '<td align="center">';
  198. // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
  199. // so no way to know the qty received for this line of shipping.
  200. //print $langs->trans("FeatureNotYetAvailable");
  201. //print '</td>';
  202. // Date shipping real
  203. print '<td align="right">';
  204. print dol_print_date($receiving->date_delivery,'day');
  205. print '</td>';
  206. }
  207. else
  208. {
  209. //print '<td>&nbsp;</td>';
  210. print '<td>&nbsp;</td>';
  211. print '<td>&nbsp;</td>';
  212. }
  213. }
  214. print '</tr>';
  215. $i++;
  216. }
  217. print '</table>';
  218. }
  219. $db->free($resql);
  220. }
  221. else
  222. {
  223. dol_print_error($db);
  224. }
  225. return 1;
  226. }
  227. ?>