PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 9ms app.codeStats 0ms

/htdocs/compta/facture/contact.php

https://github.com/zeert/dolibarr
PHP | 205 lines | 126 code | 34 blank | 45 comment | 26 complexity | fbea3733c0b74a3f5c48b11b17860062 MD5 | raw file
  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@dolibarr.fr>
  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 2 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/**
 22 *       \file       htdocs/compta/facture/contact.php
 23 *       \ingroup    facture
 24 *       \brief      Onglet de gestion des contacts des factures
 25 */
 26
 27require("../../main.inc.php");
 28require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
 29require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
 30require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
 31require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php');
 32require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
 33
 34$langs->load("bills");
 35$langs->load("companies");
 36
 37$id     = (GETPOST('id')?GETPOST('id','int'):GETPOST('facid','int'));  // For backward compatibility
 38$ref    = GETPOST('ref','alpha');
 39$lineid = GETPOST('lineid','int');
 40$socid  = GETPOST('socid','int');
 41$action = GETPOST('action','alpha');
 42
 43// Security check
 44if ($user->societe_id) $socid=$user->societe_id;
 45$result = restrictedArea($user, 'facture', $id);
 46
 47$object = new Facture($db);
 48
 49
 50/*
 51 * Ajout d'un nouveau contact
 52 */
 53
 54if ($action == 'addcontact' && $user->rights->facture->creer)
 55{
 56	$result = $object->fetch($id);
 57
 58    if ($result > 0 && $id > 0)
 59    {
 60    	$contactid = (GETPOST('userid') ? GETPOST('userid','int') : GETPOST('contactid','int'));
 61  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
 62    }
 63
 64	if ($result >= 0)
 65	{
 66		Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 67		exit;
 68	}
 69	else
 70	{
 71		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 72		{
 73			$langs->load("errors");
 74			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 75		}
 76		else
 77		{
 78			$mesg = '<div class="error">'.$object->error.'</div>';
 79		}
 80	}
 81}
 82
 83// bascule du statut d'un contact
 84else if ($action == 'swapstatut' && $user->rights->facture->creer)
 85{
 86	if ($object->fetch($id))
 87	{
 88	    $result=$object->swapContactStatus(GETPOST('ligne'));
 89	}
 90	else
 91	{
 92		dol_print_error($db);
 93	}
 94}
 95
 96// Efface un contact
 97else if ($action == 'deletecontact' && $user->rights->facture->creer)
 98{
 99	$object->fetch($id);
100	$result = $object->delete_contact($lineid);
101
102	if ($result >= 0)
103	{
104		Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105		exit;
106	}
107	else {
108		dol_print_error($db);
109	}
110}
111
112
113/*
114 * View
115 */
116
117llxHeader('', $langs->trans("Bill"), "Facture");
118
119$form = new Form($db);
120$formcompany = new FormCompany($db);
121$contactstatic=new Contact($db);
122$userstatic=new User($db);
123
124
125/* *************************************************************************** */
126/*                                                                             */
127/* Mode vue et edition                                                         */
128/*                                                                             */
129/* *************************************************************************** */
130dol_htmloutput_mesg($mesg);
131
132if ($id > 0 || ! empty($ref))
133{
134	if ($object->fetch($id, $ref) > 0)
135	{
136		$object->fetch_thirdparty();
137
138		$head = facture_prepare_head($object);
139
140		dol_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), 0, 'bill');
141
142		/*
143		 *   Facture synthese pour rappel
144		 */
145		print '<table class="border" width="100%">';
146
147		$linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
148
149		// Ref
150		print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
151		print '<td colspan="3">';
152		$morehtmlref='';
153		$discount=new DiscountAbsolute($db);
154		$result=$discount->fetch(0,$object->id);
155		if ($result > 0)
156		{
157			$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
158		}
159		if ($result < 0)
160		{
161			dol_print_error('',$discount->error);
162		}
163		print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
164		print '</td></tr>';
165
166		// Ref customer
167		print '<tr><td width="20%">';
168        print '<table class="nobordernopadding" width="100%"><tr><td>';
169        print $langs->trans('RefCustomer');
170        print '</td>';
171        print '</tr></table>';
172        print '</td>';
173        print '<td colspan="5">';
174        print $object->ref_client;
175		print '</td></tr>';
176
177		// Customer
178		print "<tr><td>".$langs->trans("Company")."</td>";
179		print '<td colspan="3">'.$object->client->getNomUrl(1,'compta').'</td></tr>';
180		print "</table>";
181
182		print '</div>';
183
184		print '<br>';
185
186		// Contacts lines (modules that overwrite templates must declare this into descriptor)
187		$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
188		foreach($dirtpls as $reldir)
189		{
190		    $res=@include(dol_buildpath($reldir.'/contacts.tpl.php'));
191		    if ($res) break;
192		}
193
194	}
195	else
196	{
197		// Record not found
198		print "ErrorRecordNotFound";
199	}
200}
201
202
203llxFooter();
204$db->close();
205?>