PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/facture/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 205 lines | 126 code | 34 blank | 45 comment | 26 complexity | 3f4cd044e6b91afc08dfda0f2d018b73 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-2009 Destailleur Laurent <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/facture/contact.php
  22. * \ingroup facture
  23. * \brief Onglet de gestion des contacts des factures
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. $langs->load("bills");
  32. $langs->load("companies");
  33. $id = (GETPOST('id')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  34. $ref = GETPOST('ref','alpha');
  35. $lineid = GETPOST('lineid','int');
  36. $socid = GETPOST('socid','int');
  37. $action = GETPOST('action','alpha');
  38. // Security check
  39. if ($user->societe_id) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'facture', $id);
  41. $object = new Facture($db);
  42. /*
  43. * Ajout d'un nouveau contact
  44. */
  45. if ($action == 'addcontact' && $user->rights->facture->creer)
  46. {
  47. $result = $object->fetch($id);
  48. if ($result > 0 && $id > 0)
  49. {
  50. $contactid = (GETPOST('userid') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  51. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  52. }
  53. if ($result >= 0)
  54. {
  55. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  56. exit;
  57. }
  58. else
  59. {
  60. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  61. {
  62. $langs->load("errors");
  63. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  64. }
  65. else
  66. {
  67. $mesg = '<div class="error">'.$object->error.'</div>';
  68. }
  69. }
  70. }
  71. // bascule du statut d'un contact
  72. else if ($action == 'swapstatut' && $user->rights->facture->creer)
  73. {
  74. if ($object->fetch($id))
  75. {
  76. $result=$object->swapContactStatus(GETPOST('ligne'));
  77. }
  78. else
  79. {
  80. dol_print_error($db);
  81. }
  82. }
  83. // Efface un contact
  84. else if ($action == 'deletecontact' && $user->rights->facture->creer)
  85. {
  86. $object->fetch($id);
  87. $result = $object->delete_contact($lineid);
  88. if ($result >= 0)
  89. {
  90. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  91. exit;
  92. }
  93. else {
  94. dol_print_error($db);
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. llxHeader('', $langs->trans("Bill"), "Facture");
  101. $form = new Form($db);
  102. $formcompany = new FormCompany($db);
  103. $contactstatic=new Contact($db);
  104. $userstatic=new User($db);
  105. /* *************************************************************************** */
  106. /* */
  107. /* Mode vue et edition */
  108. /* */
  109. /* *************************************************************************** */
  110. dol_htmloutput_mesg($mesg);
  111. if ($id > 0 || ! empty($ref))
  112. {
  113. if ($object->fetch($id, $ref) > 0)
  114. {
  115. $object->fetch_thirdparty();
  116. $head = facture_prepare_head($object);
  117. dol_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), 0, 'bill');
  118. /*
  119. * Facture synthese pour rappel
  120. */
  121. print '<table class="border" width="100%">';
  122. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  123. // Ref
  124. print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
  125. print '<td colspan="3">';
  126. $morehtmlref='';
  127. $discount=new DiscountAbsolute($db);
  128. $result=$discount->fetch(0,$object->id);
  129. if ($result > 0)
  130. {
  131. $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
  132. }
  133. if ($result < 0)
  134. {
  135. dol_print_error('',$discount->error);
  136. }
  137. print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
  138. print '</td></tr>';
  139. // Ref customer
  140. print '<tr><td width="20%">';
  141. print '<table class="nobordernopadding" width="100%"><tr><td>';
  142. print $langs->trans('RefCustomer');
  143. print '</td>';
  144. print '</tr></table>';
  145. print '</td>';
  146. print '<td colspan="5">';
  147. print $object->ref_client;
  148. print '</td></tr>';
  149. // Customer
  150. print "<tr><td>".$langs->trans("Company")."</td>";
  151. print '<td colspan="3">'.$object->client->getNomUrl(1,'compta').'</td></tr>';
  152. print "</table>";
  153. print '</div>';
  154. print '<br>';
  155. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  156. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  157. foreach($dirtpls as $reldir)
  158. {
  159. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  160. if ($res) break;
  161. }
  162. }
  163. else
  164. {
  165. // Record not found
  166. print "ErrorRecordNotFound";
  167. }
  168. }
  169. llxFooter();
  170. $db->close();
  171. ?>