PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/acquis/report_docacq.php

http://gevion.googlecode.com/
PHP | 320 lines | 263 code | 13 blank | 44 comment | 53 complexity | e569080266e7be51a1728bc6b488d80a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*$Id: report_docacq.php,v 1.24 2010/02/24 08:19:59 devincen Exp $
  3. --------------------------------------------------------------------------
  4. Gazie - Gestione Azienda
  5. Copyright (C) 2004-2010 - Antonio De Vincentiis Montesilvano (PE)
  6. (www.devincentiis.it)
  7. <http://gazie.sourceforge.net>
  8. --------------------------------------------------------------------------
  9. Questo programma e` free software; e` lecito redistribuirlo e/o
  10. modificarlo secondo i termini della Licenza Pubblica Generica GNU
  11. come e` pubblicata dalla Free Software Foundation; o la versione 2
  12. della licenza o (a propria scelta) una versione successiva.
  13. Questo programma e` distribuito nella speranza che sia utile, ma
  14. SENZA ALCUNA GARANZIA; senza neppure la garanzia implicita di
  15. NEGOZIABILITA` o di APPLICABILITA` PER UN PARTICOLARE SCOPO. Si
  16. veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.
  17. Ognuno dovrebbe avere ricevuto una copia della Licenza Pubblica
  18. Generica GNU insieme a questo programma; in caso contrario, si
  19. scriva alla Free Software Foundation, Inc., 59
  20. Temple Place, Suite 330, Boston, MA 02111-1307 USA Stati Uniti.
  21. --------------------------------------------------------------------------
  22. */
  23. require("../../library/include/datlib.inc.php");
  24. require("../vendit/class/class_scadenzario.php");
  25. $cscad = new ClassScadenzario();
  26. $admin_aziend=checkAdmin();
  27. $message = "";
  28. if (isset($_GET['auxil'])) {
  29. $auxil = $_GET['auxil'];
  30. $where = " tipdoc LIKE 'AF_' ";
  31. } else {
  32. $auxil = 1;
  33. $where = " tipdoc LIKE 'AF_' ";
  34. }
  35. if (isset($_GET['protoc'])) {
  36. if ($_GET['protoc'] > 0) {
  37. $protocollo = $_GET['protoc'];
  38. $auxil = $_GET['auxil']."&protoc=".$protocollo;
  39. $where = " tipdoc LIKE 'AF_' AND protoc = $protocollo ";
  40. $passo = 1;
  41. }
  42. } else {
  43. $protocollo ='';
  44. }
  45. if ((isset($_GET['clientdoc'])) and (!empty($_GET['clientdoc']))) {
  46. $clientdoc = $_GET['clientdoc'];
  47. $auxil = $_GET['auxil'];
  48. $where = " tipdoc LIKE 'AF_' AND ragso1 like '%".addslashes($clientdoc)."%'";
  49. $passo = 10000;
  50. $clientdoc = stripslashes($clientdoc);
  51. }
  52. if ((isset($_GET['per_data'])) and (!empty($_GET['per_data']))) {
  53. $per_data_selected = "checked";
  54. /*
  55. * gioemi=7&mesemi=2&annemi=2001
  56. */
  57. $auxil = $_GET['auxil'];
  58. $data_search_da = $_GET['annemi']."-".$_GET['mesemi']."-".$_GET['gioemi'];
  59. $data_search_a = $_GET['annami']."-".$_GET['mesami']."-".$_GET['gioami'];
  60. if (!empty($where)) {
  61. $where .= " AND datemi >= '".$data_search_da."' AND datemi <= '".$data_search_a."' ";
  62. } else {
  63. $where = " tipdoc LIKE 'AF_' datemi >= '".$data_search_da."' and datemi <= '".$data_search_a."' ";
  64. }
  65. $where .= " GROUP BY protoc, datfat ";
  66. } else {
  67. $_GET['annemi'] = date("Y");
  68. $_GET['mesemi'] = date("m");
  69. $_GET['gioemi'] = date("d");
  70. $_GET['annami'] = date("Y");
  71. $_GET['mesami'] = date("m");
  72. $_GET['gioami'] = date("d");
  73. }
  74. if (isset($_GET['all'])) {
  75. $where = "tipdoc LIKE 'AF_' GROUP BY protoc, datfat";
  76. $auxil = $_GET['auxil']."&all=yes";
  77. $passo = 100000;
  78. $protocollo ='';
  79. }
  80. $titolo="Documenti d'acquisto";
  81. require("../../library/include/header.php");
  82. $script_transl=HeadMain();
  83. ?>
  84. <table border="0" cellpadding="3" cellspacing="1" align="center" width="70%">
  85. <tr>
  86. <td class="FacetFormHeaderFont"><a href="admin_docacq.php?Insert&tipdoc=AFA" accesskey="F">Registra Fattura d'Acquisto Merce</a></td>
  87. <td class="FacetFormHeaderFont"><a href="admin_docacq.php?Insert&tipdoc=AFC" accesskey="N">Registra Nota Credito per Merce</a></td>
  88. <td class="FacetFormHeaderFont"><a href="accounting_documents.php?type=A" accesskey="C">Contabilizzazione fatture</a></td>
  89. </tr>
  90. </table>
  91. <form method="GET" >
  92. <div align="center" class="FacetFormHeaderFont"><?php echo $titolo; ?>
  93. </div>
  94. <?php
  95. if (!isset($_GET['field']) || ($_GET['field'] == 2) || (empty($_GET['field'])))
  96. $orderby = "datfat DESC, protoc DESC";
  97. $recordnav = new recordnav($gTables['tesdoc'], $where, $limit, $passo);
  98. $recordnav -> output();
  99. ?>
  100. <table class="Tlarge">
  101. <tr>
  102. <td colspan="2" class="FacetFieldCaptionTD">Protocollo:
  103. <input type="text" name="protoc" value="<?php if (isset($protocollo)) print $protocollo; ?>" maxlength="6" size="3" tabindex="1" class="FacetInput">
  104. </td>
  105. <td colspan="1" class="FacetFieldCaptionTD">Cliente:
  106. <input type="text" name="clientdoc" value="<?php if (isset($clientdoc)) print $clientdoc; ?>" maxlength="100" size="16" tabindex="1" class="FacetInput">
  107. </td>
  108. <td colspan="2" class="FacetFieldCaptionTD">
  109. <input type="checkbox" value="per_data" name="per_data" <?=$per_data_selected?>> Da:
  110. <?
  111. // select del giorno
  112. echo "\t <select name=\"gioemi\" class=\"FacetSelect\" >\n";
  113. for( $counter = 1; $counter <= 31; $counter++ )
  114. {
  115. $selected = "";
  116. if($counter == $_GET['gioemi'])
  117. $selected = "selected";
  118. echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
  119. }
  120. echo "\t </select>\n";
  121. // select del mese
  122. echo "\t <select name=\"mesemi\" class=\"FacetSelect\" >\n";
  123. for( $counter = 1; $counter <= 12; $counter++ )
  124. {
  125. $selected = "";
  126. if($counter == $_GET['mesemi'])
  127. $selected = "selected";
  128. $nome_mese = ucwords(strftime("%B", mktime (0,0,0,$counter,1,0)));
  129. echo "\t\t <option value=\"$counter\" $selected >$nome_mese</option>\n";
  130. }
  131. echo "\t </select>\n";
  132. // select del anno
  133. echo "\t <select name=\"annemi\" class=\"FacetSelect\" onchange=\"this.form.submit()\">\n";
  134. for( $counter = date("Y")-10; $counter <= date("Y")+10; $counter++ )
  135. {
  136. $selected = "";
  137. if($counter == $_GET['annemi'])
  138. $selected = "selected";
  139. echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
  140. }
  141. echo "\t </select>\n";
  142. ?>
  143. A:
  144. <?
  145. // select del giorno
  146. echo "\t <select name=\"gioami\" class=\"FacetSelect\" >\n";
  147. for( $counter = 1; $counter <= 31; $counter++ )
  148. {
  149. $selected = "";
  150. if($counter == $_GET['gioami'])
  151. $selected = "selected";
  152. echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
  153. }
  154. echo "\t </select>\n";
  155. // select del mese
  156. echo "\t <select name=\"mesami\" class=\"FacetSelect\" >\n";
  157. for( $counter = 1; $counter <= 12; $counter++ )
  158. {
  159. $selected = "";
  160. if($counter == $_GET['mesami'])
  161. $selected = "selected";
  162. $nome_mese = ucwords(strftime("%B", mktime (0,0,0,$counter,1,0)));
  163. echo "\t\t <option value=\"$counter\" $selected >$nome_mese</option>\n";
  164. }
  165. echo "\t </select>\n";
  166. // select del anno
  167. echo "\t <select name=\"annami\" class=\"FacetSelect\" onchange=\"this.form.submit()\">\n";
  168. for( $counter = date("Y")-10; $counter <= date("Y")+10; $counter++ )
  169. {
  170. $selected = "";
  171. if($counter == $_GET['annami'])
  172. $selected = "selected";
  173. echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
  174. }
  175. echo "\t </select>\n";
  176. ?>
  177. </td>
  178. <td>
  179. <input type="submit" name="search" value="Cerca" tabindex="1" onClick="javascript:document.report.all.value=1;">
  180. </td>
  181. <td>
  182. <input type="submit" name="all" value="Mostra tutti" onClick="javascript:document.report.all.value=1;">
  183. </td>
  184. </tr>
  185. <tr>
  186. <?php
  187. // creo l'array (header => campi) per l'ordinamento dei record
  188. $headers_tesdoc = array (
  189. "Prot." => "protoc",
  190. "Tipo" => "tipdoc",
  191. "Numero" => "numfat",
  192. "Data" => "datfat",
  193. "Cliente" => "ragso1",
  194. "Totale" => "",
  195. "Status" => "",
  196. "Stampa" => "",
  197. "Cancella" => ""
  198. );
  199. $linkHeaders = new linkHeaders($headers_tesdoc);
  200. $linkHeaders -> output();
  201. ?>
  202. </tr>
  203. <?php
  204. $rs_last_doc = gaz_dbi_dyn_query("MAX(protoc) AS maxpro, YEAR(datfat) AS y", $gTables['tesdoc'],"tipdoc LIKE 'AF_' GROUP BY y " ,'protoc DESC');
  205. while ($last_doc = gaz_dbi_fetch_array($rs_last_doc)){
  206. $lt_doc[$last_doc['y']]=$last_doc['maxpro'];
  207. }
  208. //recupero le testate in base alle scelte impostate
  209. $result = gaz_dbi_dyn_query($gTables['tesdoc'].".*,".$gTables['anagra'].".ragso1", $gTables['tesdoc']." LEFT JOIN ".$gTables['clfoco']." ON ".$gTables['tesdoc'].".clfoco = ".$gTables['clfoco'].".codice LEFT JOIN ".$gTables['anagra'].' ON '.$gTables['clfoco'].'.id_anagra = '.$gTables['anagra'].'.id', $where, $orderby,$limit, $passo);
  210. $ctrlprotoc = "";
  211. while ($a_row = gaz_dbi_fetch_array($result)) {
  212. $y=substr($a_row['datfat'],0,4);
  213. if ($a_row["tipdoc"] == 'AFA') {
  214. $tipodoc="Fattura";
  215. $modulo="stampa_docacq.php?id_tes=".$a_row['id_tes'];
  216. $modifi="admin_docacq.php?Update&id_tes=".$a_row['id_tes'];
  217. } elseif ($a_row["tipdoc"] == 'AFC') {
  218. $tipodoc="Nota Credito";
  219. $modulo="stampa_docacq.php?id_tes=".$a_row['id_tes'];
  220. $modifi="admin_docacq.php?Update&id_tes=".$a_row['id_tes'];
  221. }
  222. if ($a_row["protoc"] <> $ctrlprotoc) {
  223. print "<tr>";
  224. if (! empty ($modifi)) {
  225. print "<td class=\"FacetDataTD\"><a href=\"".$modifi."\">".$a_row["protoc"]."</td>";
  226. } else {
  227. print "<td class=\"FacetDataTD\">".$a_row["protoc"]." &nbsp;</td>";
  228. }
  229. print "<td class=\"FacetDataTD\">".$tipodoc." &nbsp;</td>";
  230. print "<td class=\"FacetDataTD\">".$a_row["numfat"]." &nbsp;</td>";
  231. print "<td class=\"FacetDataTD\">".$a_row["datfat"]." &nbsp;</td>";
  232. print "<td class=\"FacetDataTD\">".$a_row["ragso1"]."&nbsp;</td>";
  233. try {
  234. $totivafat = 0;
  235. $ivacast = 0;
  236. //scarico tutte le variabili precedentemente valorizzate
  237. //mi ricavo il totale dell'ultima fattura
  238. $ay_rigdoc = $cscad->get_all_rigdoc($a_row['id_tes'], $gTables['rigdoc']);
  239. //recupero i dati relativi alla fattura
  240. $ay_tesdoc = $cscad->get_tesdoc_from_idtes($a_row['id_tes'], $gTables['tesdoc'], $gTables['pagame']);
  241. //calcolo il castelletto IVA
  242. $ay_castle = $cscad->get_castle_for_rigdoc($ay_rigdoc, $ay_tesdoc['tesdoc']['sconto']);
  243. //calcolo tutte le spese relative alla fattura appena ricevuta
  244. $tot_spese = $cscad->calc_tot_spese($ay_tesdoc);
  245. //inserisco nella variabile last l'ultimo entry dell'array decalc_castle
  246. $last = count($ay_castle['decalc_castle']);
  247. //inserisco nella variabile acc_val il valore di tot_spese
  248. $acc_val = $tot_spese;
  249. // leggo l'intero array castle e lo analizzo
  250. foreach ($ay_castle['castle'] as $k=>$v) {
  251. //recupero l'iva che interessa il rigo del castelletto e la salvo in variabile
  252. $vat = $cscad->get_iva($k, $gTables['aliiva']);
  253. if (isset($ay_castle['decalc_castle'][$k])) {
  254. $last--;
  255. if ($last==0) {
  256. $v += $acc_val;
  257. $ay_castle['totimpfat'] += $acc_val;
  258. } else {
  259. $decalc=round($tot_spese*$v/$ay_castle['totimp_decalc'],2);
  260. $v += $decalc;
  261. $ay_castle['totimpfat'] += $decalc;
  262. $acc_val-=$decalc;
  263. }
  264. }
  265. $ivacast = round($v*$vat['aliquo'])/100;
  266. $totivafat += $ivacast;
  267. }
  268. // calcolo il totale importo della fattura
  269. $tot_fattura = $ay_castle['totimpfat']+$totivafat+$ay_tesdoc['stamp']-$ay_castle['rit'];
  270. $tot_finale = $tot_finale+$tot_fattura;
  271. } catch (Exception $e) {
  272. $feedback = $e->getMessage();
  273. }
  274. if (isset($feedback)) {
  275. echo "<td class=\"FacetDataTD\"> ".$feedback." &nbsp;</td>";
  276. } else {
  277. echo "<td class=\"FacetDataTD\"> &euro; ".$tot_fattura." &nbsp;</td>";
  278. }
  279. if ($a_row["id_con"] > 0) {
  280. echo "<td class=\"FacetDataTD\" align=\"center\"><a href=\"../contab/admin_movcon.php?id_tes=".$a_row["id_con"]."&Update\">Cont. n.".$a_row["id_con"]."</a></td>";
  281. } else {
  282. echo "<td class=\"FacetDataTD\" align=\"center\"><a href=\"accounting_documents.php?type=A&last=".$a_row["protoc"]."\">Contabilizza</a></td>";
  283. }
  284. print "<td class=\"FacetDataTD\"><a href=\"".$modulo."\"><center><img src=\"../../library/images/stampa.gif\" alt=\"Stampa\" border=\"0\"></a></td>";
  285. if (($lt_doc[$y]==$a_row['protoc']) && ($a_row["id_con"]==0)) {
  286. print "<td class=\"FacetDataTD\"><a href=\"delete_docacq.php?id_tes=".$a_row["id_tes"]."\"><center><img src=\"../../library/images/x.gif\" alt=\"Cancella\" border=\"0\"></a></td>";
  287. } else {
  288. print "<td class=\"FacetDataTD\"></td>";
  289. }
  290. print "</tr>\n";
  291. }
  292. $ctrlprotoc = $a_row["protoc"];
  293. }
  294. ?>
  295. </form>
  296. </table>
  297. <!-- CREAZIONE TABELLA CONTENTE IL TOTALE GENERICO DEL REPORT RICHIESTO -->
  298. <table align="right" border="1" cellspacing="1">
  299. <tr>
  300. <td class="FacetFieldCaptionTD"><strong>TOTALE</strong></td>
  301. <td class="FacetDataTD">&euro; <?=$tot_finale?></td>
  302. </tr>
  303. </table>
  304. </body>
  305. </html>