monthlystatsindex.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. $res = 0;
  3. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  4. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  5. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  6. }
  7. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  8. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  9. $tmp2 = realpath(__FILE__);
  10. $i = strlen($tmp) - 1;
  11. $j = strlen($tmp2) - 1;
  12. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  13. $i--;
  14. $j--;
  15. }
  16. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  17. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  18. }
  19. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  20. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  21. }
  22. // Try main.inc.php using relative path
  23. if (!$res && file_exists("../main.inc.php")) {
  24. $res = @include "../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../main.inc.php")) {
  27. $res = @include "../../main.inc.php";
  28. }
  29. if (!$res && file_exists("../../../main.inc.php")) {
  30. $res = @include "../../../main.inc.php";
  31. }
  32. if (!$res) {
  33. die("Include of main fails");
  34. }
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/userinvoice.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  42. $helper = new HelperUserInvoice($db);
  43. $commmissionhandler = new CommissionHandler();
  44. $userObj = new User($db);
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("financialreport@financialreport"));
  47. $action = GETPOST('action', 'aZ09');
  48. $id = GETPOST('id', 'int');
  49. $idmenu = GETPOST('idmenu', 'int');
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $search_nickname = GETPOST('search_nickname', 'alpha');
  54. $search_name = GETPOST('search_name', 'alpha');
  55. $search_login = GETPOST('search_login', 'alpha');
  56. $searchArray = ['search_name' => $search_name, 'search_nickname' => $search_nickname];
  57. $confirmmakeupto = GETPOST('confirmmakeupto', 'alpha');
  58. $datastring = GETPOST('datastring', 'alpha');
  59. $year = GETPOST('year', 'int');
  60. $month = GETPOST('month', 'int') < 10 ? '0' . GETPOST('month', 'int') : GETPOST('month', 'int');
  61. $excelexport = GETPOST('excelexport', 'int');
  62. $search = array();
  63. foreach ($searchArray as $key => $val) {
  64. if (GETPOST($key, 'alpha') !== '') {
  65. $search[$key] = GETPOST($key, 'alpha');
  66. }
  67. }
  68. if (GETPOST('button_removefilter_x', 'alpha')) {
  69. foreach ($searchArray as $key => $val) {
  70. $search[$key] = '';
  71. $searchArray[$key] = '';
  72. $$key = '';
  73. }
  74. }
  75. if (!$sortorder) {
  76. $sortorder = "ASC";
  77. }
  78. $form = new Form($db);
  79. $formfile = new FormFile($db);
  80. if($year == '' || $year == 0 || empty($year) || is_null($year)){
  81. $year = date("Y");
  82. }
  83. if($month == '' || $month == 0 || empty($month) || is_null($month)){
  84. $month = date("m");
  85. }
  86. function getLastDayOfMonth($year, $month) {
  87. $lastDay = date('t', mktime(0, 0, 0, $month, 1, $year));
  88. return $lastDay;
  89. }
  90. $lastDayOfMonth = getLastDayOfMonth($year, $month);
  91. $from = $year . '-' . $month . '-01';
  92. $to = $year . '-' . $month . '-' . $lastDayOfMonth;
  93. $saledTickets = [];
  94. $sql = "SELECT
  95. f.type,
  96. f.ref,
  97. e.label,
  98. c.value,
  99. f.datef,
  100. f.datef,
  101. f.date_lim_reglement,
  102. fdet.total_ht,
  103. fdet.total_tva,
  104. fdet.total_ttc,
  105. fdet.multicurrency_total_ht,
  106. fdet.multicurrency_total_tva,
  107. fdet.multicurrency_total_ttc,
  108. fdet.multicurrency_code,
  109. pai.libelle,
  110. fdet.tva_tx,
  111. f.date_closing
  112. FROM llx_facture as f
  113. INNER JOIN llx_facturedet as fdet ON fdet.fk_facture = f.rowid
  114. INNER JOIN llx_entity as e ON e.rowid = f.entity
  115. INNER JOIN llx_const as c ON c.entity = f.entity
  116. INNER JOIN llx_c_paiement as pai ON pai.id = f.fk_mode_reglement
  117. WHERE f.datec BETWEEN '{$from} 00:00:00' AND '{$to} 23:59:59'
  118. AND f.entity = {$entity}
  119. AND c.name = 'MAIN_INFO_TVAINTRA'
  120. AND f.date_closing IS NOT NULL
  121. ORDER BY f.datec ASC";
  122. //print $sql;
  123. $data = $db->query($sql);
  124. while($row=$db->fetch_object($data))
  125. {
  126. $saledTickets[] = $row;
  127. }
  128. $daterange = $from . ' - ' . $to;
  129. if($excelexport){
  130. $helper->createExcelMonthlyExport($daterange, $entity, $saledTickets);
  131. }
  132. $title = $langs->trans('MonthlyStatistic');
  133. $help_url = '';
  134. $morejs = '';
  135. $morecss = '';
  136. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  137. $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=';
  138. print '<form method="POST" id="witholdingForm" action="' . $url . '">' . "\n";
  139. print '<input type="hidden" name="token" value="' . newToken() . '">';
  140. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  141. print '<input type="hidden" name="action" value="list">';
  142. print '<input type="hidden" name="year" value="' . $year . '">';
  143. print load_fiche_titre($langs->trans("MonthlyStatistic"), '', 'financialreport.png@financialreport');
  144. print '<div style="height: 50px; background-color: lightgray; text-align: center; padding-top: 20px; border-radius: 10px;">';
  145. include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/tpl/daterangedivbasecommission.tpl.php';
  146. print '</div>';
  147. print '<div class="center" style="margin-bottom: 30px;"><button class="ExcelExport" type="submit" name="excelexport", value="1">' . $langs->trans('Excel export') . '</button></div>';
  148. print '
  149. <table style="width:100%;">
  150. <tr>
  151. <th>' . $langs->trans("Facture") . '</th>
  152. <th>' . $langs->trans("Type") . '</th>
  153. <th>' . $langs->trans("Entity") . '</th>
  154. <th>' . $langs->trans("VATnumber") . '</th>
  155. <th>' . $langs->trans("DateCreation") . '</th>
  156. <th>' . $langs->trans("DateCompletion") . '</th>
  157. <th>' . $langs->trans("PaymentDeadline") . '</th>
  158. <th>' . $langs->trans("NetHUF") . '</th>
  159. <th>' . $langs->trans("VatHUF") . '</th>
  160. <th>' . $langs->trans("GrossHUF") . '</th>
  161. <th>' . $langs->trans("Net") . '</th>
  162. <th>' . $langs->trans("VAT") . '</th>
  163. <th>' . $langs->trans("Gross") . '</th>
  164. <th>' . $langs->trans("Currency") . '</th>
  165. <th>' . $langs->trans("PaymentMethod") . '</th>
  166. <th>' . $langs->trans("VAT") . ' %</th>
  167. </tr>';
  168. //include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/tpl/search_fields_for_userslist.tpl.php';
  169. //$helper->tableDrawerForBasicCommission($allSalesUsers, $db, $idmenu, $year, $month);
  170. foreach($saledTickets as $item)
  171. {
  172. $mtht = $item->multicurrency_total_ht == $item->total_ht ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
  173. $mttva = $item->multicurrency_total_tva == $item->total_tva ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
  174. $mtttc = $item->multicurrency_total_ttc == $item->total_ttc ? '' : number_format($item->multicurrency_total_ttc, 4, ',', ' ');
  175. print '<tr class="center">
  176. <td>' . $item->ref . '</td>
  177. <td>' . $helper->getFectureType($item->type) . '</td>
  178. <td>' . $item->label . '</td>
  179. <td>' . $item->value . '</td>
  180. <td>' . $item->datef . '</td>
  181. <td>' . $item->date_lim_reglement . '</td>
  182. <td>' . $item->datef . '</td>
  183. <td>' . number_format($item->total_ht, 4, ',', ' ') . '</td>
  184. <td>' . number_format($item->total_tva, 4, ',', ' ') . '</td>
  185. <td>' . number_format($item->total_ttc, 4, ',', ' ') . '</td>
  186. <td>' . $mtht . '</td>
  187. <td>' . $mttva . '</td>
  188. <td>' . $mtttc . '</td>
  189. <td>' . $item->multicurrency_code . '</td>
  190. <td>' . $item->libelle . '</td>
  191. <td>' . number_format($item->tva_tx, 0) . ' %</td>
  192. </tr>';
  193. }
  194. print '</table>';
  195. print '</form>' . "\n";
  196. // End of page
  197. llxFooter();
  198. $db->close();
  199. ?>
  200. <style>
  201. .ExcelExport{
  202. margin-top: 20px;
  203. width: 200px;
  204. height: 30px;
  205. background-color: rgb(163, 0, 51);
  206. color: white;
  207. border-radius: 20px;
  208. border: none;
  209. cursor: pointer;
  210. background-color: green;
  211. }
  212. </style>