dolibarr  7.0.0-beta
document.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
7  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2017 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 if (! empty($conf->projet->enabled)) {
38  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
39 }
40 
41 $langs->load('propal');
42 $langs->load('compta');
43 $langs->load('other');
44 $langs->load("bills");
45 $langs->load('companies');
46 
47 
48 $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
49 $ref=GETPOST('ref','alpha');
50 $socid=GETPOST('socid','int');
51 $action=GETPOST('action','alpha');
52 $confirm=GETPOST('confirm', 'alpha');
53 
54 // Security check
55 if ($user->societe_id)
56 {
57  $socid = $user->societe_id;
58 }
59 $result=restrictedArea($user,'facture',$id,'');
60 
61 // Get parameters
62 $sortfield = GETPOST("sortfield",'alpha');
63 $sortorder = GETPOST("sortorder",'alpha');
64 $page = GETPOST("page",'int');
65 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
66 $offset = $conf->liste_limit * $page;
67 $pageprev = $page - 1;
68 $pagenext = $page + 1;
69 if (! $sortorder) $sortorder="ASC";
70 if (! $sortfield) $sortfield="name";
71 
72 $object = new Facture($db);
73 if ($object->fetch($id))
74 {
75  $object->fetch_thirdparty();
76  $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
77 }
78 
79 
80 /*
81  * Actions
82  */
83 
84 include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
85 
86 
87 /*
88  * View
89  */
90 
91 $title = $langs->trans('InvoiceCustomer') . " - " . $langs->trans('Documents');
92 $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
93 llxHeader('', $title, $helpurl);
94 
95 $form = new Form($db);
96 
97 if ($id > 0 || ! empty($ref))
98 {
99  if ($object->fetch($id,$ref) > 0)
100  {
101  $object->fetch_thirdparty();
102 
103  $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
104 
105  $head = facture_prepare_head($object);
106  dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill');
107 
108  $totalpaye = $object->getSommePaiement();
109 
110  // Construit liste des fichiers
111  $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
112  $totalsize=0;
113  foreach($filearray as $key => $file)
114  {
115  $totalsize+=$file['size'];
116  }
117 
118 
119  // Invoice content
120 
121  $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
122 
123  $morehtmlref='<div class="refidno">';
124  // Ref customer
125  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
126  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
127  // Thirdparty
128  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
129  // Project
130  if (! empty($conf->projet->enabled))
131  {
132  $langs->load("projects");
133  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
134  if ($user->rights->facture->creer)
135  {
136  if ($action != 'classify')
137  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
138  $morehtmlref.=' : ';
139  if ($action == 'classify') {
140  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
141  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
142  $morehtmlref.='<input type="hidden" name="action" value="classin">';
143  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
144  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
145  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
146  $morehtmlref.='</form>';
147  } else {
148  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
149  }
150  } else {
151  if (! empty($object->fk_project)) {
152  $proj = new Project($db);
153  $proj->fetch($object->fk_project);
154  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
155  $morehtmlref.=$proj->ref;
156  $morehtmlref.='</a>';
157  } else {
158  $morehtmlref.='';
159  }
160  }
161  }
162  $morehtmlref.='</div>';
163 
164  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
165 
166  dol_banner_tab($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref, '', 0);
167 
168  print '<div class="fichecenter">';
169  print '<div class="underbanner clearboth"></div>';
170 
171  print '<table class="border" width="100%">';
172 
173  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
174  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
175  print "</table>\n";
176 
177  print "</div>\n";
178 
179  dol_fiche_end();
180 
181  $modulepart = 'facture';
182  $permission = $user->rights->facture->creer;
183  $permtoedit = $user->rights->facture->creer;
184  $param = '&id=' . $object->id;
185  include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
186  }
187  else
188  {
189  dol_print_error($db);
190  }
191 }
192 else
193 {
194  print $langs->trans("ErrorUnknown");
195 }
196 
197 llxFooter();
198 
199 $db->close();
llxHeader()
Header empty.
Definition: document.php:70
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
print
Draft customers invoices.
Definition: index.php:91
Class to manage invoices.
llxFooter()
Footer empty.
Definition: document.php:76
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36