contact.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. if (isModEnabled('project')) {
  34. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  35. }
  36. $langs->loadLangs(array("bills", "other", "companies"));
  37. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. // Security check
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  45. $hookmanager->initHooks(array('invoicesuppliercardcontact'));
  46. $object = new FactureFournisseur($db);
  47. $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  48. $permissiontoadd = $usercancreate;
  49. /*
  50. * Ajout d'un nouveau contact
  51. */
  52. if ($action == 'addcontact' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  53. $result = $object->fetch($id, $ref);
  54. if ($result > 0 && $id > 0) {
  55. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  56. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  57. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  58. }
  59. if ($result >= 0) {
  60. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  61. exit;
  62. } else {
  63. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  64. $langs->load("errors");
  65. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  66. } else {
  67. setEventMessages($object->error, $object->errors, 'errors');
  68. }
  69. }
  70. } elseif ($action == 'swapstatut' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  71. // bascule du statut d'un contact
  72. if ($object->fetch($id)) {
  73. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  74. } else {
  75. dol_print_error($db);
  76. }
  77. } elseif ($action == 'deletecontact' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  78. // Efface un contact
  79. $object->fetch($id);
  80. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  81. if ($result >= 0) {
  82. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  83. exit;
  84. } else {
  85. dol_print_error($db);
  86. }
  87. }
  88. /*
  89. * View
  90. */
  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. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  105. $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
  106. llxHeader('', $title, $helpurl);
  107. $head = facturefourn_prepare_head($object);
  108. print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  110. $morehtmlref = '<div class="refidno">';
  111. // Ref supplier
  112. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  113. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  114. // Thirdparty
  115. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  116. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  117. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  118. }
  119. // Project
  120. if (isModEnabled('project')) {
  121. $langs->load("projects");
  122. $morehtmlref .= '<br>';
  123. if (0) {
  124. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  125. if ($action != 'classify') {
  126. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  127. }
  128. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  129. } else {
  130. if (!empty($object->fk_project)) {
  131. $proj = new Project($db);
  132. $proj->fetch($object->fk_project);
  133. $morehtmlref .= $proj->getNomUrl(1);
  134. if ($proj->title) {
  135. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  136. }
  137. }
  138. }
  139. }
  140. $morehtmlref .= '</div>';
  141. $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  142. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  143. /*
  144. print '<div class="fichecenter">';
  145. print '<div class="fichehalfleft">';
  146. print '<div class="underbanner clearboth"></div>';
  147. print '<table class="border centpercent tableforfield">';
  148. // Type
  149. print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
  150. print '<span class="badgeneutral">';
  151. print $object->getLibType();
  152. print '</span>';
  153. if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
  154. $facreplaced = new FactureFournisseur($db);
  155. $facreplaced->fetch($object->fk_facture_source);
  156. print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1));
  157. }
  158. if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  159. $facusing = new FactureFournisseur($db);
  160. $facusing->fetch($object->fk_facture_source);
  161. print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1));
  162. }
  163. $facidavoir = $object->getListIdAvoirFromInvoice();
  164. if (count($facidavoir) > 0) {
  165. $invoicecredits = array();
  166. foreach ($facidavoir as $facid) {
  167. $facavoir = new FactureFournisseur($db);
  168. $facavoir->fetch($facid);
  169. $invoicecredits[] = $facavoir->getNomUrl(1);
  170. }
  171. print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
  172. }
  173. //if ($facidnext > 0) {
  174. // $facthatreplace = new FactureFournisseur($db);
  175. // $facthatreplace->fetch($facidnext);
  176. // print ' '.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1));
  177. //}
  178. print '</td></tr>';
  179. // Label
  180. print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
  181. print $form->editfieldval("Label", 'label', $object->label, $object, 0);
  182. print '</td></tr>';
  183. print '</table>';
  184. print '</div><div class="fichehalfright">';
  185. print '<div class="underbanner clearboth"></div>';
  186. print '<table class="border centpercent tableforfield">';
  187. // Amount
  188. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  189. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  190. // Amount Local Taxes
  191. //TODO: Place into a function to control showing by country or study better option
  192. if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
  193. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  194. print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  195. print '</tr>';
  196. }
  197. if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
  198. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  199. print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  200. print '</tr>';
  201. }
  202. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  203. print "</table>";
  204. print '</div>';
  205. print '</div>';
  206. */
  207. print dol_get_fiche_end();
  208. //print '<div class="clearboth"></div>';
  209. //print '<br>';
  210. // Contacts lines
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  212. } else {
  213. print "ErrorRecordNotFound";
  214. }
  215. }
  216. // End of page
  217. llxFooter();
  218. $db->close();