sendings.lib.php 12 KB

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