contact.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  6. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  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 <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/fourn/facture/contact.php
  23. * \ingroup facture, fournisseur
  24. * \brief Onglet de gestion des contacts des factures
  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/fourn.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. if (!empty($conf->projet->enabled)) {
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. }
  35. $langs->loadLangs(array("bills", "other", "companies"));
  36. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. // Security check
  40. if ($user->socid) {
  41. $socid = $user->socid;
  42. }
  43. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  44. $hookmanager->initHooks(array('invoicesuppliercardcontact'));
  45. $object = new FactureFournisseur($db);
  46. /*
  47. * Ajout d'un nouveau contact
  48. */
  49. if ($action == 'addcontact' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  50. $result = $object->fetch($id, $ref);
  51. if ($result > 0 && $id > 0) {
  52. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  53. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  54. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  55. }
  56. if ($result >= 0) {
  57. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  58. exit;
  59. } else {
  60. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  61. $langs->load("errors");
  62. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  63. } else {
  64. setEventMessages($object->error, $object->errors, 'errors');
  65. }
  66. }
  67. } elseif ($action == 'swapstatut' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  68. // bascule du statut d'un contact
  69. if ($object->fetch($id)) {
  70. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  71. } else {
  72. dol_print_error($db);
  73. }
  74. } elseif ($action == 'deletecontact' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  75. // Efface un contact
  76. $object->fetch($id);
  77. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  78. if ($result >= 0) {
  79. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  80. exit;
  81. } else {
  82. dol_print_error($db);
  83. }
  84. }
  85. /*
  86. * View
  87. */
  88. $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('ContactsAddresses');
  89. $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
  90. llxHeader('', $title, $helpurl);
  91. $form = new Form($db);
  92. $formcompany = new FormCompany($db);
  93. $contactstatic = new Contact($db);
  94. $userstatic = new User($db);
  95. /* *************************************************************************** */
  96. /* */
  97. /* Mode vue et edition */
  98. /* */
  99. /* *************************************************************************** */
  100. if ($id > 0 || !empty($ref)) {
  101. if ($object->fetch($id, $ref) > 0) {
  102. $object->fetch_thirdparty();
  103. $alreadypaid = $object->getSommePaiement();
  104. $head = facturefourn_prepare_head($object);
  105. print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  107. $morehtmlref = '<div class="refidno">';
  108. // Ref supplier
  109. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  110. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  111. // Thirdparty
  112. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  113. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  114. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  115. }
  116. // Project
  117. if (!empty($conf->projet->enabled)) {
  118. $langs->load("projects");
  119. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  120. if ($user->rights->facture->creer) {
  121. if ($action != 'classify') {
  122. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  123. $morehtmlref .= ' : ';
  124. }
  125. if ($action == 'classify') {
  126. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  127. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  128. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  129. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  130. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  131. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  132. $morehtmlref .= '</form>';
  133. } else {
  134. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  135. }
  136. } else {
  137. if (!empty($object->fk_project)) {
  138. $proj = new Project($db);
  139. $proj->fetch($object->fk_project);
  140. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  141. if ($proj->title) {
  142. $morehtmlref .= ' - '.$proj->title;
  143. }
  144. } else {
  145. $morehtmlref .= '';
  146. }
  147. }
  148. }
  149. $morehtmlref .= '</div>';
  150. $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  151. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  152. print '<div class="fichecenter">';
  153. print '<div class="underbanner clearboth"></div>';
  154. print '<table class="border centpercent tableforfield">';
  155. // Type
  156. print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
  157. print '<span class="badgeneutral">';
  158. print $object->getLibType();
  159. print '</span>';
  160. if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
  161. $facreplaced = new FactureFournisseur($db);
  162. $facreplaced->fetch($object->fk_facture_source);
  163. print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
  164. }
  165. if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  166. $facusing = new FactureFournisseur($db);
  167. $facusing->fetch($object->fk_facture_source);
  168. print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
  169. }
  170. $facidavoir = $object->getListIdAvoirFromInvoice();
  171. if (count($facidavoir) > 0) {
  172. $invoicecredits = array();
  173. foreach ($facidavoir as $facid) {
  174. $facavoir = new FactureFournisseur($db);
  175. $facavoir->fetch($facid);
  176. $invoicecredits[] = $facavoir->getNomUrl(1);
  177. }
  178. print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')';
  179. }
  180. //if ($facidnext > 0) {
  181. // $facthatreplace = new FactureFournisseur($db);
  182. // $facthatreplace->fetch($facidnext);
  183. // print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
  184. //}
  185. print '</td></tr>';
  186. // Label
  187. print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
  188. print $form->editfieldval("Label", 'label', $object->label, $object, 0);
  189. print '</td></tr>';
  190. // Amount
  191. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  192. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  193. // Amount Local Taxes
  194. //TODO: Place into a function to control showing by country or study better option
  195. if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
  196. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  197. print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  198. print '</tr>';
  199. }
  200. if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
  201. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  202. print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  203. print '</tr>';
  204. }
  205. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  206. print "</table>";
  207. print dol_get_fiche_end();
  208. print '<br>';
  209. // Contacts lines
  210. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  211. } else {
  212. print "ErrorRecordNotFound";
  213. }
  214. }
  215. // End of page
  216. llxFooter();
  217. $db->close();