PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fourn/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 432 lines | 302 code | 65 blank | 65 comment | 40 complexity | 3689c897a2fccca3a6eb8384b0caa4ae MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/fourn/fiche.php
  23. * \ingroup fournisseur, facture
  24. * \brief Page for supplier third party card (view, edit)
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  32. $langs->load('suppliers');
  33. $langs->load('products');
  34. $langs->load('bills');
  35. $langs->load('orders');
  36. $langs->load('companies');
  37. $langs->load('commercial');
  38. $action = GETPOST('action');
  39. // Security check
  40. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  41. if ($user->societe_id) $id=$user->societe_id;
  42. $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe');
  43. $object = new Fournisseur($db);
  44. /*
  45. * Action
  46. */
  47. if ($action == 'setsupplieraccountancycode')
  48. {
  49. $result=$object->fetch($id);
  50. $object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
  51. $result=$object->update($object->id,$user,1,0,1);
  52. if ($result < 0)
  53. {
  54. $mesg=join(',',$object->errors);
  55. }
  56. $action="";
  57. }
  58. /*
  59. * View
  60. */
  61. $contactstatic = new Contact($db);
  62. $form = new Form($db);
  63. if ($object->fetch($id))
  64. {
  65. llxHeader('',$langs->trans('SupplierCard'));
  66. /*
  67. * Affichage onglets
  68. */
  69. $head = societe_prepare_head($object);
  70. dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"),0,'company');
  71. print '<table width="100%" class="notopnoleftnoright">';
  72. print '<tr><td valign="top" width="50%" class="notopnoleft">';
  73. print '<table width="100%" class="border">';
  74. print '<tr><td width="20%">'.$langs->trans("ThirdPartyName").'</td><td width="80%" colspan="3">';
  75. $object->next_prev_filter="te.fournisseur = 1";
  76. print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','','');
  77. print '</td></tr>';
  78. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  79. {
  80. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  81. }
  82. if ($object->fournisseur)
  83. {
  84. print '<tr>';
  85. print '<td nowrap="nowrap">'.$langs->trans("SupplierCode"). '</td><td colspan="3">';
  86. print $object->code_fournisseur;
  87. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  88. print '</td>';
  89. print '</tr>';
  90. print '<tr>';
  91. print '<td>';
  92. print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  93. print '</td><td colspan="3">';
  94. print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  95. print '</td>';
  96. print '</tr>';
  97. }
  98. // Address
  99. print '<tr><td valign="top">'.$langs->trans("Address").'</td><td colspan="3">';
  100. dol_print_address($object->address,'gmap','thirdparty',$object->id);
  101. print '</td></tr>';
  102. // Zip / Town
  103. print '<tr><td nowrap="nowrap">'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'</td>';
  104. print '</tr>';
  105. // Country
  106. print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
  107. $img=picto_from_langcode($object->country_code);
  108. if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0);
  109. else print ($img?$img.' ':'').$object->country;
  110. print '</td></tr>';
  111. // Phone
  112. print '<tr><td>'.$langs->trans("Phone").'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->country_code,0,$object->id,'AC_TEL').'</td>';
  113. // Fax
  114. print '<td>'.$langs->trans("Fax").'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'</td></tr>';
  115. // EMail
  116. print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($object->email,0,$object->id,'AC_EMAIL').'</td></tr>';
  117. // Web
  118. print '<tr><td>'.$langs->trans("Web")."</td><td colspan=\"3\">".dol_print_url($object->url)."</td></tr>";
  119. // Assujetti a TVA ou pas
  120. print '<tr>';
  121. print '<td nowrap="nowrap">'.$langs->trans('VATIsUsed').'</td><td colspan="3">';
  122. print yn($object->tva_assuj);
  123. print '</td>';
  124. print '</tr>';
  125. // Local Taxes
  126. if($mysoc->country_code=='ES')
  127. {
  128. if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
  129. {
  130. print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax1IsUsedES').'</td><td colspan="3">';
  131. print yn($object->localtax1_assuj);
  132. print '</td></tr>';
  133. print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax2IsUsedES').'</td><td colspan="3">';
  134. print yn($object->localtax2_assuj);
  135. print '</td></tr>';
  136. }
  137. elseif($mysoc->localtax1_assuj=="1")
  138. {
  139. print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
  140. print yn($object->localtax1_assuj);
  141. print '</td></tr>';
  142. }
  143. elseif($mysoc->localtax2_assuj=="1")
  144. {
  145. print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
  146. print yn($object->localtax2_assuj);
  147. print '</td></tr>';
  148. }
  149. }
  150. // TVA Intra
  151. print '<tr><td nowrap>'.$langs->trans('VATIntra').'</td><td colspan="3">';
  152. print $object->tva_intra;
  153. print '</td></tr>';
  154. // Module Adherent
  155. if (! empty($conf->adherent->enabled))
  156. {
  157. $langs->load("members");
  158. $langs->load("users");
  159. print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToSpeedealingMember").'</td>';
  160. print '<td colspan="3">';
  161. $adh=new Adherent($db);
  162. $result=$adh->fetch('','',$object->id);
  163. if ($result > 0)
  164. {
  165. $adh->ref=$adh->getFullName($langs);
  166. print $adh->getNomUrl(1);
  167. }
  168. else
  169. {
  170. print $langs->trans("UserNotLinkedToMember");
  171. }
  172. print '</td>';
  173. print "</tr>\n";
  174. }
  175. print '</table>';
  176. print '</td><td valign="top" width="50%" class="notopnoleftnoright">';
  177. $var=true;
  178. $MAXLIST=5;
  179. // Lien recap
  180. print '<table class="noborder" width="100%">';
  181. print '<tr class="liste_titre">';
  182. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
  183. print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
  184. print '</tr>';
  185. print '</table>';
  186. /*
  187. * List of products
  188. */
  189. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
  190. {
  191. $langs->load("products");
  192. print '<table class="noborder" width="100%">';
  193. print '<tr class="liste_titre">';
  194. print '<td>'.$langs->trans("ProductsAndServices").'</td><td align="right">';
  195. print '<a href="'.DOL_URL_ROOT.'/fourn/product/liste.php?fourn_id='.$object->id.'">'.$langs->trans("All").' ('.$object->nbOfProductRefs().')';
  196. print '</a></td></tr></table>';
  197. }
  198. print '<br>';
  199. /*
  200. * Last orders
  201. */
  202. $orderstatic = new CommandeFournisseur($db);
  203. if ($user->rights->fournisseur->commande->lire)
  204. {
  205. // TODO move to DAO class
  206. $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut";
  207. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
  208. $sql.= " WHERE p.fk_soc =".$object->id;
  209. $sql.= " ORDER BY p.date_commande DESC";
  210. $sql.= " ".$db->plimit($MAXLIST);
  211. $resql=$db->query($sql);
  212. if ($resql)
  213. {
  214. $i = 0 ;
  215. $num = $db->num_rows($resql);
  216. if ($num > 0)
  217. {
  218. print '<table class="noborder" width="100%">';
  219. print '<tr class="liste_titre">';
  220. print '<td colspan="3">';
  221. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastOrders",($num<$MAXLIST?"":$MAXLIST)).'</td>';
  222. print '<td align="right"><a href="commande/liste.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' ('.$num.')</td>';
  223. 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>';
  224. print '</tr></table>';
  225. print '</td></tr>';
  226. }
  227. while ($i < $num && $i <= $MAXLIST)
  228. {
  229. $obj = $db->fetch_object($resql);
  230. $var=!$var;
  231. print "<tr $bc[$var]>";
  232. print '<td><a href="commande/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref.'</a></td>';
  233. print '<td align="center" width="80">';
  234. if ($obj->dc)
  235. {
  236. print dol_print_date($db->jdate($obj->dc),'day');
  237. }
  238. else
  239. {
  240. print "-";
  241. }
  242. print '</td>';
  243. print '<td align="right" nowrap="nowrap">'.$orderstatic->LibStatut($obj->fk_statut,5).'</td>';
  244. print '</tr>';
  245. $i++;
  246. }
  247. $db->free($resql);
  248. if ($num >0) print "</table>";
  249. }
  250. else
  251. {
  252. dol_print_error($db);
  253. }
  254. }
  255. /*
  256. * Last invoices
  257. */
  258. $MAXLIST=5;
  259. $langs->load('bills');
  260. $facturestatic = new FactureFournisseur($db);
  261. if ($user->rights->fournisseur->facture->lire)
  262. {
  263. // TODO move to DAO class
  264. $sql = 'SELECT f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef as df,f.total_ttc as amount,f.paye,';
  265. $sql.= ' SUM(pf.amount) as am';
  266. $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
  267. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
  268. $sql.= ' WHERE f.fk_soc = '.$object->id;
  269. $sql.= ' GROUP BY f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef,f.total_ttc,f.paye';
  270. $sql.= ' ORDER BY f.datef DESC';
  271. $resql=$db->query($sql);
  272. if ($resql)
  273. {
  274. $i = 0 ;
  275. $num = $db->num_rows($resql);
  276. if ($num > 0)
  277. {
  278. print '<table class="noborder" width="100%">';
  279. print '<tr class="liste_titre">';
  280. print '<td colspan="4">';
  281. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="facture/index.php?socid='.$object->id.'">'.$langs->trans('AllBills').' ('.$num.')</td>';
  282. 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>';
  283. print '</tr></table>';
  284. print '</td></tr>';
  285. }
  286. while ($i < min($num,$MAXLIST))
  287. {
  288. $obj = $db->fetch_object($resql);
  289. $var=!$var;
  290. print '<tr '.$bc[$var].'>';
  291. print '<td>';
  292. print '<a href="facture/fiche.php?facid='.$obj->rowid.'">';
  293. print img_object($langs->trans('ShowBill'),'bill').' '.$obj->facnumber.'</a> '.dol_trunc($obj->libelle,14).'</td>';
  294. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($obj->df),'day').'</td>';
  295. print '<td align="right" nowrap="nowrap">'.price($obj->amount).'</td>';
  296. print '<td align="right" nowrap="nowrap">';
  297. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$obj->am);
  298. print '</td>';
  299. print '</tr>';
  300. $i++;
  301. }
  302. $db->free($resql);
  303. if ($num > 0) print '</table>';
  304. }
  305. else
  306. {
  307. dol_print_error($db);
  308. }
  309. }
  310. print '</td></tr>';
  311. print '</table>' . "\n";
  312. print '</div>';
  313. /*
  314. * Barre d'actions
  315. */
  316. print '<div class="tabsAction">';
  317. if ($user->rights->fournisseur->commande->creer)
  318. {
  319. $langs->load("orders");
  320. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
  321. }
  322. if ($user->rights->fournisseur->facture->creer)
  323. {
  324. $langs->load("bills");
  325. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
  326. }
  327. // Add action
  328. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  329. {
  330. if ($user->rights->agenda->myactions->create)
  331. {
  332. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
  333. }
  334. else
  335. {
  336. print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
  337. }
  338. }
  339. print '</div>';
  340. print '<br>';
  341. if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
  342. {
  343. print '<br>';
  344. // List of contacts
  345. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?id='.$object->id);
  346. }
  347. // Addresses list
  348. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  349. {
  350. $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  351. }
  352. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  353. {
  354. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  355. // List of todo actions
  356. show_actions_todo($conf,$langs,$db,$object);
  357. // List of done actions
  358. show_actions_done($conf,$langs,$db,$object);
  359. }
  360. }
  361. else
  362. {
  363. dol_print_error($db);
  364. }
  365. llxFooter();
  366. $db->close();
  367. ?>