PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/journal/purchasesjournal.php

https://github.com/asterix14/dolibarr
PHP | 210 lines | 130 code | 32 blank | 48 comment | 16 complexity | a21cef1a601e18adadb1164094027ee4 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/journal/purchasesjournal.php
  21. * \ingroup societe, fournisseur, facture
  22. * \brief Page with purchases journal
  23. */
  24. require("../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/report.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php");
  28. $langs->load("companies");
  29. $langs->load("other");
  30. $langs->load("compta");
  31. // Protection if external user
  32. if ($user->societe_id > 0)
  33. {
  34. accessforbidden();
  35. }
  36. /*******************************************************************
  37. * ACTIONS
  38. *
  39. * Put here all code to do according to value of "action" parameter
  40. ********************************************************************/
  41. /***************************************************
  42. * PAGE
  43. *
  44. * Put here all code to build page
  45. ****************************************************/
  46. llxHeader('','','');
  47. $form=new Form($db);
  48. $year_current = strftime("%Y",dol_now());
  49. $pastmonth = strftime("%m",dol_now()) - 1;
  50. $pastmonthyear = $year_current;
  51. if ($pastmonth == 0)
  52. {
  53. $pastmonth = 12;
  54. $pastmonthyear--;
  55. }
  56. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  57. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  58. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  59. {
  60. $date_start=dol_get_first_day($pastmonthyear,$pastmonth,false); $date_end=dol_get_last_day($pastmonthyear,$pastmonth,false);
  61. }
  62. $nom=$langs->trans("PurchasesJournal");
  63. //$nomlink=;
  64. $builddate=time();
  65. $description=$langs->trans("DescPurchasesJournal");
  66. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  67. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  68. $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_PAYS);
  69. $idpays = $p[0];
  70. $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.libelle,";
  71. $sql .= " fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type,";
  72. $sql .= " s.code_compta_fournisseur, p.accountancy_code_buy , ct.accountancy_code";
  73. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det fd ";
  74. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '".$idpays."'";
  75. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON p.rowid = fd.fk_product ";
  76. $sql .= " JOIN ".MAIN_DB_PREFIX."facture_fourn f ON f.rowid = fd.fk_facture_fourn ";
  77. $sql .= " JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid = f.fk_soc" ;
  78. $sql .= " WHERE f.fk_statut > 0 AND f.entity IN (0,".$conf->entity.")";
  79. if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  80. $result = $db->query($sql);
  81. if ($result)
  82. {
  83. $num = $db->num_rows($result);
  84. // les variables
  85. $cptfour = (! empty($conf->global->COMPTA_ACCOUNT_SUPPLIER))?$conf->global->COMPTA_ACCOUNT_SUPPLIER:$langs->trans("CodeNotDef");
  86. $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT))?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef");
  87. $tabfac = array();
  88. $tabht = array();
  89. $tabtva = array();
  90. $tabttc = array();
  91. $i=0;
  92. while ($i < $num)
  93. {
  94. $obj = $db->fetch_object($result);
  95. // contr么les
  96. $compta_soc = (! empty($obj->code_compta_fournisseur))?$obj->code_compta_fournisseur:$cptfour;
  97. $compta_prod = $obj->accountancy_code_buy;
  98. if (empty($compta_prod))
  99. {
  100. if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_BUY_ACCOUNT))?$conf->global->COMPTA_PRODUCT_BUY_ACCOUNT:$langs->trans("CodeNotDef");
  101. else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_BUY_ACCOUNT))?$conf->global->COMPTA_SERVICE_BUY_ACCOUNT:$langs->trans("CodeNotDef");
  102. }
  103. $compta_tva = (! empty($obj->accountancy_code))?$obj->accountancy_code:$cpttva;
  104. $tabfac[$obj->rowid]["date"] = $obj->datef;
  105. $tabfac[$obj->rowid]["ref"] = $obj->facnumber;
  106. $tabfac[$obj->rowid]["type"] = $obj->type;
  107. $tabfac[$obj->rowid]["lib"] = $obj->libelle;
  108. $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
  109. $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
  110. $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
  111. $i++;
  112. }
  113. }
  114. else {
  115. dol_print_error($db);
  116. }
  117. /*
  118. * Show result array
  119. */
  120. $i = 0;
  121. print "<table class=\"noborder\" width=\"100%\">";
  122. print "<tr class=\"liste_titre\">";
  123. ///print "<td>".$langs->trans("JournalNum")."</td>";
  124. print "<td>".$langs->trans("Date")."</td>";
  125. print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
  126. print "<td>".$langs->trans("Account")."</td>";
  127. print "<t><td>".$langs->trans("Type")."</td><td align='right'>".$langs->trans("Debit")."</td><td align='right'>".$langs->trans("Credit")."</td>";
  128. print "</tr>\n";
  129. $var=true;
  130. $r='';
  131. $invoicestatic=new FactureFournisseur($db);
  132. foreach ($tabfac as $key => $val)
  133. {
  134. $invoicestatic->id=$key;
  135. $invoicestatic->ref=$val["ref"];
  136. $invoicestatic->type=$val["type"];
  137. print "<tr ".$bc[$var]." >";
  138. // third party
  139. //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
  140. print "<td>".$val["date"]."</td>";
  141. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  142. foreach ($tabttc[$key] as $k => $mt)
  143. {
  144. print "<td>".$k."</td><td>".$langs->trans("ThirdParty")."</td><td align='right'>".($mt>=0?price($mt):'')."</td><td align='right'>".($mt<0?-price(-$mt):'')."</td>";
  145. }
  146. print "</tr>";
  147. // product
  148. foreach ($tabht[$key] as $k => $mt)
  149. {
  150. if ($mt)
  151. {
  152. print "<tr ".$bc[$var]." >";
  153. //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
  154. print "<td>".$val["date"]."</td>";
  155. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  156. print "<td>".$k."</td><td>".$langs->trans("Products")."</td><td align='right'>".($mt<0?price(-$mt):'')."</td><td align='right'>".($mt>=0?price($mt):'')."</td></tr>";
  157. }
  158. }
  159. // vat
  160. //var_dump($tabtva);
  161. foreach ($tabtva[$key] as $k => $mt)
  162. {
  163. if ($mt)
  164. {
  165. print "<tr ".$bc[$var]." >";
  166. //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
  167. print "<td>".$val["date"]."</td>";
  168. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  169. print "<td>".$k."</td><td>".$langs->trans("VAT")." ".$key."</td><td align='right'>".($mt<0?price(-$mt):'')."</td><td align='right'>".($mt>=0?price($mt):'')."</td></tr>";
  170. }
  171. }
  172. $var = !$var;
  173. }
  174. print "</table>";
  175. // End of page
  176. $db->close();
  177. llxFooter();
  178. ?>