dolibarr  13.0.2
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@open-dsi.fr>
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 <https://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', 'aZ09');
45 $confirm = GETPOST('confirm', 'alpha');
46 $ref = GETPOST('ref', 'alpha');
47 
48 // Security check
49 if ($user->socid) $socid = $user->socid;
50 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
51 
52 // Get parameters
53 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
54 $sortfield = GETPOST("sortfield", 'alpha');
55 $sortorder = GETPOST("sortorder", 'alpha');
56 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
57 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
61 if (!$sortorder) $sortorder = "ASC";
62 if (!$sortfield) $sortfield = "name";
63 
64 $object = new FactureFournisseur($db);
65 if ($object->fetch($id, $ref))
66 {
67  $object->fetch_thirdparty();
68  $ref = dol_sanitizeFileName($object->ref);
69  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
70 }
71 
72 
73 /*
74  * Actions
75  */
76 
77 include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
78 
79 
80 /*
81  * View
82  */
83 
84 $form = new Form($db);
85 
86 $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Documents');
87 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
88 llxHeader('', $title, $helpurl);
89 
90 if ($object->id > 0)
91 {
92  $head = facturefourn_prepare_head($object);
93  print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
94 
95  $totalpaye = $object->getSommePaiement();
96 
97  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
98 
99  $morehtmlref = '<div class="refidno">';
100  // Ref supplier
101  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
102  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
103  // Thirdparty
104  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
105  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>)';
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 class="editfielda" 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="'.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  // Build file list
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  print '<table class="border tableforfield centpercent">';
165 
166  // Type
167  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
168  print $object->getLibType();
169  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
170  {
171  $facreplaced = new FactureFournisseur($db);
172  $facreplaced->fetch($object->fk_facture_source);
173  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
174  }
175  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE)
176  {
177  $facusing = new FactureFournisseur($db);
178  $facusing->fetch($object->fk_facture_source);
179  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
180  }
181 
182  $facidavoir = $object->getListIdAvoirFromInvoice();
183  if (count($facidavoir) > 0)
184  {
185  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
186  $i = 0;
187  foreach ($facidavoir as $id)
188  {
189  if ($i == 0) print ' ';
190  else print ',';
191  $facavoir = new FactureFournisseur($db);
192  $facavoir->fetch($id);
193  print $facavoir->getNomUrl(1);
194  }
195  print ')';
196  }
197  /*
198  if ($facidnext > 0)
199  {
200  $facthatreplace=new FactureFournisseur($db);
201  $facthatreplace->fetch($facidnext);
202  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
203  }
204  */
205  print '</td></tr>';
206 
207  // Label
208  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
209  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
210  print '</td>';
211 
212  // Amount
213  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
214  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
215 
216  // Amount Local Taxes
217  //TODO: Place into a function to control showing by country or study better option
218  if ($mysoc->localtax1_assuj == "1") //Localtax1
219  {
220  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
221  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
222  print '</tr>';
223  }
224  if ($mysoc->localtax2_assuj == "1") //Localtax2
225  {
226  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
227  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
228  print '</tr>';
229  }
230  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
231 
232  print '</table><br>';
233 
234  print '<div class="underbanner clearboth"></div>';
235 
236  print '<table class="border tableforfield centpercent">';
237 
238  // Nb of files
239  print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
240 
241  print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
242 
243  print '</table>';
244  print '</div>';
245 
246  print '<div class="clearboth"></div>';
247 
249 
250 
251  $modulepart = 'facture_fournisseur';
252  $permission = $user->rights->fournisseur->facture->creer;
253  $permtoedit = $user->rights->fournisseur->facture->creer;
254  $param = '&facid='.$object->id;
255 
256  $defaulttpldir = '/core/tpl';
257  $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
258  foreach ($dirtpls as $module => $reldir)
259  {
260  if (!empty($module)) {
261  $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
262  } else {
263  $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php';
264  }
265 
266  if (empty($conf->file->strict_mode)) {
267  $res = @include $tpl;
268  } else {
269  $res = include $tpl; // for debug
270  }
271  if ($res) break;
272  }
273 } else {
274  print $langs->trans('ErrorUnknown');
275 }
276 
277 // End of page
278 llxFooter();
279 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
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.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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:60
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:34
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
const TYPE_CREDIT_NOTE
Credit note invoice.
print
Draft customers invoices.
Definition: index.php:89
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59