/htdocs/compta/facture/apercu.php

https://github.com/asterix14/dolibarr · PHP · 412 lines · 294 code · 51 blank · 67 comment · 92 complexity · 791611f803bf1be552c6b8237cd573a3 MD5 · raw file

  1. <?php
  2. /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@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 2 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * \file htdocs/compta/facture/apercu.php
  24. * \ingroup facture
  25. * \brief Page de l'onglet apercu d'une facture
  26. */
  27. require("../../main.inc.php");
  28. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  29. require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php');
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  31. if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  32. $langs->load("bills");
  33. // Security check
  34. $socid=0;
  35. $id = GETPOST("facid");
  36. $ref = GETPOST("ref");
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'facture', $id);
  39. /*
  40. * View
  41. */
  42. $now=dol_now();
  43. llxHeader('',$langs->trans("Bill"),'Facture');
  44. $form = new Form($db);
  45. /* *************************************************************************** */
  46. /* */
  47. /* Mode fiche */
  48. /* */
  49. /* *************************************************************************** */
  50. if ($id > 0 || ! empty($ref))
  51. {
  52. $object = New Facture($db);
  53. if ($object->fetch($id,$ref) > 0)
  54. {
  55. $soc = new Societe($db);
  56. $soc->fetch($object->socid);
  57. $author = new User($db);
  58. if ($object->user_author)
  59. {
  60. $author->fetch($object->user_author);
  61. }
  62. $head = facture_prepare_head($object);
  63. dol_fiche_head($head, 'preview', $langs->trans("InvoiceCustomer"), 0, 'bill');
  64. $totalpaye = $object->getSommePaiement();
  65. /*
  66. * Facture
  67. */
  68. print '<table class="border" width="100%">';
  69. $rowspan=3;
  70. // Reference
  71. print '<tr><td width="20%">'.$langs->trans('Ref').'</td><td colspan="5">'.$object->ref.'</td></tr>';
  72. // Societe
  73. print '<tr><td>'.$langs->trans("Company").'</td>';
  74. print '<td colspan="5">'.$soc->getNomUrl(1,'compta').'</td>';
  75. print '</tr>';
  76. // Type
  77. print '<tr><td>'.$langs->trans('Type').'</td><td colspan="5">';
  78. print $object->getLibType();
  79. if ($object->type == 1)
  80. {
  81. $facreplaced=new Facture($db);
  82. $facreplaced->fetch($object->fk_facture_source);
  83. print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
  84. }
  85. if ($object->type == 2)
  86. {
  87. $facusing=new Facture($db);
  88. $facusing->fetch($object->fk_facture_source);
  89. print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
  90. }
  91. $facidavoir=$object->getListIdAvoirFromInvoice();
  92. if (count($facidavoir) > 0)
  93. {
  94. print ' ('.$langs->transnoentities("InvoiceHasAvoir");
  95. $i=0;
  96. foreach($facidavoir as $id)
  97. {
  98. if ($i==0) print ' ';
  99. else print ',';
  100. $facavoir=new Facture($db);
  101. $facavoir->fetch($id);
  102. print $facavoir->getNomUrl(1);
  103. }
  104. print ')';
  105. }
  106. if ($objectidnext > 0)
  107. {
  108. $facthatreplace=new Facture($db);
  109. $facthatreplace->fetch($objectidnext);
  110. print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
  111. }
  112. print '</td></tr>';
  113. // Relative and absolute discounts
  114. $addabsolutediscount=' <a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddGlobalDiscount").'</a>';
  115. $addcreditnote=' <a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
  116. print '<tr><td>'.$langs->trans('Discounts');
  117. print '</td><td colspan="5">';
  118. if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
  119. else print $langs->trans("CompanyHasNoRelativeDiscount");
  120. if ($absolute_discount > 0)
  121. {
  122. print '. ';
  123. if ($object->statut > 0 || $object->type == 2 || $object->type == 3)
  124. {
  125. if ($object->statut == 0)
  126. {
  127. print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
  128. print '. ';
  129. }
  130. else
  131. {
  132. if ($object->statut < 1 || $object->type == 2 || $object->type == 3)
  133. {
  134. $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
  135. print '<br>'.$text.'.<br>';
  136. }
  137. else
  138. {
  139. $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
  140. $text2=$langs->trans("AbsoluteDiscountUse");
  141. print $form->textwithpicto($text,$text2);
  142. }
  143. }
  144. }
  145. else
  146. {
  147. // Remise dispo de type remise fixe (not credit note)
  148. $filter='fk_facture_source IS NULL';
  149. print '<br>';
  150. $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id',$soc->id, $absolute_discount, $filter, $resteapayer, ' - '.$addabsolutediscount);
  151. }
  152. }
  153. else
  154. {
  155. if ($absolute_creditnote > 0) // If not linke will be added later
  156. {
  157. if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'<br>';
  158. else print '.';
  159. }
  160. else print '. ';
  161. }
  162. if ($absolute_creditnote > 0)
  163. {
  164. // If validated, we show link "add credit note to payment"
  165. if ($object->statut != 1 || $object->type == 2 || $object->type == 3)
  166. {
  167. if ($object->statut == 0 && $object->type != 3)
  168. {
  169. $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie));
  170. print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
  171. }
  172. else
  173. {
  174. print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.';
  175. }
  176. }
  177. else
  178. {
  179. // Remise dispo de type avoir
  180. $filter='fk_facture_source IS NOT NULL';
  181. if (! $absolute_discount) print '<br>';
  182. $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer);
  183. }
  184. }
  185. if (! $absolute_discount && ! $absolute_creditnote)
  186. {
  187. print $langs->trans("CompanyHasNoAbsoluteDiscount");
  188. if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'<br>';
  189. else print '. ';
  190. }
  191. /*if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
  192. {
  193. if (! $absolute_discount && ! $absolute_creditnote) print '<br>';
  194. //print ' &nbsp; - &nbsp; ';
  195. print $addabsolutediscount;
  196. //print ' &nbsp; - &nbsp; '.$addcreditnote; // We disbale link to credit note
  197. }*/
  198. print '</td></tr>';
  199. // Dates
  200. print '<tr><td>'.$langs->trans("Date").'</td>';
  201. print '<td colspan="5">'.dol_print_date($object->date,"daytext").'</td>';
  202. print "</tr>";
  203. // Date payment term
  204. print '<tr><td>';
  205. print '<table class="nobordernopadding" width="100%"><tr><td>';
  206. print $langs->trans('DateMaxPayment');
  207. print '</td>';
  208. if ($object->type != 2 && $action != 'editpaymentterm' && $object->brouillon && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&amp;facid='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
  209. print '</tr></table>';
  210. print '</td><td colspan="5">';
  211. if ($object->type != 2)
  212. {
  213. if ($action == 'editpaymentterm')
  214. {
  215. $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date_lim_reglement,'paymentterm');
  216. }
  217. else
  218. {
  219. print dol_print_date($object->date_lim_reglement,'daytext');
  220. if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! $object->am) print img_warning($langs->trans('Late'));
  221. }
  222. }
  223. else
  224. {
  225. print '&nbsp;';
  226. }
  227. print '</td></tr>';
  228. // Conditions reglement
  229. print '<tr><td>'.$langs->trans("PaymentConditionsShort").'</td><td colspan="5">';
  230. $form->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->cond_reglement_id,"none");
  231. print '</td>';
  232. print '</td></tr>';
  233. // Mode de reglement
  234. print '<tr><td>';
  235. print '<table class="nobordernopadding" width="100%"><tr><td>';
  236. print $langs->trans('PaymentMode');
  237. print '</td>';
  238. if ($action != 'editmode' && $object->brouillon && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;facid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  239. print '</tr></table>';
  240. print '</td><td colspan="3">';
  241. if ($action == 'editmode')
  242. {
  243. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
  244. }
  245. else
  246. {
  247. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'none');
  248. }
  249. print '</td>';
  250. $nbrows=5;
  251. if ($conf->projet->enabled) $nbrows++;
  252. print '<td rowspan="'.$nbrows.'" colspan="2" valign="top">';
  253. /*
  254. * Documents
  255. */
  256. $objectref = dol_sanitizeFileName($object->ref);
  257. $dir_output = $conf->facture->dir_output . "/";
  258. $filepath = $dir_output . $objectref . "/";
  259. $file = $filepath . $objectref . ".pdf";
  260. $filedetail = $filepath . $objectref . "-detail.pdf";
  261. $relativepath = $objectref.'/'.$objectref.'.pdf';
  262. $relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf';
  263. // Chemin vers png apercus
  264. $fileimage = $file.".png"; // Si PDF d'1 page
  265. $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page
  266. $relativepathimage = $relativepath.'.png';
  267. $var=true;
  268. // Si fichier PDF existe
  269. if (file_exists($file))
  270. {
  271. $encfile = urlencode($file);
  272. print_titre($langs->trans("Documents"));
  273. print '<table class="border" width="100%">';
  274. print "<tr $bc[$var]><td>".$langs->trans("Bill")." PDF</td>";
  275. print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepath).'">'.$object->ref.'.pdf</a></td>';
  276. print '<td align="right">'.dol_print_size(dol_filesize($file)). '</td>';
  277. print '<td align="right">'.dol_print_date(dol_filemtime($file),'dayhour').'</td>';
  278. print '</tr>';
  279. // Si fichier detail PDF existe
  280. if (file_exists($filedetail)) // facture detaillee supplementaire
  281. {
  282. print "<tr $bc[$var]><td>Facture detaillee</td>";
  283. print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepathdetail).'">'.$object->ref.'-detail.pdf</a></td>';
  284. print '<td align="right">'.dol_print_size(dol_filesize($filedetail)).'</td>';
  285. print '<td align="right">'.dol_print_date(dol_filemtime($filedetail),'dayhour').'</td>';
  286. print '</tr>';
  287. }
  288. print "</table>\n";
  289. // Conversion du PDF en image png si fichier png non existant
  290. if (! file_exists($fileimage) && ! file_exists($fileimagebis))
  291. {
  292. if (class_exists("Imagick"))
  293. {
  294. $ret = dol_convert_file($file);
  295. if ($ret < 0) $error++;
  296. }
  297. else
  298. {
  299. $langs->load("errors");
  300. print '<font class="error">'.$langs->trans("ErrorNoImagickReadimage").'</font>';
  301. }
  302. }
  303. }
  304. print "</td></tr>";
  305. print '<tr><td>'.$langs->trans("AmountHT").'</td>';
  306. print '<td align="right" colspan="2"><b>'.price($object->total_ht).'</b></td>';
  307. print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
  308. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right" colspan="2" nowrap>'.price($object->total_tva).'</td>';
  309. print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
  310. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2" nowrap>'.price($object->total_ttc).'</td>';
  311. print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
  312. // Statut
  313. print '<tr><td>'.$langs->trans('Status').'</td><td align="left" colspan="3">'.($object->getLibStatut(4,$totalpaye)).'</td></tr>';
  314. // Projet
  315. if ($conf->projet->enabled)
  316. {
  317. $langs->load("projects");
  318. print '<tr>';
  319. print '<td>'.$langs->trans("Project").'</td><td colspan="3">';
  320. if ($object->fk_project > 0)
  321. {
  322. $project = New Project($db);
  323. $project->fetch($object->fk_project);
  324. print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$object->fk_project.'">'.$project->title.'</a>';
  325. }
  326. else
  327. {
  328. print '&nbsp;';
  329. }
  330. print '</td></tr>';
  331. }
  332. print '</table>';
  333. dol_fiche_end();
  334. }
  335. else
  336. {
  337. // Facture non trouvee
  338. print $langs->trans("ErrorBillNotFound",$_GET["facid"]);
  339. }
  340. }
  341. // Si fichier png PDF d'1 page trouve
  342. if (file_exists($fileimage))
  343. {
  344. print '<img src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercufacture&file='.urlencode($relativepathimage).'">';
  345. }
  346. // Si fichier png PDF de plus d'1 page trouve
  347. elseif (file_exists($fileimagebis))
  348. {
  349. $multiple = preg_replace('/\.png/','',$relativepath) . "-";
  350. for ($i = 0; $i < 20; $i++)
  351. {
  352. $preview = $multiple.$i.'.png';
  353. if (file_exists($dir_output.$preview))
  354. {
  355. print '<img src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercufacture&file='.urlencode($preview).'"><p>';
  356. }
  357. }
  358. }
  359. $db->close();
  360. llxFooter();
  361. ?>