PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/speedealing/speedealing
PHP | 320 lines | 194 code | 46 blank | 80 comment | 27 complexity | bffd4f0e710ea86e067ffea8512e3e4f MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2008-2012 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 3 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. /**
  25. * Prepare array with list of tabs
  26. *
  27. * @param Object $object Object related to tabs
  28. * @return array Array of tabs to shoc
  29. */
  30. function shipping_prepare_head($object)
  31. {
  32. global $langs, $conf, $user;
  33. $langs->load("sendings");
  34. $langs->load("deliveries");
  35. $h = 0;
  36. $head = array();
  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. if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)
  42. {
  43. // delivery link
  44. $object->fetchObjectLinked($object->id,$object->element);
  45. if (! empty($object->linkedObjectsIds['delivery'][0]))
  46. {
  47. $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0];
  48. $head[$h][1] = $langs->trans("DeliveryCard");
  49. $head[$h][2] = 'delivery';
  50. $h++;
  51. }
  52. }
  53. $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id;
  54. $head[$h][1] = $langs->trans("ContactsAddresses");
  55. $head[$h][2] = 'contact';
  56. $h++;
  57. // Show more tabs from modules
  58. // Entries must be declared in modules descriptor with line
  59. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  60. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  61. complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
  62. return $head;
  63. }
  64. /**
  65. * Prepare array with list of tabs
  66. *
  67. * @param Object $object Object related to tabs
  68. * @return array Array of tabs to shoc
  69. */
  70. function delivery_prepare_head($object)
  71. {
  72. global $langs, $conf, $user;
  73. $langs->load("sendings");
  74. $langs->load("deliveries");
  75. $h = 0;
  76. $head = array();
  77. if ($conf->expedition_bon->enabled && $user->rights->expedition->lire)
  78. {
  79. $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->origin_id;
  80. $head[$h][1] = $langs->trans("SendingCard");
  81. $head[$h][2] = 'shipping';
  82. $h++;
  83. }
  84. $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->id;
  85. $head[$h][1] = $langs->trans("DeliveryCard");
  86. $head[$h][2] = 'delivery';
  87. $h++;
  88. // Show more tabs from modules
  89. // Entries must be declared in modules descriptor with line
  90. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  91. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  92. complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
  93. return $head;
  94. }
  95. /**
  96. * List sendings and receive receipts
  97. *
  98. * @param string $origin Origin ('commande', ...)
  99. * @param int $origin_id Origin id
  100. * @param string $filter Filter
  101. * @return int <0 if KO, >0 if OK
  102. */
  103. function show_list_sending_receive($origin,$origin_id,$filter='')
  104. {
  105. global $db, $conf, $langs, $bc;
  106. global $form;
  107. $product_static=new Product($db);
  108. $expedition=new Expedition($db);
  109. $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked";
  110. $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line";
  111. $sql.= ", e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
  112. //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
  113. $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
  114. $sql.= ' p.description as product_desc';
  115. $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  116. $sql.= ", ".MAIN_DB_PREFIX."expedition as e";
  117. $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  118. //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";
  119. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  120. $sql.= " WHERE e.entity = ".$conf->entity;
  121. $sql.= " AND obj.fk_".$origin." = ".$origin_id;
  122. $sql.= " AND obj.rowid = ed.fk_origin_line";
  123. $sql.= " AND ed.fk_expedition = e.rowid";
  124. if ($filter) $sql.= $filter;
  125. $sql.= " ORDER BY obj.fk_product";
  126. dol_syslog("show_list_sending_receive sql=".$sql, LOG_DEBUG);
  127. $resql = $db->query($sql);
  128. if ($resql)
  129. {
  130. $num = $db->num_rows($resql);
  131. $i = 0;
  132. if ($num)
  133. {
  134. if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder"));
  135. else print_titre($langs->trans("SendingsAndReceivingForSameOrder"));
  136. print '<table class="liste" width="100%">';
  137. print '<tr class="liste_titre">';
  138. //print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
  139. print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
  140. print '<td align="left">'.$langs->trans("Description").'</td>';
  141. print '<td align="center">'.$langs->trans("DateCreation").'</td>';
  142. print '<td align="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
  143. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  144. if ($conf->livraison_bon->enabled)
  145. {
  146. print '<td>'.$langs->trans("DeliveryOrder").'</td>';
  147. //print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
  148. print '<td align="right">'.$langs->trans("DeliveryDate").'</td>';
  149. }
  150. print "</tr>\n";
  151. $var=True;
  152. while ($i < $num)
  153. {
  154. $var=!$var;
  155. $objp = $db->fetch_object($resql);
  156. print "<tr $bc[$var]>";
  157. // Sending id
  158. 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>';
  159. // Description
  160. if ($objp->fk_product > 0)
  161. {
  162. // Define output language
  163. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  164. {
  165. $object = new $origin($db);
  166. $object->fetch($origin_id);
  167. $object->fetch_thirdparty();
  168. $prod = new Product($db, $objp->fk_product);
  169. $outputlangs = $langs;
  170. $newlang='';
  171. if (empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  172. if (empty($newlang)) $newlang=$object->client->default_lang;
  173. if (! empty($newlang))
  174. {
  175. $outputlangs = new Translate();
  176. $outputlangs->setDefaultLang($newlang);
  177. }
  178. $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
  179. }
  180. else
  181. {
  182. $label = (! empty($objp->label)?$objp->label:$objp->product_label);
  183. }
  184. print '<td>';
  185. // Show product and description
  186. $product_static->type=$objp->fk_product_type;
  187. $product_static->id=$objp->fk_product;
  188. $product_static->ref=$objp->ref;
  189. $text=$product_static->getNomUrl(1);
  190. $text.= ' - '.$label;
  191. $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description));
  192. print $form->textwithtooltip($text,$description,3,'','',$i);
  193. // Show range
  194. print_date_range($objp->date_start,$objp->date_end);
  195. // Add description in form
  196. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  197. {
  198. print (! empty($objp->description) && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
  199. }
  200. print '</td>';
  201. }
  202. else
  203. {
  204. print "<td>";
  205. if ($objp->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
  206. else $text = img_object($langs->trans('Product'),'product');
  207. if (! empty($objp->label)) {
  208. $text.= ' <strong>'.$objp->label.'</strong>';
  209. print $form->textwithtooltip($text,$objp->description,3,'','',$i);
  210. } else {
  211. print $text.' '.nl2br($objp->description);
  212. }
  213. // Show range
  214. print_date_range($objp->date_start,$objp->date_end);
  215. print "</td>\n";
  216. }
  217. //print '<td align="center">'.$objp->qty_asked.'</td>';
  218. // Date creation
  219. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
  220. // Date shipping creation
  221. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($objp->date_delivery),'day').'</td>';
  222. // Qty shipped
  223. print '<td align="center">'.$objp->qty_shipped.'</td>';
  224. // Informations on receipt
  225. if ($conf->livraison_bon->enabled)
  226. {
  227. include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
  228. $expedition->id=$objp->sendingid;
  229. $expedition->fetchObjectLinked($expedition->id,$expedition->element);
  230. //var_dump($expedition->linkedObjects);
  231. $receiving=$expedition->linkedObjects['delivery'][0];
  232. if (! empty($receiving))
  233. {
  234. // $expedition->fk_origin_line = id of det line of order
  235. // $receiving->fk_origin_line = id of det line of order
  236. // $receiving->origin may be 'shipping'
  237. // $receiving->origin_id may be id of shipping
  238. // Ref
  239. print '<td>';
  240. print $receiving->getNomUrl($db);
  241. //print '<a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
  242. print '</td>';
  243. // Qty received
  244. //print '<td align="center">';
  245. // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
  246. // so no way to know the qty received for this line of shipping.
  247. //print $langs->trans("FeatureNotYetAvailable");
  248. //print '</td>';
  249. // Date shipping real
  250. print '<td align="right">';
  251. print dol_print_date($receiving->date_delivery,'day');
  252. print '</td>';
  253. }
  254. else
  255. {
  256. //print '<td>&nbsp;</td>';
  257. print '<td>&nbsp;</td>';
  258. print '<td>&nbsp;</td>';
  259. }
  260. }
  261. print '</tr>';
  262. $i++;
  263. }
  264. print '</table>';
  265. }
  266. $db->free($resql);
  267. }
  268. else
  269. {
  270. dol_print_error($db);
  271. }
  272. return 1;
  273. }
  274. ?>