cashcontrol_card.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
  33. $langs->loadLangs(array("install", "cashdesk", "admin", "banks"));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $categid = GETPOST('categid');
  38. $label = GETPOST("label");
  39. $now = dol_now();
  40. $syear = (GETPOSTISSET('closeyear') ? GETPOST('closeyear', 'int') : dol_print_date($now, "%Y"));
  41. $smonth = (GETPOSTISSET('closemonth') ? GETPOST('closemonth', 'int') : dol_print_date($now, "%m"));
  42. $sday = (GETPOSTISSET('closeday') ? GETPOST('closeday', 'int') : dol_print_date($now, "%d"));
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortfield) {
  54. $sortfield = 'rowid';
  55. }
  56. if (!$sortorder) {
  57. $sortorder = 'ASC';
  58. }
  59. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
  60. if ($contextpage == 'takepos') {
  61. $_GET['optioncss'] = 'print';
  62. }
  63. $arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
  64. $arrayofposavailable = array();
  65. if (isModEnabled('cashdesk')) {
  66. $arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
  67. }
  68. if (isModEnabled('takepos')) {
  69. $arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
  70. }
  71. // TODO Add hook here to allow other POS to add themself
  72. $object = new CashControl($db);
  73. $extrafields = new ExtraFields($db);
  74. // fetch optionals attributes and labels
  75. $extrafields->fetch_name_optionals_label($object->table_element);
  76. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  77. $hookmanager->initHooks(array('cashcontrolcard', 'globalcard'));
  78. // Load object
  79. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  80. // Security check
  81. if ($user->socid > 0) { // Protection if external user
  82. //$socid = $user->socid;
  83. accessforbidden();
  84. }
  85. if (!$user->hasRight("cashdesk", "run") && !$user->hasRight("takepos", "run")) {
  86. accessforbidden();
  87. }
  88. /*
  89. * Actions
  90. */
  91. $permissiontoadd = ($user->hasRight("cashdesk", "run") || $user->hasRight("takepos", "run"));
  92. $permissiontodelete = ($user->hasRight("cashdesk", "run") || $user->hasRight("takepos", "run")) || ($permissiontoadd && $object->status == 0);
  93. if (empty($backtopage)) {
  94. $backtopage = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.(!empty($id) && $id > 0 ? $id : '__ID__');
  95. }
  96. $backurlforlist = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php';
  97. $triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
  98. if (!getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CASH') && !getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CASH1')) {
  99. setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
  100. }
  101. if (GETPOST('cancel', 'alpha')) {
  102. if ($action == 'valid') {
  103. $action = 'view';
  104. } else {
  105. $action = 'create';
  106. }
  107. }
  108. if ($action == "reopen") {
  109. $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
  110. if ($result < 0) {
  111. setEventMessages($object->error, $object->errors, 'errors');
  112. }
  113. $action = 'view';
  114. }
  115. if ($action == "start") {
  116. $error = 0;
  117. if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1') {
  118. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
  119. $action = 'create';
  120. $error++;
  121. }
  122. if (GETPOST('posnumber', 'alpha') == '') {
  123. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
  124. $action = 'create';
  125. $error++;
  126. }
  127. if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1') {
  128. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
  129. $action = 'create';
  130. $error++;
  131. }
  132. } elseif ($action == "add") {
  133. if (GETPOST('opening', 'alpha') == '') {
  134. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
  135. $action = 'start';
  136. $error++;
  137. }
  138. $error = 0;
  139. foreach ($arrayofpaymentmode as $key => $val) {
  140. $object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
  141. }
  142. if (!$error) {
  143. $object->day_close = GETPOST('closeday', 'int');
  144. $object->month_close = GETPOST('closemonth', 'int');
  145. $object->year_close = GETPOST('closeyear', 'int');
  146. $object->opening = price2num(GETPOST('opening', 'alpha'));
  147. $object->posmodule = GETPOST('posmodule', 'alpha');
  148. $object->posnumber = GETPOST('posnumber', 'alpha');
  149. $db->begin();
  150. $id = $object->create($user);
  151. if ($id > 0) {
  152. $db->commit();
  153. $action = "view";
  154. } else {
  155. $db->rollback;
  156. $action = "view";
  157. }
  158. }
  159. if ($contextpage == 'takepos') {
  160. print "
  161. <script>
  162. parent.location.href='../../takepos/index.php?place='+parent.place;
  163. </script>";
  164. exit;
  165. }
  166. }
  167. if ($action == "valid") { // validate = close
  168. $object->fetch($id);
  169. $db->begin();
  170. /*
  171. $object->day_close = GETPOST('closeday', 'int');
  172. $object->month_close = GETPOST('closemonth', 'int');
  173. $object->year_close = GETPOST('closeyear', 'int');
  174. */
  175. $object->cash = price2num(GETPOST('cash_amount', 'alpha'));
  176. $object->card = price2num(GETPOST('card_amount', 'alpha'));
  177. $object->cheque = price2num(GETPOST('cheque_amount', 'alpha'));
  178. $result = $object->update($user);
  179. $result = $object->valid($user);
  180. if ($result <= 0) {
  181. setEventMessages($object->error, $object->errors, 'errors');
  182. $db->rollback();
  183. } else {
  184. setEventMessages($langs->trans("CashFenceDone"), null);
  185. $db->commit();
  186. }
  187. if ($contextpage == 'takepos') {
  188. print "
  189. <script>
  190. parent.location.href='../../takepos/index.php?place='+parent.place;
  191. </script>";
  192. exit;
  193. }
  194. $action = "view";
  195. }
  196. // Action to delete
  197. if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
  198. $object->fetch($id);
  199. if (!($object->id > 0)) {
  200. dol_print_error('', 'Error, object must be fetched before being deleted');
  201. exit;
  202. }
  203. $result = $object->delete($user);
  204. //var_dump($result);
  205. if ($result > 0) {
  206. // Delete OK
  207. setEventMessages("RecordDeleted", null, 'mesgs');
  208. header("Location: ".$backurlforlist);
  209. exit;
  210. } else {
  211. if (!empty($object->errors)) {
  212. setEventMessages(null, $object->errors, 'errors');
  213. } else {
  214. setEventMessages($object->error, null, 'errors');
  215. }
  216. }
  217. }
  218. /*
  219. * View
  220. */
  221. $form = new Form($db);
  222. $initialbalanceforterminal = array();
  223. $theoricalamountforterminal = array();
  224. $theoricalnbofinvoiceforterminal = array();
  225. llxHeader('', $langs->trans("CashControl"));
  226. if ($action == "create" || $action == "start" || $action == 'close') {
  227. if ($action == 'close') {
  228. $posmodule = $object->posmodule;
  229. $terminalid = $object->posnumber;
  230. $terminaltouse = $terminalid;
  231. $syear = $object->year_close;
  232. $smonth = $object->month_close;
  233. $sday = $object->day_close;
  234. } elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') {
  235. $posmodule = GETPOST('posmodule', 'alpha');
  236. $terminalid = GETPOST('posnumber', 'alpha');
  237. $terminaltouse = $terminalid;
  238. if ($terminaltouse == '1' && $posmodule == 'cashdesk') {
  239. $terminaltouse = '';
  240. }
  241. if ($posmodule == 'cashdesk' && $terminaltouse != '' && $terminaltouse != '1') {
  242. $terminaltouse = '';
  243. setEventMessages($langs->trans("OnlyTerminal1IsAvailableForCashDeskModule"), null, 'errors');
  244. $error++;
  245. }
  246. }
  247. if (isset($terminalid) && $terminalid != '') {
  248. // Calculate $initialbalanceforterminal for terminal 0
  249. foreach ($arrayofpaymentmode as $key => $val) {
  250. if ($key != 'cash') {
  251. $initialbalanceforterminal[$terminalid][$key] = 0;
  252. continue;
  253. }
  254. // Get the bank account dedicated to this point of sale module/terminal
  255. $vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
  256. $bankid = getDolGlobalInt($vartouse);
  257. if ($bankid > 0) {
  258. $sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
  259. $sql .= " WHERE fk_account = ".((int) $bankid);
  260. if ($syear && !$smonth) {
  261. $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
  262. } elseif ($syear && $smonth && !$sday) {
  263. $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
  264. } elseif ($syear && $smonth && $sday) {
  265. $sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
  266. } else {
  267. setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
  268. }
  269. $resql = $db->query($sql);
  270. if ($resql) {
  271. $obj = $db->fetch_object($resql);
  272. if ($obj) {
  273. $initialbalanceforterminal[$terminalid][$key] = $obj->total;
  274. }
  275. } else {
  276. dol_print_error($db);
  277. }
  278. } else {
  279. setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
  280. $error++;
  281. }
  282. }
  283. // Calculate $theoricalamountforterminal
  284. foreach ($arrayofpaymentmode as $key => $val) {
  285. $sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
  286. $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";
  287. $sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
  288. $sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
  289. $sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
  290. $sql .= " AND f.paye = 1";
  291. $sql .= " AND p.entity IN (".getEntity('facture').")";
  292. if ($key == 'cash') {
  293. $sql .= " AND cp.code = 'LIQ'";
  294. } elseif ($key == 'cheque') {
  295. $sql .= " AND cp.code = 'CHQ'";
  296. } elseif ($key == 'card') {
  297. $sql .= " AND cp.code = 'CB'";
  298. } else {
  299. dol_print_error('Value for key = '.$key.' not supported');
  300. exit;
  301. }
  302. if ($syear && !$smonth) {
  303. $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
  304. } elseif ($syear && $smonth && !$sday) {
  305. $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
  306. } elseif ($syear && $smonth && $sday) {
  307. $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))."'";
  308. } else {
  309. setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
  310. }
  311. $resql = $db->query($sql);
  312. if ($resql) {
  313. $theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
  314. $obj = $db->fetch_object($resql);
  315. if ($obj) {
  316. $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
  317. $theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
  318. }
  319. } else {
  320. dol_print_error($db);
  321. }
  322. }
  323. }
  324. //var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal);
  325. if ($action != 'close') {
  326. print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register');
  327. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  328. print '<input type="hidden" name="token" value="'.newToken().'">';
  329. if ($contextpage == 'takepos') {
  330. print '<input type="hidden" name="contextpage" value="takepos">';
  331. }
  332. if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
  333. print '<input type="hidden" name="action" value="add">';
  334. } elseif ($action == 'close') {
  335. print '<input type="hidden" name="action" value="valid">';
  336. print '<input type="hidden" name="id" value="'.$id.'">';
  337. } else {
  338. print '<input type="hidden" name="action" value="start">';
  339. }
  340. print '<div class="div-table-responsive-no-min">';
  341. print '<table class="noborder centpercent">';
  342. print '<tr class="liste_titre">';
  343. print '<td>'.$langs->trans("Module").'</td>';
  344. print '<td>'.$langs->trans("Terminal").'</td>';
  345. print '<td>'.$langs->trans("Year").'</td>';
  346. print '<td>'.$langs->trans("Month").'</td>';
  347. print '<td>'.$langs->trans("Day").'</td>';
  348. print '<td></td>';
  349. print "</tr>\n";
  350. $disabled = 0;
  351. $prefix = 'close';
  352. print '<tr class="oddeven">';
  353. print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).'</td>';
  354. print '<td>';
  355. $array = array();
  356. $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
  357. for ($i = 1; $i <= $numterminals; $i++) {
  358. $array[$i] = $i;
  359. }
  360. $selectedposnumber = 0;
  361. $showempty = 1;
  362. if (getDolGlobalString('TAKEPOS_NUM_TERMINALS') == '1') {
  363. $selectedposnumber = 1;
  364. $showempty = 0;
  365. }
  366. print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ? GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
  367. //print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
  368. print '</td>';
  369. // Year
  370. print '<td>';
  371. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
  372. for ($year = $syear - 10; $year < $syear + 10; $year++) {
  373. $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
  374. }
  375. $retstring .= "</select>\n";
  376. print $retstring;
  377. print '</td>';
  378. // Month
  379. print '<td>';
  380. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
  381. $retstring .= '<option value="0"></option>';
  382. for ($month = 1; $month <= 12; $month++) {
  383. $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
  384. $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
  385. $retstring .= "</option>";
  386. }
  387. $retstring .= "</select>";
  388. print $retstring;
  389. print '</td>';
  390. // Day
  391. print '<td>';
  392. $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
  393. $retstring .= '<option value="0" selected>&nbsp;</option>';
  394. for ($day = 1; $day <= 31; $day++) {
  395. $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
  396. }
  397. $retstring .= "</select>";
  398. print $retstring;
  399. print '</td>';
  400. // Button Start
  401. print '<td>';
  402. if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
  403. print '';
  404. } else {
  405. print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
  406. }
  407. print '</td>';
  408. print '</table>';
  409. print '</div>';
  410. // Table to see/enter balance
  411. if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
  412. $posmodule = GETPOST('posmodule', 'alpha');
  413. $terminalid = GETPOST('posnumber', 'alpha');
  414. print '<br>';
  415. print '<div class="div-table-responsive-no-min">';
  416. print '<table class="noborder centpercent">';
  417. print '<tr class="liste_titre">';
  418. print '<td></td>';
  419. print '<td class="center">'.$langs->trans("InitialBankBalance");
  420. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  421. print '</td>';
  422. /*
  423. print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
  424. print $langs->trans("AmountAtEndOfPeriod");
  425. print '</td>';
  426. */
  427. print '<td></td>';
  428. print '</tr>';
  429. print '<tr class="liste_titre">';
  430. print '<td></td>';
  431. print '<td class="center">'.$langs->trans("Cash");
  432. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  433. print '</td>';
  434. /*
  435. $i = 0;
  436. foreach ($arrayofpaymentmode as $key => $val)
  437. {
  438. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
  439. //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
  440. print '</td>';
  441. $i++;
  442. }*/
  443. print '<td></td>';
  444. print '</tr>';
  445. /*print '<tr>';
  446. // Initial amount
  447. print '<td>'.$langs->trans("NbOfInvoices").'</td>';
  448. print '<td class="center">';
  449. print '</td>';
  450. // Amount per payment type
  451. $i = 0;
  452. foreach ($arrayofpaymentmode as $key => $val)
  453. {
  454. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  455. print $theoricalnbofinvoiceforterminal[$terminalid][$key];
  456. print '</td>';
  457. $i++;
  458. }
  459. // Save
  460. print '<td align="center"></td>';
  461. print '</tr>';
  462. */
  463. print '<tr>';
  464. // Initial amount
  465. print '<td>'.$langs->trans("TheoricalAmount").'</td>';
  466. print '<td class="center">';
  467. print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
  468. print '</td>';
  469. // Amount per payment type
  470. /*$i = 0;
  471. foreach ($arrayofpaymentmode as $key => $val)
  472. {
  473. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  474. print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
  475. print '</td>';
  476. $i++;
  477. }*/
  478. // Save
  479. print '<td></td>';
  480. print '</tr>';
  481. print '<tr>';
  482. print '<td>'.$langs->trans("RealAmount").'</td>';
  483. // Initial amount
  484. print '<td class="center">';
  485. print '<input ';
  486. if ($action == 'close') {
  487. print 'disabled '; // To close cash user can't set opening cash
  488. }
  489. print 'name="opening" type="text" class="maxwidth100 center" value="';
  490. if ($action == 'close') {
  491. $object->fetch($id);
  492. print $object->opening;
  493. } else {
  494. print(GETPOSTISSET('opening') ? price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
  495. }
  496. print '">';
  497. print '</td>';
  498. // Amount per payment type
  499. /*$i = 0;
  500. foreach ($arrayofpaymentmode as $key => $val)
  501. {
  502. print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
  503. print '<input ';
  504. if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
  505. print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
  506. print '</td>';
  507. $i++;
  508. }*/
  509. // Save
  510. print '<td class="center">';
  511. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  512. if ($action == 'start') {
  513. print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
  514. } elseif ($action == 'close') {
  515. print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
  516. }
  517. print '</td>';
  518. print '</tr>';
  519. print '</table>';
  520. print '</div>';
  521. }
  522. print '</form>';
  523. }
  524. }
  525. if (empty($action) || $action == "view" || $action == "close") {
  526. $result = $object->fetch($id);
  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 '<span class="amount">'.price($object->opening, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
  573. print "</td></tr>";
  574. foreach ($arrayofpaymentmode as $key => $val) {
  575. print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
  576. print '<span class="amount">'.price($object->$key, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
  577. print "</td></tr>";
  578. }
  579. print "</table>\n";
  580. print '</div></div>';
  581. print '<div class="clearboth"></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();