cashcontrol_card.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/cashcontrol/cashcontrol_card.php
  25. * \ingroup cashdesk|takepos
  26. * \brief Page to show a cash fence
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
  32. $langs->loadLangs(array("install", "cashdesk", "admin", "banks"));
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. $categid = GETPOST('categid');
  37. $label = GETPOST("label");
  38. $now = dol_now();
  39. $syear = (GETPOSTISSET('closeyear') ?GETPOST('closeyear', 'int') : dol_print_date($now, "%Y"));
  40. $smonth = (GETPOSTISSET('closemonth') ?GETPOST('closemonth', 'int') : dol_print_date($now, "%m"));
  41. $sday = (GETPOSTISSET('closeday') ?GETPOST('closeday', 'int') : dol_print_date($now, "%d"));
  42. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. if (empty($page) || $page == -1) {
  47. $page = 0;
  48. } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (!$sortfield) {
  53. $sortfield = 'rowid';
  54. }
  55. if (!$sortorder) {
  56. $sortorder = 'ASC';
  57. }
  58. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
  59. if ($contextpage == 'takepos') {
  60. $_GET['optioncss'] = 'print';
  61. }
  62. $arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
  63. $arrayofposavailable = array();
  64. if (!empty($conf->cashdesk->enabled)) {
  65. $arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
  66. }
  67. if (!empty($conf->takepos->enabled)) {
  68. $arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
  69. }
  70. // TODO Add hook here to allow other POS to add themself
  71. $object = new CashControl($db);
  72. $extrafields = new ExtraFields($db);
  73. // fetch optionals attributes and labels
  74. $extrafields->fetch_name_optionals_label($object->table_element);
  75. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  76. $hookmanager->initHooks(array('cashcontrolcard', 'globalcard'));
  77. // Load object
  78. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  79. // Security check
  80. if ($user->socid > 0) { // Protection if external user
  81. //$socid = $user->socid;
  82. accessforbidden();
  83. }
  84. if (!$user->rights->cashdesk->run && !$user->rights->takepos->run) {
  85. accessforbidden();
  86. }
  87. /*
  88. * Actions
  89. */
  90. $permissiontoadd = ($user->rights->cashdesk->run || $user->rights->takepos->run);
  91. $permissiontodelete = ($user->rights->cashdesk->run || $user->rights->takepos->run) || ($permissiontoadd && $object->status == 0);
  92. if (empty($backtopage)) {
  93. $backtopage = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.($id > 0 ? $id : '__ID__');
  94. }
  95. $backurlforlist = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php';
  96. $triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
  97. if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1)) {
  98. setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
  99. }
  100. if (GETPOST('cancel', 'alpha')) {
  101. if ($action == 'valid') {
  102. $action = 'view';
  103. } else {
  104. $action = 'create';
  105. }
  106. }
  107. if ($action == "reopen") {
  108. $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
  109. if ($result < 0) {
  110. setEventMessages($object->error, $object->error, 'errors');
  111. }
  112. $action = 'view';
  113. }
  114. if ($action == "start") {
  115. $error = 0;
  116. if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1') {
  117. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
  118. $action = 'create';
  119. $error++;
  120. }
  121. if (GETPOST('posnumber', 'alpha') == '') {
  122. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
  123. $action = 'create';
  124. $error++;
  125. }
  126. if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1') {
  127. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
  128. $action = 'create';
  129. $error++;
  130. }
  131. } elseif ($action == "add") {
  132. if (GETPOST('opening', 'alpha') == '') {
  133. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
  134. $action = 'start';
  135. $error++;
  136. }
  137. $error = 0;
  138. foreach ($arrayofpaymentmode as $key => $val) {
  139. $object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
  140. }
  141. if (!$error) {
  142. $object->day_close = GETPOST('closeday', 'int');
  143. $object->month_close = GETPOST('closemonth', 'int');
  144. $object->year_close = GETPOST('closeyear', 'int');
  145. $object->opening = price2num(GETPOST('opening', 'alpha'));
  146. $object->posmodule = GETPOST('posmodule', 'alpha');
  147. $object->posnumber = GETPOST('posnumber', 'alpha');
  148. $db->begin();
  149. $id = $object->create($user);
  150. if ($id > 0) {
  151. $db->commit();
  152. $action = "view";
  153. } else {
  154. $db->rollback;
  155. $action = "view";
  156. }
  157. }
  158. if ($contextpage == 'takepos') {
  159. print "
  160. <script>
  161. parent.location.href='../../takepos/index.php?place='+parent.place;
  162. </script>";
  163. exit;
  164. }
  165. }
  166. if ($action == "valid") { // validate = close
  167. $object->fetch($id);
  168. $db->begin();
  169. /*
  170. $object->day_close = GETPOST('closeday', 'int');
  171. $object->month_close = GETPOST('closemonth', 'int');
  172. $object->year_close = GETPOST('closeyear', 'int');
  173. */
  174. $object->cash = price2num(GETPOST('cash_amount', 'alpha'));
  175. $object->card = price2num(GETPOST('card_amount', 'alpha'));
  176. $object->cheque = price2num(GETPOST('cheque_amount', 'alpha'));
  177. $result = $object->update($user);
  178. $result = $object->valid($user);
  179. if ($result <= 0) {
  180. setEventMessages($object->error, $object->errors, 'errors');
  181. $db->rollback();
  182. } else {
  183. setEventMessages($langs->trans("CashFenceDone"), null);
  184. $db->commit();
  185. }
  186. if ($contextpage == 'takepos') {
  187. print "
  188. <script>
  189. parent.location.href='../../takepos/index.php?place='+parent.place;
  190. </script>";
  191. exit;
  192. }
  193. $action = "view";
  194. }
  195. // Action to delete
  196. if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
  197. $object->fetch($id);
  198. if (!($object->id > 0)) {
  199. dol_print_error('', 'Error, object must be fetched before being deleted');
  200. exit;
  201. }
  202. $result = $object->delete($user);
  203. //var_dump($result);
  204. if ($result > 0) {
  205. // Delete OK
  206. setEventMessages("RecordDeleted", null, 'mesgs');
  207. header("Location: ".$backurlforlist);
  208. exit;
  209. } else {
  210. if (!empty($object->errors)) {
  211. setEventMessages(null, $object->errors, 'errors');
  212. } else {
  213. setEventMessages($object->error, null, 'errors');
  214. }
  215. }
  216. }
  217. /*
  218. * View
  219. */
  220. $form = new Form($db);
  221. $initialbalanceforterminal = array();
  222. $theoricalamountforterminal = array();
  223. $theoricalnbofinvoiceforterminal = array();
  224. if ($action == "create" || $action == "start" || $action == 'close') {
  225. if ($action == 'close') {
  226. $posmodule = $object->posmodule;
  227. $terminalid = $object->posnumber;
  228. $terminaltouse = $terminalid;
  229. $syear = $object->year_close;
  230. $smonth = $object->month_close;
  231. $sday = $object->day_close;
  232. } elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') {
  233. $posmodule = GETPOST('posmodule', 'alpha');
  234. $terminalid = GETPOST('posnumber', 'alpha');
  235. $terminaltouse = $terminalid;
  236. if ($terminaltouse == '1' && $posmodule == 'cashdesk') {
  237. $terminaltouse = '';
  238. }
  239. if ($posmodule == 'cashdesk' && $terminaltouse != '' && $terminaltouse != '1') {
  240. $terminaltouse = '';
  241. setEventMessages($langs->trans("OnlyTerminal1IsAvailableForCashDeskModule"), null, 'errors');
  242. $error++;
  243. }
  244. }
  245. if ($terminalid != '') {
  246. // Calculate $initialbalanceforterminal for terminal 0
  247. foreach ($arrayofpaymentmode as $key => $val) {
  248. if ($key != 'cash') {
  249. $initialbalanceforterminal[$terminalid][$key] = 0;
  250. continue;
  251. }
  252. // Get the bank account dedicated to this point of sale module/terminal
  253. $vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
  254. $bankid = $conf->global->$vartouse;
  255. if ($bankid > 0) {
  256. $sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
  257. $sql .= " WHERE fk_account = ".((int) $bankid);
  258. if ($syear && !$smonth) {
  259. $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
  260. } elseif ($syear && $smonth && !$sday) {
  261. $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
  262. } elseif ($syear && $smonth && $sday) {
  263. $sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
  264. } else {
  265. setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
  266. }
  267. $resql = $db->query($sql);
  268. if ($resql) {
  269. $obj = $db->fetch_object($resql);
  270. if ($obj) {
  271. $initialbalanceforterminal[$terminalid][$key] = $obj->total;
  272. }
  273. } else {
  274. dol_print_error($db);
  275. }
  276. } else {
  277. setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
  278. $error++;
  279. }
  280. }
  281. // Calculate $theoricalamountforterminal
  282. foreach ($arrayofpaymentmode as $key => $val) {
  283. $sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
  284. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as cp";
  285. $sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
  286. $sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
  287. $sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
  288. $sql .= " AND f.paye = 1";
  289. $sql .= " AND p.entity IN (".getEntity('facture').")";
  290. if ($key == 'cash') {
  291. $sql .= " AND cp.code = 'LIQ'";
  292. } elseif ($key == 'cheque') {
  293. $sql .= " AND cp.code = 'CHQ'";
  294. } elseif ($key == 'card') {
  295. $sql .= " AND cp.code = 'CB'";
  296. } else {
  297. dol_print_error('Value for key = '.$key.' not supported');
  298. exit;
  299. }
  300. if ($syear && !$smonth) {
  301. $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
  302. } elseif ($syear && $smonth && !$sday) {
  303. $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
  304. } elseif ($syear && $smonth && $sday) {
  305. $sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
  306. } else {
  307. setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
  308. }
  309. $resql = $db->query($sql);
  310. if ($resql) {
  311. $theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
  312. $obj = $db->fetch_object($resql);
  313. if ($obj) {
  314. $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
  315. $theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
  316. }
  317. } else {
  318. dol_print_error($db);
  319. }
  320. }
  321. }
  322. //var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal);
  323. if ($action != 'close') {
  324. llxHeader('', $langs->trans("NewCashFence"));
  325. print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register');
  326. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  327. print '<input type="hidden" name="token" value="'.newToken().'">';
  328. if ($contextpage == 'takepos') {
  329. print '<input type="hidden" name="contextpage" value="takepos">';
  330. }
  331. if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
  332. print '<input type="hidden" name="action" value="add">';
  333. } elseif ($action == 'close') {
  334. print '<input type="hidden" name="action" value="valid">';
  335. print '<input type="hidden" name="id" value="'.$id.'">';
  336. } else {
  337. print '<input type="hidden" name="action" value="start">';
  338. }
  339. print '<div class="div-table-responsive-no-min">';
  340. print '<table class="noborder centpercent">';
  341. print '<tr class="liste_titre">';
  342. print '<td>'.$langs->trans("Module").'</td>';
  343. print '<td>'.$langs->trans("Terminal").'</td>';
  344. print '<td>'.$langs->trans("Year").'</td>';
  345. print '<td>'.$langs->trans("Month").'</td>';
  346. print '<td>'.$langs->trans("Day").'</td>';
  347. print '<td></td>';
  348. print "</tr>\n";
  349. $disabled = 0;
  350. $prefix = 'close';
  351. print '<tr class="oddeven">';
  352. print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).'</td>';
  353. print '<td>';
  354. $array = array();
  355. $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
  356. for ($i = 1; $i <= $numterminals; $i++) {
  357. $array[$i] = $i;
  358. }
  359. $selectedposnumber = 0;
  360. $showempty = 1;
  361. if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') {
  362. $selectedposnumber = 1;
  363. $showempty = 0;
  364. }
  365. print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
  366. //print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
  367. print '</td>';
  368. // Year
  369. print '<td>';
  370. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
  371. for ($year = $syear - 10; $year < $syear + 10; $year++) {
  372. $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
  373. }
  374. $retstring .= "</select>\n";
  375. print $retstring;
  376. print '</td>';
  377. // Month
  378. print '<td>';
  379. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
  380. $retstring .= '<option value="0"></option>';
  381. for ($month = 1; $month <= 12; $month++) {
  382. $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
  383. $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
  384. $retstring .= "</option>";
  385. }
  386. $retstring .= "</select>";
  387. print $retstring;
  388. print '</td>';
  389. // Day
  390. print '<td>';
  391. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
  392. $retstring .= '<option value="0" selected>&nbsp;</option>';
  393. for ($day = 1; $day <= 31; $day++) {
  394. $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
  395. }
  396. $retstring .= "</select>";
  397. print $retstring;
  398. print '</td>';
  399. // Button Start
  400. print '<td>';
  401. if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
  402. print '';
  403. } else {
  404. print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
  405. }
  406. print '</td>';
  407. print '</table>';
  408. print '</div>';
  409. // Table to see/enter balance
  410. if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
  411. $posmodule = GETPOST('posmodule', 'alpha');
  412. $terminalid = GETPOST('posnumber', 'alpha');
  413. print '<br>';
  414. print '<div class="div-table-responsive-no-min">';
  415. print '<table class="noborder centpercent">';
  416. print '<tr class="liste_titre">';
  417. print '<td></td>';
  418. print '<td class="center">'.$langs->trans("InitialBankBalance");
  419. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  420. print '</td>';
  421. /*
  422. print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
  423. print $langs->trans("AmountAtEndOfPeriod");
  424. print '</td>';
  425. */
  426. print '<td></td>';
  427. print '</tr>';
  428. print '<tr class="liste_titre">';
  429. print '<td></td>';
  430. print '<td class="center">'.$langs->trans("Cash");
  431. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  432. print '</td>';
  433. /*
  434. $i = 0;
  435. foreach ($arrayofpaymentmode as $key => $val)
  436. {
  437. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
  438. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  439. print '</td>';
  440. $i++;
  441. }*/
  442. print '<td></td>';
  443. print '</tr>';
  444. /*print '<tr>';
  445. // Initial amount
  446. print '<td>'.$langs->trans("NbOfInvoices").'</td>';
  447. print '<td class="center">';
  448. print '</td>';
  449. // Amount per payment type
  450. $i = 0;
  451. foreach ($arrayofpaymentmode as $key => $val)
  452. {
  453. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  454. print $theoricalnbofinvoiceforterminal[$terminalid][$key];
  455. print '</td>';
  456. $i++;
  457. }
  458. // Save
  459. print '<td align="center"></td>';
  460. print '</tr>';
  461. */
  462. print '<tr>';
  463. // Initial amount
  464. print '<td>'.$langs->trans("TheoricalAmount").'</td>';
  465. print '<td class="center">';
  466. print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
  467. print '</td>';
  468. // Amount per payment type
  469. /*$i = 0;
  470. foreach ($arrayofpaymentmode as $key => $val)
  471. {
  472. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  473. print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
  474. print '</td>';
  475. $i++;
  476. }*/
  477. // Save
  478. print '<td></td>';
  479. print '</tr>';
  480. print '<tr>';
  481. print '<td>'.$langs->trans("RealAmount").'</td>';
  482. // Initial amount
  483. print '<td class="center">';
  484. print '<input ';
  485. if ($action == 'close') {
  486. print 'disabled '; // To close cash user can't set opening cash
  487. }
  488. print 'name="opening" type="text" class="maxwidth100 center" value="';
  489. if ($action == 'close') {
  490. $object->fetch($id);
  491. print $object->opening;
  492. } else {
  493. print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
  494. }
  495. print '">';
  496. print '</td>';
  497. // Amount per payment type
  498. /*$i = 0;
  499. foreach ($arrayofpaymentmode as $key => $val)
  500. {
  501. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  502. print '<input ';
  503. if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
  504. print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
  505. print '</td>';
  506. $i++;
  507. }*/
  508. // Save
  509. print '<td class="center">';
  510. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  511. if ($action == 'start') {
  512. print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
  513. } elseif ($action == 'close') {
  514. print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
  515. }
  516. print '</td>';
  517. print '</tr>';
  518. print '</table>';
  519. print '</div>';
  520. }
  521. print '</form>';
  522. }
  523. }
  524. if (empty($action) || $action == "view" || $action == "close") {
  525. $result = $object->fetch($id);
  526. llxHeader('', $langs->trans("CashControl"));
  527. if ($result <= 0) {
  528. print $langs->trans("ErrorRecordNotFound");
  529. } else {
  530. $head = array();
  531. $head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
  532. $head[0][1] = $langs->trans("CashControl");
  533. $head[0][2] = 'cashcontrol';
  534. print dol_get_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account');
  535. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  536. $morehtmlref = '<div class="refidno">';
  537. $morehtmlref .= '</div>';
  538. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  539. print '<div class="fichecenter">';
  540. print '<div class="fichehalfleft">';
  541. print '<div class="underbanner clearboth"></div>';
  542. print '<table class="border tableforfield" width="100%">';
  543. print '<tr><td class="titlefield nowrap">';
  544. print $langs->trans("Ref");
  545. print '</td><td>';
  546. print $id;
  547. print '</td></tr>';
  548. print '<tr><td valign="middle">'.$langs->trans("Module").'</td><td>';
  549. print $object->posmodule;
  550. print "</td></tr>";
  551. print '<tr><td valign="middle">'.$langs->trans("Terminal").'</td><td>';
  552. print $object->posnumber;
  553. print "</td></tr>";
  554. print '<tr><td class="nowrap">';
  555. print $langs->trans("Period");
  556. print '</td><td>';
  557. print $object->year_close;
  558. print ($object->month_close ? "-" : "").$object->month_close;
  559. print ($object->day_close ? "-" : "").$object->day_close;
  560. print '</td></tr>';
  561. print '</table>';
  562. print '</div>';
  563. print '<div class="fichehalfright">>';
  564. print '<div class="underbanner clearboth"></div>';
  565. print '<table class="border tableforfield centpercent">';
  566. print '<tr><td class="titlefield nowrap">';
  567. print $langs->trans("DateCreationShort");
  568. print '</td><td>';
  569. print dol_print_date($object->date_creation, 'dayhour');
  570. print '</td></tr>';
  571. print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
  572. print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency);
  573. print "</td></tr>";
  574. foreach ($arrayofpaymentmode as $key => $val) {
  575. print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
  576. print price($object->$key, 0, $langs, 1, -1, -1, $conf->currency);
  577. print "</td></tr>";
  578. }
  579. print "</table>\n";
  580. print '</div></div>';
  581. print '<div style="clear:both"></div>';
  582. print dol_get_fiche_end();
  583. if ($action != 'close') {
  584. print '<div class="tabsAction">';
  585. print '<div class="inline-block divButAction"><a target="_blank" rel="noopener noreferrer" class="butAction" href="report.php?id='.((int) $id).'">'.$langs->trans('PrintTicket').'</a></div>';
  586. if ($object->status == CashControl::STATUS_DRAFT) {
  587. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=close&token='.newToken().'&contextpage='.$contextpage.'">'.$langs->trans('Close').'</a></div>';
  588. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=confirm_delete&token='.newToken().'">'.$langs->trans('Delete').'</a></div>';
  589. } else {
  590. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=reopen&token='.newToken().'">'.$langs->trans('ReOpen').'</a></div>';
  591. }
  592. print '</div>';
  593. if ($contextpage != 'takepos') {
  594. print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
  595. }
  596. } else {
  597. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
  598. print '<input type="hidden" name="token" value="'.newToken().'">';
  599. if ($contextpage == 'takepos') {
  600. print '<input type="hidden" name="contextpage" value="takepos">';
  601. }
  602. if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
  603. print '<input type="hidden" name="action" value="add">';
  604. } elseif ($action == 'close') {
  605. print '<input type="hidden" name="action" value="valid">';
  606. print '<input type="hidden" name="id" value="'.$id.'">';
  607. } else {
  608. print '<input type="hidden" name="action" value="start">';
  609. }
  610. /*
  611. print '<div class="div-table-responsive-no-min">';
  612. print '<table class="noborder centpercent">';
  613. print '<tr class="liste_titre">';
  614. print '<td>'.$langs->trans("Module").'</td>';
  615. print '<td>'.$langs->trans("Terminal").'</td>';
  616. print '<td>'.$langs->trans("Year").'</td>';
  617. print '<td>'.$langs->trans("Month").'</td>';
  618. print '<td>'.$langs->trans("Day").'</td>';
  619. print '<td></td>';
  620. print "</tr>\n";
  621. $disabled = 1;
  622. $prefix = 'close';
  623. print '<tr class="oddeven">';
  624. print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
  625. print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
  626. print '<td>';
  627. $array = array();
  628. $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
  629. for($i = 1; $i <= $numterminals; $i++) {
  630. $array[$i] = $i;
  631. }
  632. $selectedposnumber = $object->posnumber; $showempty = 1;
  633. //print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
  634. print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
  635. print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
  636. print '</td>';
  637. // Year
  638. print '<td>';
  639. print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
  640. print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
  641. print '</td>';
  642. // Month
  643. print '<td>';
  644. print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
  645. print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
  646. print '</td>';
  647. // Day
  648. print '<td>';
  649. print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
  650. print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
  651. print '</td>';
  652. print '<td></td>';
  653. print '</table>';
  654. print '</div>';
  655. */
  656. // Table to see/enter balance
  657. if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
  658. $posmodule = $object->posmodule;
  659. $terminalid = $object->posnumber;
  660. print '<br>';
  661. print '<div class="div-table-responsive-no-min">';
  662. print '<table class="noborder centpercent">';
  663. print '<tr class="liste_titre">';
  664. print '<td></td>';
  665. print '<td class="center">'.$langs->trans("InitialBankBalance");
  666. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  667. print '</td>';
  668. print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
  669. print $langs->trans("AmountAtEndOfPeriod");
  670. print '</td>';
  671. print '<td></td>';
  672. print '</tr>';
  673. print '<tr class="liste_titre">';
  674. print '<td></td>';
  675. print '<td class="center">'.$langs->trans("Cash");
  676. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  677. print '</td>';
  678. $i = 0;
  679. foreach ($arrayofpaymentmode as $key => $val) {
  680. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
  681. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  682. print '</td>';
  683. $i++;
  684. }
  685. print '<td></td>';
  686. print '</tr>';
  687. print '<tr>';
  688. // Initial amount
  689. print '<td>'.$langs->trans("NbOfInvoices").'</td>';
  690. print '<td class="center">';
  691. print '</td>';
  692. // Amount per payment type
  693. $i = 0;
  694. foreach ($arrayofpaymentmode as $key => $val) {
  695. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  696. print $theoricalnbofinvoiceforterminal[$terminalid][$key];
  697. print '</td>';
  698. $i++;
  699. }
  700. // Save
  701. print '<td align="center"></td>';
  702. print '</tr>';
  703. print '<tr>';
  704. // Initial amount
  705. print '<td>'.$langs->trans("TheoricalAmount").'</td>';
  706. print '<td class="center">';
  707. print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
  708. print '</td>';
  709. // Amount per payment type
  710. $i = 0;
  711. foreach ($arrayofpaymentmode as $key => $val) {
  712. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  713. if ($key == 'cash') {
  714. $deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
  715. print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'<br>';
  716. } else {
  717. print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
  718. }
  719. print '</td>';
  720. $i++;
  721. }
  722. // Save
  723. print '<td align="center"></td>';
  724. print '</tr>';
  725. print '<tr>';
  726. print '<td>'.$langs->trans("RealAmount").'</td>';
  727. // Initial amount
  728. print '<td class="center">';
  729. print '<input ';
  730. if ($action == 'close') {
  731. print 'disabled '; // To close cash user can't set opening cash
  732. }
  733. print 'name="opening" type="text" class="maxwidth100 center" value="';
  734. if ($action == 'close') {
  735. $object->fetch($id);
  736. print $object->opening;
  737. } else {
  738. print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
  739. }
  740. print '">';
  741. print '</td>';
  742. // Amount per payment type
  743. $i = 0;
  744. foreach ($arrayofpaymentmode as $key => $val) {
  745. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  746. print '<input ';
  747. if ($action == 'start') {
  748. print 'disabled '; // To start cash user only can set opening cash
  749. }
  750. print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
  751. print '</td>';
  752. $i++;
  753. }
  754. // Save
  755. print '<td class="center">';
  756. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  757. if ($action == 'start') {
  758. print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
  759. } elseif ($action == 'close') {
  760. print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
  761. }
  762. print '</td>';
  763. print '</tr>';
  764. print '</table>';
  765. print '</div>';
  766. }
  767. print '</form>';
  768. }
  769. }
  770. }
  771. // End of page
  772. llxFooter();
  773. $db->close();