dolibarr  9.0.0
document.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
7  * Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
8  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
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.'/fourn/class/fournisseur.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.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->loadLangs(array('bills', 'other', 'companies'));
42 
43 $id = GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int');
44 $action=GETPOST('action','alpha');
45 $confirm=GETPOST('confirm','alpha');
46 $ref = GETPOST('ref','alpha');
47 
48 // Security check
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
51 
52 // Get parameters
53 $sortfield = GETPOST("sortfield",'alpha');
54 $sortorder = GETPOST("sortorder",'alpha');
55 $page = GETPOST("page",'int');
56 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
57 $offset = $conf->liste_limit * $page;
58 $pageprev = $page - 1;
59 $pagenext = $page + 1;
60 if (! $sortorder) $sortorder="ASC";
61 if (! $sortfield) $sortfield="name";
62 
63 $object = new FactureFournisseur($db);
64 if ($object->fetch($id, $ref))
65 {
66  $object->fetch_thirdparty();
67  $ref=dol_sanitizeFileName($object->ref);
68  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref;
69 }
70 
71 
72 /*
73  * Actions
74  */
75 
76 include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
77 
78 
79 /*
80  * View
81  */
82 
83 $form = new Form($db);
84 
85 $title = $langs->trans('SupplierInvoice') . " - " . $langs->trans('Documents');
86 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
87 llxHeader('', $title, $helpurl);
88 
89 if ($object->id > 0)
90 {
91  $head = facturefourn_prepare_head($object);
92  dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'bill');
93 
94  $totalpaye = $object->getSommePaiement();
95 
96  $linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
97 
98  $morehtmlref='<div class="refidno">';
99  // Ref supplier
100  $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
101  $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
102  // Thirdparty
103  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
104  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
105  // Project
106  if (! empty($conf->projet->enabled))
107  {
108  $langs->load("projects");
109  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
110  if ($user->rights->facture->creer)
111  {
112  if ($action != 'classify')
113  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
114  $morehtmlref.=' : ';
115  if ($action == 'classify') {
116  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
117  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
118  $morehtmlref.='<input type="hidden" name="action" value="classin">';
119  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
120  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
121  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
122  $morehtmlref.='</form>';
123  } else {
124  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
125  }
126  } else {
127  if (! empty($object->fk_project)) {
128  $proj = new Project($db);
129  $proj->fetch($object->fk_project);
130  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
131  $morehtmlref.=$proj->ref;
132  $morehtmlref.='</a>';
133  } else {
134  $morehtmlref.='';
135  }
136  }
137  }
138  $morehtmlref.='</div>';
139 
140  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
141 
142  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
143 
144  print '<div class="fichecenter">';
145  print '<div class="underbanner clearboth"></div>';
146 
147  // Build file list
148  $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
149  $totalsize=0;
150  foreach($filearray as $key => $file)
151  {
152  $totalsize+=$file['size'];
153  }
154 
155  /*
156  * Confirm delete file
157  */
158  if ($action == 'delete')
159  {
160  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
161  }
162 
163  print '<table class="border" width="100%">';
164 
165  // Type
166  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
167  print $object->getLibType();
168  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
169  {
170  $facreplaced=new FactureFournisseur($db);
171  $facreplaced->fetch($object->fk_facture_source);
172  print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
173  }
174  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE)
175  {
176  $facusing=new FactureFournisseur($db);
177  $facusing->fetch($object->fk_facture_source);
178  print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
179  }
180 
181  $facidavoir=$object->getListIdAvoirFromInvoice();
182  if (count($facidavoir) > 0)
183  {
184  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
185  $i=0;
186  foreach($facidavoir as $id)
187  {
188  if ($i==0) print ' ';
189  else print ',';
190  $facavoir=new FactureFournisseur($db);
191  $facavoir->fetch($id);
192  print $facavoir->getNomUrl(1);
193  }
194  print ')';
195  }
196  /*
197  if ($facidnext > 0)
198  {
199  $facthatreplace=new FactureFournisseur($db);
200  $facthatreplace->fetch($facidnext);
201  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
202  }
203  */
204  print '</td></tr>';
205 
206  // Label
207  print '<tr><td>'.$form->editfieldkey("Label",'label',$object->label,$object,0).'</td><td>';
208  print $form->editfieldval("Label",'label',$object->label,$object,0);
209  print '</td>';
210 
211  // Amount
212  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
213  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
214 
215  // Amount Local Taxes
216  //TODO: Place into a function to control showing by country or study better option
217  if ($societe->localtax1_assuj=="1") //Localtax1
218  {
219  print '<tr><td>'.$langs->transcountry("AmountLT1",$societe->country_code).'</td>';
220  print '<td>'.price($object->total_localtax1,1,$langs,0,-1,-1,$conf->currency).'</td>';
221  print '</tr>';
222  }
223  if ($societe->localtax2_assuj=="1") //Localtax2
224  {
225  print '<tr><td>'.$langs->transcountry("AmountLT2",$societe->country_code).'</td>';
226  print '<td>'.price($object->total_localtax2,1,$langs,0,-1,-1,$conf->currency).'</td>';
227  print '</tr>';
228  }
229  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
230 
231  print '</table><br>';
232 
233  print '<div class="underbanner clearboth"></div>';
234 
235  print '<table class="border" width="100%">';
236 
237  // Nb of files
238  print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
239 
240  print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize,1,1).'</td></tr>';
241 
242  print '</table>';
243  print '</div>';
244 
245  print '<div class="clearboth"></div>';
246 
247  dol_fiche_end();
248 
249 
250  $modulepart = 'facture_fournisseur';
251  $permission = $user->rights->fournisseur->facture->creer;
252  $permtoedit = $user->rights->fournisseur->facture->creer;
253  $param = '&facid=' . $object->id;
254  include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
255 }
256 else
257 {
258  print $langs->trans('ErrorUnknown');
259 }
260 
261 // End of page
262 llxFooter();
263 $db->close();
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
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.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:59
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:34
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
const TYPE_CREDIT_NOTE
Credit note invoice.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
llxFooter()
Footer empty.
Definition: document.php:68
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
if(isset($_GET["hashp"]) &&! defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:60