PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/journal/sellsjournal.php

https://github.com/asterix14/dolibarr
PHP | 212 lines | 129 code | 33 blank | 50 comment | 16 complexity | d7200b4b34e430b03699dac86780e066 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/sellsjournal.php
  21. * \ingroup societe, facture
  22. * \brief Page with sells 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."/compta/facture/class/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. // Put here content of your page
  49. // ...
  50. $year_current = strftime("%Y",dol_now());
  51. $pastmonth = strftime("%m",dol_now()) - 1;
  52. $pastmonthyear = $year_current;
  53. if ($pastmonth == 0)
  54. {
  55. $pastmonth = 12;
  56. $pastmonthyear--;
  57. }
  58. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  59. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  60. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  61. {
  62. $date_start=dol_get_first_day($pastmonthyear,$pastmonth,false); $date_end=dol_get_last_day($pastmonthyear,$pastmonth,false);
  63. }
  64. $nom=$langs->trans("SellsJournal");
  65. //$nomlink=;
  66. $builddate=time();
  67. $description=$langs->trans("DescSellsJournal");
  68. $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);
  69. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  70. $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_PAYS);
  71. $idpays = $p[0];
  72. $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.ref_client , fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc,";
  73. $sql .= " p.accountancy_code_sell, s.code_compta , ct.accountancy_code";
  74. $sql .= " FROM ".MAIN_DB_PREFIX."facturedet fd ";
  75. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON p.rowid = fd.fk_product ";
  76. $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON f.rowid = fd.fk_facture ";
  77. $sql .= " JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid = f.fk_soc";
  78. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '".$idpays."'";
  79. $sql .= " WHERE f.fk_statut > 0 AND f.entity IN (0,".$conf->entity.")";
  80. if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  81. $sql .= " order by f.rowid";
  82. $result = $db->query($sql);
  83. if ($result)
  84. {
  85. $tabfac = array();
  86. $tabht = array();
  87. $tabtva = array();
  88. $tabttc = array();
  89. $num = $db->num_rows($result);
  90. $i=0;
  91. $resligne=array();
  92. while ($i < $num)
  93. {
  94. $obj = $db->fetch_object($result);
  95. // les variables
  96. $cptcli = (! empty($conf->global->COMPTA_ACCOUNT_CUSTOMER))?$conf->global->COMPTA_ACCOUNT_CUSTOMER:$langs->trans("CodeNotDef");
  97. $compta_soc = (! empty($obj->code_compta))?$obj->code_compta:$cptcli;
  98. $compta_prod = $obj->accountancy_code_sell;
  99. if (empty($compta_prod))
  100. {
  101. if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT))?$conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT:$langs->trans("CodeNotDef");
  102. else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_SOLD_ACCOUNT))?$conf->global->COMPTA_SERVICE_SOLD_ACCOUNT:$langs->trans("CodeNotDef");
  103. }
  104. $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT))?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef");
  105. $compta_tva = (! empty($obj->accountancy_code))?$obj->accountancy_code:$cpttva;
  106. //la ligne facture
  107. $tabfac[$obj->rowid]["date"] = $obj->datef;
  108. $tabfac[$obj->rowid]["ref"] = $obj->facnumber;
  109. $tabfac[$obj->rowid]["type"] = $obj->type;
  110. $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
  111. $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
  112. $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
  113. $i++;
  114. }
  115. }
  116. else {
  117. dol_print_error($db);
  118. }
  119. /*
  120. * Show result array
  121. */
  122. $i = 0;
  123. print "<table class=\"noborder\" width=\"100%\">";
  124. print "<tr class=\"liste_titre\">";
  125. //print "<td>".$langs->trans("JournalNum")."</td>";
  126. print "<td>".$langs->trans("Date")."</td><td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
  127. print "<td>".$langs->trans("Account")."</td>";
  128. print "<t><td>".$langs->trans("Type")."</td><td align='right'>".$langs->trans("Debit")."</td><td align='right'>".$langs->trans("Credit")."</td>";
  129. print "</tr>\n";
  130. $var=true;
  131. $r='';
  132. $invoicestatic=new Facture($db);
  133. foreach ($tabfac as $key => $val)
  134. {
  135. $invoicestatic->id=$key;
  136. $invoicestatic->ref=$val["ref"];
  137. $invoicestatic->type=$val["type"];
  138. print "<tr ".$bc[$var].">";
  139. // third party
  140. //print "<td>".$conf->global->COMPTA_JOURNAL_SELL."</td>";
  141. print "<td>".$val["date"]."</td>";
  142. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  143. foreach ($tabttc[$key] as $k => $mt)
  144. {
  145. 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>";
  146. }
  147. print "</tr>";
  148. // product
  149. foreach ($tabht[$key] as $k => $mt)
  150. {
  151. if ($mt)
  152. {
  153. print "<tr ".$bc[$var].">";
  154. //print "<td>".$conf->global->COMPTA_JOURNAL_SELL."</td>";
  155. print "<td>".$val["date"]."</td>";
  156. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  157. 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>";
  158. }
  159. }
  160. // vat
  161. //var_dump($tabtva);
  162. foreach ($tabtva[$key] as $k => $mt)
  163. {
  164. if ($mt)
  165. {
  166. print "<tr ".$bc[$var].">";
  167. //print "<td>".$conf->global->COMPTA_JOURNAL_SELL."</td>";
  168. print "<td>".$val["date"]."</td>";
  169. print "<td>".$invoicestatic->getNomUrl(1)."</td>";
  170. 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>";
  171. }
  172. }
  173. $var = !$var;
  174. }
  175. print "</table>";
  176. // End of page
  177. $db->close();
  178. llxFooter();
  179. ?>