1<?php
2/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@inodbox.com>
5 * Copyright (C) 2013      Florian Henry		<florian.henry@open-concept.pro>
6 * Copyright (C) 2017      Ferran Marcet       	 <fmarcet@2byte.es>
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/**
23 *      \file       htdocs/compta/facture/note.php
24 *      \ingroup    facture
25 *      \brief      Fiche de notes sur une facture
26 */
27
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
32if (!empty($conf->projet->enabled)) {
33	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34}
35
36// Load translation files required by the page
37$langs->loadLangs(array('companies', 'bills'));
38
39$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
40$ref = GETPOST('ref', 'alpha');
41$socid = GETPOST('socid', 'int');
42$action = GETPOST('action', 'aZ09');
43
44$object = new Facture($db);
45// Load object
46if ($id > 0 || !empty($ref)) {
47	$object->fetch($id, $ref, '', '', $conf->global->INVOICE_USE_SITUATION);
48}
49
50$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
51
52// Security check
53$socid = 0;
54if ($user->socid) {
55	$socid = $user->socid;
56}
57$result = restrictedArea($user, 'facture', $id, '');
58
59
60/*
61 * Actions
62 */
63
64include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
65
66
67
68/*
69 * View
70 */
71
72$title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Notes');
73$helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
74llxHeader('', $title, $helpurl);
75
76$form = new Form($db);
77
78if ($id > 0 || !empty($ref)) {
79	$object = new Facture($db);
80	$object->fetch($id, $ref);
81
82	$object->fetch_thirdparty();
83
84	$head = facture_prepare_head($object);
85
86	$totalpaye = $object->getSommePaiement();
87
88	print dol_get_fiche_head($head, 'note', $langs->trans("InvoiceCustomer"), -1, 'bill');
89
90	// Invoice content
91
92	$linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
93
94	$morehtmlref = '<div class="refidno">';
95	// Ref customer
96	$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
97	$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
98	// Thirdparty
99	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
100	// Project
101	if (!empty($conf->projet->enabled)) {
102		$langs->load("projects");
103		$morehtmlref .= '<br>'.$langs->trans('Project').' ';
104		if ($user->rights->facture->creer) {
105			if ($action != 'classify') {
106				//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
107				$morehtmlref .= ' : ';
108			}
109			if ($action == 'classify') {
110				//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
111				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
112				$morehtmlref .= '<input type="hidden" name="action" value="classin">';
113				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
114				$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
115				$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
116				$morehtmlref .= '</form>';
117			} else {
118				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
119			}
120		} else {
121			if (!empty($object->fk_project)) {
122				$proj = new Project($db);
123				$proj->fetch($object->fk_project);
124				$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
125				$morehtmlref .= $proj->ref;
126				$morehtmlref .= '</a>';
127			} else {
128				$morehtmlref .= '';
129			}
130		}
131	}
132	$morehtmlref .= '</div>';
133
134	$object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
135
136	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
137
138	print '<div class="fichecenter">';
139	print '<div class="underbanner clearboth"></div>';
140
141
142	$cssclass = "titlefield";
143	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
144
145	print dol_get_fiche_end();
146}
147
148// End of page
149llxFooter();
150$db->close();
151