card.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Jean Heimburger <jean@tiaris.info>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/fourn/card.php
  26. * \ingroup fournisseur, facture
  27. * \brief Page for supplier third party card (view, edit)
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  36. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  37. $langs->load('companies');
  38. $langs->load('suppliers');
  39. $langs->load('products');
  40. $langs->load('bills');
  41. $langs->load('orders');
  42. $langs->load('commercial');
  43. $action = GETPOST('action');
  44. $cancelbutton = GETPOST('cancel');
  45. // Security check
  46. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  47. if ($user->societe_id) $id=$user->societe_id;
  48. $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe');
  49. $object = new Fournisseur($db);
  50. $extrafields = new ExtraFields($db);
  51. // fetch optionals attributes and labels
  52. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  53. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  54. $hookmanager->initHooks(array('suppliercard','globalcard'));
  55. /*
  56. * Action
  57. */
  58. $parameters=array('socid'=>$socid);
  59. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  60. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  61. if (empty($reshook))
  62. {
  63. if ($cancelbutton)
  64. {
  65. $action = "";
  66. }
  67. if ($action == 'setsupplieraccountancycode')
  68. {
  69. $result=$object->fetch($id);
  70. $object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
  71. $result=$object->update($object->id,$user,1,0,1);
  72. if ($result < 0)
  73. {
  74. $mesg=join(',',$object->errors);
  75. }
  76. }
  77. // conditions de reglement
  78. if ($action == 'setconditions' && $user->rights->societe->creer)
  79. {
  80. $object->fetch($id);
  81. $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int'));
  82. if ($result < 0) dol_print_error($db,$object->error);
  83. }
  84. // mode de reglement
  85. if ($action == 'setmode' && $user->rights->societe->creer)
  86. {
  87. $object->fetch($id);
  88. $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int'));
  89. if ($result < 0) dol_print_error($db,$object->error);
  90. }
  91. }
  92. /*
  93. * View
  94. */
  95. $contactstatic = new Contact($db);
  96. $form = new Form($db);
  97. if ($id > 0 && empty($object->id))
  98. {
  99. // Load data of third party
  100. $res=$object->fetch($id);
  101. if ($object->id <= 0) dol_print_error($db,$object->error);
  102. }
  103. if ($object->id > 0)
  104. {
  105. $title=$langs->trans("ThirdParty")." - ".$langs->trans('SupplierCard');
  106. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('SupplierCard');
  107. $help_url='';
  108. llxHeader('',$title, $help_url);
  109. /*
  110. * Show tabs
  111. */
  112. $head = societe_prepare_head($object);
  113. dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"),0,'company');
  114. dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
  115. print '<div class="fichecenter"><div class="fichehalfleft">';
  116. print '<div class="underbanner clearboth"></div>';
  117. print '<table width="100%" class="border">';
  118. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  119. {
  120. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  121. }
  122. if ($object->fournisseur)
  123. {
  124. print '<tr>';
  125. print '<td class="nowrap">'.$langs->trans("SupplierCode"). '</td><td colspan="3">';
  126. print $object->code_fournisseur;
  127. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  128. print '</td>';
  129. print '</tr>';
  130. $langs->load('compta');
  131. print '<tr>';
  132. print '<td>';
  133. print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  134. print '</td><td colspan="3">';
  135. print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  136. print '</td>';
  137. print '</tr>';
  138. }
  139. // Assujetti a TVA ou pas
  140. print '<tr>';
  141. print '<td class="nowrap">'.$langs->trans('VATIsUsed').'</td><td colspan="3">';
  142. print yn($object->tva_assuj);
  143. print '</td>';
  144. print '</tr>';
  145. // Local Taxes
  146. if ($mysoc->useLocalTax(1))
  147. {
  148. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  149. print yn($object->localtax1_assuj);
  150. print '</td></tr>';
  151. }
  152. if ($mysoc->useLocalTax(2))
  153. {
  154. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  155. print yn($object->localtax2_assuj);
  156. print '</td></tr>';
  157. }
  158. // TVA Intra
  159. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td colspan="3">';
  160. print $object->tva_intra;
  161. print '</td></tr>';
  162. // Conditions de reglement par defaut
  163. $langs->load('bills');
  164. $form = new Form($db);
  165. print '<tr><td>';
  166. print '<table width="100%" class="nobordernopadding"><tr><td>';
  167. print $langs->trans('PaymentConditions');
  168. print '<td>';
  169. if (($action != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
  170. print '</tr></table>';
  171. print '</td><td colspan="3">';
  172. if ($action == 'editconditions')
  173. {
  174. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'cond_reglement_supplier_id',-1,1);
  175. }
  176. else
  177. {
  178. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'none');
  179. }
  180. print "</td>";
  181. print '</tr>';
  182. // Mode de reglement par defaut
  183. print '<tr><td class="nowrap">';
  184. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  185. print $langs->trans('PaymentMode');
  186. print '<td>';
  187. if (($action != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  188. print '</tr></table>';
  189. print '</td><td colspan="3">';
  190. if ($action == 'editmode')
  191. {
  192. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'mode_reglement_supplier_id');
  193. }
  194. else
  195. {
  196. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'none');
  197. }
  198. print "</td>";
  199. print '</tr>';
  200. // Categories
  201. if (! empty($conf->categorie->enabled))
  202. {
  203. $langs->load("categories");
  204. print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
  205. print '<td colspan="3">';
  206. print $form->showCategories($object->id, 'supplier', 1);
  207. print "</td></tr>";
  208. }
  209. // Other attributes
  210. $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  211. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  212. print $hookmanager->resPrint;
  213. if (empty($reshook) && ! empty($extrafields->attribute_label))
  214. {
  215. print $object->showOptionals($extrafields);
  216. }
  217. // Module Adherent
  218. if (! empty($conf->adherent->enabled))
  219. {
  220. $langs->load("members");
  221. $langs->load("users");
  222. print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  223. print '<td colspan="3">';
  224. $adh=new Adherent($db);
  225. $result=$adh->fetch('','',$object->id);
  226. if ($result > 0)
  227. {
  228. $adh->ref=$adh->getFullName($langs);
  229. print $adh->getNomUrl(1);
  230. }
  231. else
  232. {
  233. print $langs->trans("ThirdpartyNotLinkedToMember");
  234. }
  235. print '</td>';
  236. print "</tr>\n";
  237. }
  238. print '</table>';
  239. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  240. $var=true;
  241. $MAXLIST=5;
  242. // Lien recap
  243. print '<table class="noborder" width="100%">';
  244. print '<tr class="liste_titre">';
  245. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
  246. print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
  247. print '</tr>';
  248. print '</table>';
  249. print '<br>';
  250. /*
  251. * List of products
  252. */
  253. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
  254. {
  255. $langs->load("products");
  256. print '<table class="noborder" width="100%">';
  257. print '<tr class="liste_titre">';
  258. print '<td colspan="2">'.$langs->trans("ProductsAndServices").'</td><td align="right">';
  259. print '<a href="'.DOL_URL_ROOT.'/fourn/product/list.php?fourn_id='.$object->id.'">'.$langs->trans("All").' <span class="badge">'.$object->nbOfProductRefs().'</span>';
  260. print '</a></td></tr>';
  261. //Query from product/liste.php
  262. $sql = 'SELECT p.rowid, p.ref, p.label, pfp.tms,';
  263. $sql.= ' p.fk_product_type, p.entity';
  264. $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
  265. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product";
  266. $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
  267. $sql.= ' AND pfp.fk_soc = '.$object->id;
  268. $sql .= $db->order('pfp.tms', 'desc');
  269. $sql.= $db->plimit($MAXLIST);
  270. $query = $db->query($sql);
  271. $return = array();
  272. if ($db->num_rows($query)) {
  273. $productstatic = new Product($db);
  274. while ($objp = $db->fetch_object($query)) {
  275. $var=!$var;
  276. $productstatic->id = $objp->rowid;
  277. $productstatic->ref = $objp->ref;
  278. $productstatic->label = $objp->label;
  279. $productstatic->type = $objp->fk_product_type;
  280. $productstatic->entity = $objp->entity;
  281. print "<tr ".$bc[$var].">";
  282. print '<td class="nowrap">';
  283. print $productstatic->getNomUrl(1);
  284. print '</td>';
  285. print '<td align="center">';
  286. print dol_trunc(dol_htmlentities($objp->label), 30);
  287. print '</td>';
  288. print '<td align="right" class="nowrap">'.dol_print_date($objp->tms).'</td>';
  289. print '</tr>';
  290. }
  291. }
  292. print '</table>';
  293. }
  294. /*
  295. * Last supplier proposal
  296. */
  297. $proposalstatic = new SupplierProposal($db);
  298. if ($user->rights->supplier_proposal->lire)
  299. {
  300. $sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total as total_ttc";
  301. $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p ";
  302. $sql.= " WHERE p.fk_soc =".$object->id;
  303. $sql.= " AND p.entity =".$conf->entity;
  304. $sql.= " ORDER BY p.date_valid DESC";
  305. $sql.= " ".$db->plimit($MAXLIST);
  306. $resql=$db->query($sql);
  307. if ($resql)
  308. {
  309. $i = 0 ;
  310. $num = $db->num_rows($resql);
  311. if ($num > 0)
  312. {
  313. print '<table class="noborder" width="100%">';
  314. print '<tr class="liste_titre">';
  315. print '<td colspan="3">';
  316. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierProposals",($num<$MAXLIST?"":$MAXLIST)).'</td>';
  317. print '<td align="right"><a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id.'">'.$langs->trans("AllPriceRequests").' <span class="badge">'.$num.'</span></td>';
  318. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/supplier_proposal/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  319. print '</tr></table>';
  320. print '</td></tr>';
  321. }
  322. $var = True;
  323. while ($i < $num && $i <= $MAXLIST)
  324. {
  325. $obj = $db->fetch_object($resql);
  326. $var=!$var;
  327. print "<tr ".$bc[$var].">";
  328. print '<td class="nowrap">';
  329. $proposalstatic->id = $obj->rowid;
  330. $proposalstatic->ref = $obj->ref;
  331. $proposalstatic->total_ht = $obj->total_ht;
  332. $proposalstatic->total_tva = $obj->total_tva;
  333. $proposalstatic->total_ttc = $obj->total_ttc;
  334. print $proposalstatic->getNomUrl(1);
  335. print '</td>';
  336. print '<td align="center" width="80">';
  337. if ($obj->dc)
  338. {
  339. print dol_print_date($db->jdate($obj->dc),'day');
  340. }
  341. else
  342. {
  343. print "-";
  344. }
  345. print '</td>';
  346. print '<td align="right" class="nowrap">'.$proposalstatic->LibStatut($obj->fk_statut,5).'</td>';
  347. print '</tr>';
  348. $i++;
  349. }
  350. $db->free($resql);
  351. if ($num >0) print "</table>";
  352. }
  353. else
  354. {
  355. dol_print_error($db);
  356. }
  357. }
  358. /*
  359. * Last supplier orders
  360. */
  361. $orderstatic = new CommandeFournisseur($db);
  362. if ($user->rights->fournisseur->commande->lire)
  363. {
  364. // TODO move to DAO class
  365. // Check if there are supplier orders billable
  366. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
  367. $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
  368. $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  369. $sql2.= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
  370. $sql2.= ' WHERE c.fk_soc = s.rowid';
  371. $sql2.= ' AND s.rowid = '.$object->id;
  372. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  373. $sql2.= " AND c.fk_statut IN (5)";
  374. $sql2.= " AND c.billed = 0";
  375. // Find order that are not already invoiced
  376. // just need to check received status because we have the billed status now
  377. //$sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
  378. $resql2=$db->query($sql2);
  379. if ($resql2) {
  380. $orders2invoice = $db->num_rows($resql2);
  381. $db->free($resql2);
  382. } else {
  383. setEventMessages($db->lasterror(), null, 'errors');
  384. }
  385. // TODO move to DAO class
  386. $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total_ttc";
  387. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
  388. $sql.= " WHERE p.fk_soc =".$object->id;
  389. $sql.= " AND p.entity =".$conf->entity;
  390. $sql.= " ORDER BY p.date_commande DESC";
  391. $sql.= " ".$db->plimit($MAXLIST);
  392. $resql=$db->query($sql);
  393. if ($resql)
  394. {
  395. $i = 0 ;
  396. $num = $db->num_rows($resql);
  397. if ($num > 0)
  398. {
  399. print '<table class="noborder" width="100%">';
  400. print '<tr class="liste_titre">';
  401. print '<td colspan="3">';
  402. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierOrders",($num<$MAXLIST?"":$MAXLIST)).'</td>';
  403. print '<td align="right"><a href="commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></td>';
  404. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  405. print '</tr></table>';
  406. print '</td></tr>';
  407. }
  408. $var = True;
  409. while ($i < $num && $i <= $MAXLIST)
  410. {
  411. $obj = $db->fetch_object($resql);
  412. $var=!$var;
  413. print "<tr ".$bc[$var].">";
  414. print '<td class="nowrap">';
  415. $orderstatic->id = $obj->rowid;
  416. $orderstatic->ref = $obj->ref;
  417. $orderstatic->total_ht = $obj->total_ht;
  418. $orderstatic->total_tva = $obj->total_tva;
  419. $orderstatic->total_ttc = $obj->total_ttc;
  420. print $orderstatic->getNomUrl(1);
  421. print '</td>';
  422. print '<td align="center" width="80">';
  423. if ($obj->dc)
  424. {
  425. print dol_print_date($db->jdate($obj->dc),'day');
  426. }
  427. else
  428. {
  429. print "-";
  430. }
  431. print '</td>';
  432. print '<td align="right" class="nowrap">'.$orderstatic->LibStatut($obj->fk_statut,5).'</td>';
  433. print '</tr>';
  434. $i++;
  435. }
  436. $db->free($resql);
  437. if ($num >0) print "</table>";
  438. }
  439. else
  440. {
  441. dol_print_error($db);
  442. }
  443. }
  444. /*
  445. * Last supplier invoices
  446. */
  447. $langs->load('bills');
  448. $facturestatic = new FactureFournisseur($db);
  449. if ($user->rights->fournisseur->facture->lire)
  450. {
  451. // TODO move to DAO class
  452. $sql = 'SELECT f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef as df, f.total_ht, f.total_tva, f.total_ttc as amount,f.paye,';
  453. $sql.= ' SUM(pf.amount) as am';
  454. $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
  455. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
  456. $sql.= ' WHERE f.fk_soc = '.$object->id;
  457. $sql.= " AND f.entity =".$conf->entity;
  458. $sql.= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye';
  459. $sql.= ' ORDER BY f.datef DESC';
  460. $resql=$db->query($sql);
  461. if ($resql)
  462. {
  463. $i = 0 ;
  464. $num = $db->num_rows($resql);
  465. if ($num > 0)
  466. {
  467. print '<table class="noborder" width="100%">';
  468. print '<tr class="liste_titre">';
  469. print '<td colspan="4">';
  470. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id.'">'.$langs->trans('AllBills').' <span class="badge">'.$num.'</span></td>';
  471. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  472. print '</tr></table>';
  473. print '</td></tr>';
  474. }
  475. $var=True;
  476. while ($i < min($num,$MAXLIST))
  477. {
  478. $obj = $db->fetch_object($resql);
  479. $var=!$var;
  480. print '<tr '.$bc[$var].'>';
  481. print '<td>';
  482. print '<a href="facture/card.php?facid='.$obj->rowid.'">';
  483. $facturestatic->id=$obj->rowid;
  484. $facturestatic->ref=($obj->ref?$obj->ref:$obj->rowid).($obj->ref_supplier?' - '.$obj->ref_supplier:'');
  485. $facturestatic->ref_supplier = $obj->ref_supplier;
  486. $facturestatic->total_ht = $obj->total_ht;
  487. $facturestatic->total_tva = $obj->total_tva;
  488. $facturestatic->total_ttc = $obj->total_ttc;
  489. //$facturestatic->ref_supplier=$obj->ref_supplier;
  490. print $facturestatic->getNomUrl(1);
  491. //print img_object($langs->trans('ShowBill'),'bill').' '.($obj->ref?$obj->ref:$obj->rowid).' - '.$obj->ref_supplier.'</a>';
  492. print ' '.dol_trunc($obj->libelle,14);
  493. print '</td>';
  494. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->df),'day').'</td>';
  495. print '<td align="right" class="nowrap">'.price($obj->amount).'</td>';
  496. print '<td align="right" class="nowrap">';
  497. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$obj->am);
  498. print '</td>';
  499. print '</tr>';
  500. $i++;
  501. }
  502. $db->free($resql);
  503. if ($num > 0) print '</table>';
  504. }
  505. else
  506. {
  507. dol_print_error($db);
  508. }
  509. }
  510. print '</div></div></div>';
  511. print '<div style="clear:both"></div>';
  512. dol_fiche_end();
  513. /*
  514. * Barre d'actions
  515. */
  516. print '<div class="tabsAction">';
  517. $parameters = array();
  518. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  519. // modified by hook
  520. if (empty($reshook))
  521. {
  522. if ($user->rights->fournisseur->commande->creer)
  523. {
  524. $langs->load("orders");
  525. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
  526. }
  527. if ($user->rights->fournisseur->facture->creer)
  528. {
  529. $langs->load("bills");
  530. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
  531. }
  532. if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer)
  533. {
  534. $langs->load("supplier_proposal");
  535. print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddSupplierProposal").'</a>';
  536. }
  537. if ($user->rights->fournisseur->facture->creer)
  538. {
  539. if (! empty($orders2invoice) && $orders2invoice > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  540. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  541. }
  542. // Add action
  543. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  544. {
  545. if ($user->rights->agenda->myactions->create)
  546. {
  547. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
  548. }
  549. else
  550. {
  551. print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
  552. }
  553. }
  554. }
  555. print '</div>';
  556. print '<br>';
  557. if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
  558. {
  559. print '<br>';
  560. // List of contacts
  561. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  562. }
  563. // Addresses list
  564. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  565. {
  566. $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  567. }
  568. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  569. {
  570. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  571. // List of todo actions
  572. show_actions_todo($conf,$langs,$db,$object);
  573. // List of done actions
  574. show_actions_done($conf,$langs,$db,$object);
  575. }
  576. }
  577. else
  578. {
  579. dol_print_error($db);
  580. }
  581. llxFooter();
  582. $db->close();