PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fourn/facture/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 178 lines | 101 code | 34 blank | 43 comment | 23 complexity | cb1fd5ce64cad10ceac908e2309b345d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fourn/facture/contact.php
  21. * \ingroup facture, fournisseur
  22. * \brief Onglet de gestion des contacts des factures
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. $langs->load("bills");
  31. $langs->load('other');
  32. $langs->load("companies");
  33. $id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('facid','int'));
  34. $ref = GETPOST('ref','alpha');
  35. $action = GETPOST('action','alpha');
  36. // Security check
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  39. $object = new FactureFournisseur($db);
  40. /*
  41. * Ajout d'un nouveau contact
  42. */
  43. if ($action == 'addcontact' && $user->rights->fournisseur->facture->creer)
  44. {
  45. $result = $object->fetch($id);
  46. if ($result > 0 && $id > 0)
  47. {
  48. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  49. $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  50. }
  51. if ($result >= 0)
  52. {
  53. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  54. exit;
  55. }
  56. else
  57. {
  58. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  59. {
  60. $langs->load("errors");
  61. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  62. }
  63. else
  64. {
  65. $mesg = '<div class="error">'.$object->error.'</div>';
  66. }
  67. }
  68. }
  69. // bascule du statut d'un contact
  70. else if ($action == 'swapstatut' && $user->rights->fournisseur->facture->creer)
  71. {
  72. if ($object->fetch($id))
  73. {
  74. $result=$object->swapContactStatus(GETPOST('ligne'));
  75. }
  76. else
  77. {
  78. dol_print_error($db);
  79. }
  80. }
  81. // Efface un contact
  82. else if ($action == 'deletecontact' && $user->rights->fournisseur->facture->creer)
  83. {
  84. $object->fetch($id);
  85. $result = $object->delete_contact($_GET["lineid"]);
  86. if ($result >= 0)
  87. {
  88. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  89. exit;
  90. }
  91. else {
  92. dol_print_error($db);
  93. }
  94. }
  95. /*
  96. * View
  97. */
  98. llxHeader('', $langs->trans("Bill"), "Facture");
  99. $form = new Form($db);
  100. $formcompany = new FormCompany($db);
  101. $contactstatic=new Contact($db);
  102. $userstatic=new User($db);
  103. /* *************************************************************************** */
  104. /* */
  105. /* Mode vue et edition */
  106. /* */
  107. /* *************************************************************************** */
  108. dol_htmloutput_mesg($mesg);
  109. if ($id > 0 || ! empty($ref))
  110. {
  111. if ($object->fetch($id, $ref) > 0)
  112. {
  113. $object->fetch_thirdparty();
  114. $head = facturefourn_prepare_head($object);
  115. dol_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), 0, 'bill');
  116. /*
  117. * Facture synthese pour rappel
  118. */
  119. print '<table class="border" width="100%">';
  120. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  121. // Reference du facture
  122. print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
  123. print $form->showrefnav($object, 'facid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  124. print "</td></tr>";
  125. // Ref supplier
  126. print '<tr><td nowrap="nowrap">'.$langs->trans("RefSupplier").'</td><td colspan="3">'.$object->ref_supplier.'</td>';
  127. print "</tr>\n";
  128. // Third party
  129. print "<tr><td>".$langs->trans("Supplier")."</td>";
  130. print '<td colspan="3">'.$object->client->getNomUrl(1,'compta').'</td></tr>';
  131. print "</table>";
  132. print '</div>';
  133. print '<br>';
  134. // Contacts lines
  135. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  136. }
  137. else
  138. {
  139. print "ErrorRecordNotFound";
  140. }
  141. }
  142. llxFooter();
  143. $db->close();
  144. ?>