1<?php
2/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2017      Ferran Marcet       	 <fmarcet@2byte.es>
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 <https://www.gnu.org/licenses/>.
18 */
19
20/**
21 *      \file       htdocs/compta/facture/info.php
22 *      \ingroup    facture
23 *		\brief      Page des informations d'une facture
24 */
25
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
31if (!empty($conf->projet->enabled)) {
32	include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array('companies', 'bills'));
37
38$id = GETPOST("facid", "int");
39$ref = GETPOST("ref", 'alpha');
40
41$object = new Facture($db);
42$extrafields = new ExtraFields($db);
43
44// Fetch optionals attributes and labels
45$extrafields->fetch_name_optionals_label($object->table_element);
46
47// Load object
48if ($id > 0 || !empty($ref)) {
49	$ret = $object->fetch($id, $ref, '', '', $conf->global->INVOICE_USE_SITUATION);
50}
51
52// Security check
53$fieldid = (!empty($ref) ? 'ref' : 'rowid');
54if ($user->socid) {
55	$socid = $user->socid;
56}
57$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
58$result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $fieldid, $isdraft);
59
60
61/*
62 * View
63 */
64
65$form = new Form($db);
66
67$title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Info');
68$help_url = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
69
70llxHeader('', $title, $help_url);
71
72$object->fetch_thirdparty();
73
74$object->info($object->id);
75
76$head = facture_prepare_head($object);
77print dol_get_fiche_head($head, 'info', $langs->trans("InvoiceCustomer"), -1, 'bill');
78
79$totalpaye = $object->getSommePaiement();
80
81// Invoice content
82
83$linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
84
85$morehtmlref = '<div class="refidno">';
86// Ref customer
87$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
88$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
89// Thirdparty
90$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
91// Project
92if (!empty($conf->projet->enabled)) {
93	$langs->load("projects");
94	$morehtmlref .= '<br>'.$langs->trans('Project').' ';
95	if ($user->rights->facture->creer) {
96		if ($action != 'classify') {
97			//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
98			$morehtmlref .= ' : ';
99		}
100		if ($action == 'classify') {
101			//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
102			$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
103			$morehtmlref .= '<input type="hidden" name="action" value="classin">';
104			$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
105			$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
106			$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
107			$morehtmlref .= '</form>';
108		} else {
109			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
110		}
111	} else {
112		if (!empty($object->fk_project)) {
113			$proj = new Project($db);
114			$proj->fetch($object->fk_project);
115			$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
116			$morehtmlref .= $proj->ref;
117			$morehtmlref .= '</a>';
118		} else {
119			$morehtmlref .= '';
120		}
121	}
122}
123$morehtmlref .= '</div>';
124
125$object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
126
127dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
128
129print '<div class="fichecenter">';
130print '<div class="underbanner clearboth"></div>';
131
132print '<br>';
133
134print '<table width="100%"><tr><td>';
135dol_print_object_info($object);
136print '</td></tr></table>';
137
138print '</div>';
139
140print dol_get_fiche_end();
141
142// End of page
143llxFooter();
144$db->close();
145