dolibarr  7.0.0-beta
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@capnetworks.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->load('bills');
42 $langs->load('other');
43 $langs->load("companies");
44 
45 $id = GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int');
46 $action=GETPOST('action','alpha');
47 $confirm=GETPOST('confirm','alpha');
48 $ref = GETPOST('ref','alpha');
49 
50 // Security check
51 if ($user->societe_id) $socid=$user->societe_id;
52 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
53 
54 // Get parameters
55 $sortfield = GETPOST("sortfield",'alpha');
56 $sortorder = GETPOST("sortorder",'alpha');
57 $page = GETPOST("page",'int');
58 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
59 $offset = $conf->liste_limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 if (! $sortorder) $sortorder="ASC";
63 if (! $sortfield) $sortfield="name";
64 
65 $object = new FactureFournisseur($db);
66 if ($object->fetch($id, $ref))
67 {
68  $object->fetch_thirdparty();
69  $ref=dol_sanitizeFileName($object->ref);
70  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref;
71 }
72 
73 
74 /*
75  * Actions
76  */
77 
78 include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
79 
80 
81 /*
82  * View
83  */
84 
85 $form = new Form($db);
86 
87 $title = $langs->trans('SupplierInvoice') . " - " . $langs->trans('Documents');
88 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
89 llxHeader('', $title, $helpurl);
90 
91 if ($object->id > 0)
92 {
93  $head = facturefourn_prepare_head($object);
94  dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'bill');
95 
96  $totalpaye = $object->getSommePaiement();
97 
98  $linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
99 
100  $morehtmlref='<div class="refidno">';
101  // Ref supplier
102  $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
103  $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
104  // Thirdparty
105  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
106  // Project
107  if (! empty($conf->projet->enabled))
108  {
109  $langs->load("projects");
110  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
111  if ($user->rights->facture->creer)
112  {
113  if ($action != 'classify')
114  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
115  $morehtmlref.=' : ';
116  if ($action == 'classify') {
117  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
118  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
119  $morehtmlref.='<input type="hidden" name="action" value="classin">';
120  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
121  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
122  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
123  $morehtmlref.='</form>';
124  } else {
125  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
126  }
127  } else {
128  if (! empty($object->fk_project)) {
129  $proj = new Project($db);
130  $proj->fetch($object->fk_project);
131  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
132  $morehtmlref.=$proj->ref;
133  $morehtmlref.='</a>';
134  } else {
135  $morehtmlref.='';
136  }
137  }
138  }
139  $morehtmlref.='</div>';
140 
141  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
142 
143  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
144 
145  print '<div class="fichecenter">';
146  print '<div class="underbanner clearboth"></div>';
147 
148  // Construit liste des fichiers
149  $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
150  $totalsize=0;
151  foreach($filearray as $key => $file)
152  {
153  $totalsize+=$file['size'];
154  }
155 
156  /*
157  * Confirm delete file
158  */
159  if ($action == 'delete')
160  {
161  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
162 
163  }
164 
165  print '<table class="border" width="100%">';
166 
167  // Type
168  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
169  print $object->getLibType();
170  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
171  {
172  $facreplaced=new FactureFournisseur($db);
173  $facreplaced->fetch($object->fk_facture_source);
174  print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
175  }
176  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE)
177  {
178  $facusing=new FactureFournisseur($db);
179  $facusing->fetch($object->fk_facture_source);
180  print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
181  }
182 
183  $facidavoir=$object->getListIdAvoirFromInvoice();
184  if (count($facidavoir) > 0)
185  {
186  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
187  $i=0;
188  foreach($facidavoir as $id)
189  {
190  if ($i==0) print ' ';
191  else print ',';
192  $facavoir=new FactureFournisseur($db);
193  $facavoir->fetch($id);
194  print $facavoir->getNomUrl(1);
195  }
196  print ')';
197  }
198  /*
199  if ($facidnext > 0)
200  {
201  $facthatreplace=new FactureFournisseur($db);
202  $facthatreplace->fetch($facidnext);
203  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
204  }
205  */
206  print '</td></tr>';
207 
208  // Label
209  print '<tr><td>'.$form->editfieldkey("Label",'label',$object->label,$object,0).'</td><td>';
210  print $form->editfieldval("Label",'label',$object->label,$object,0);
211  print '</td>';
212 
213  // Amount
214  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
215  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
216 
217  // Amount Local Taxes
218  //TODO: Place into a function to control showing by country or study better option
219  if ($societe->localtax1_assuj=="1") //Localtax1
220  {
221  print '<tr><td>'.$langs->transcountry("AmountLT1",$societe->country_code).'</td>';
222  print '<td>'.price($object->total_localtax1,1,$langs,0,-1,-1,$conf->currency).'</td>';
223  print '</tr>';
224  }
225  if ($societe->localtax2_assuj=="1") //Localtax2
226  {
227  print '<tr><td>'.$langs->transcountry("AmountLT2",$societe->country_code).'</td>';
228  print '<td>'.price($object->total_localtax2,1,$langs,0,-1,-1,$conf->currency).'</td>';
229  print '</tr>';
230  }
231  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc,1,$langs,0,-1,-1,$conf->currency).'</td></tr>';
232 
233  print '</table><br>';
234 
235  print '<div class="underbanner clearboth"></div>';
236 
237  print '<table class="border" width="100%">';
238 
239  // Nb of files
240  print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
241 
242  print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.$totalsize.' '.$langs->trans('bytes').'</td></tr>';
243 
244  print '</table>';
245  print '</div>';
246 
247  print '<div class="clearboth"></div>';
248 
249  dol_fiche_end();
250 
251 
252  $modulepart = 'facture_fournisseur';
253  $permission = $user->rights->fournisseur->facture->creer;
254  $permtoedit = $user->rights->fournisseur->facture->creer;
255  $param = '&facid=' . $object->id;
256  include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
257 }
258 else
259 {
260  print $langs->trans('ErrorUnknown');
261 }
262 
263 
264 llxFooter();
265 $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.
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.
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.
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.
print
Draft customers invoices.
Definition: index.php:91
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.