card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  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 <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/paiement/cheque/card.php
  25. * \ingroup bank, invoice
  26. * \brief Page for cheque deposits
  27. */
  28. require '../../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'compta'));
  35. $id =GETPOST('id','int');
  36. $ref=GETPOST('ref', 'alpha');
  37. $action=GETPOST('action', 'alpha');
  38. $confirm=GETPOST('confirm', 'alpha');
  39. // Security check
  40. $fieldname = (! empty($ref)?'ref':'rowid');
  41. if ($user->societe_id) $socid=$user->societe_id;
  42. $result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque','','fk_user_author',$fieldname);
  43. $sortfield=GETPOST('sortfield', 'alpha');
  44. $sortorder=GETPOST('sortorder', 'alpha');
  45. $page=GETPOST('page', 'int');
  46. if (! $sortorder) $sortorder="ASC";
  47. if (! $sortfield) $sortfield="b.dateo,b.rowid";
  48. if (empty($page) || $page == -1) { $page = 0; }
  49. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  50. $offset = $limit * $page ;
  51. $dir=$conf->bank->dir_output.'/checkdeposits/';
  52. $filterdate=dol_mktime(0, 0, 0, GETPOST('fdmonth'), GETPOST('fdday'), GETPOST('fdyear'));
  53. $filteraccountid=GETPOST('accountid');
  54. $object = new RemiseCheque($db);
  55. /*
  56. * Actions
  57. */
  58. if ($action == 'setdate' && $user->rights->banque->cheque)
  59. {
  60. $result = $object->fetch(GETPOST('id','int'));
  61. if ($result > 0)
  62. {
  63. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  64. $date=dol_mktime(0, 0, 0, $_POST['datecreate_month'], $_POST['datecreate_day'], $_POST['datecreate_year']);
  65. $result=$object->set_date($user,$date);
  66. if ($result < 0)
  67. {
  68. setEventMessages($object->error, $object->errors, 'errors');
  69. }
  70. }
  71. else
  72. {
  73. setEventMessages($object->error, $object->errors, 'errors');
  74. }
  75. }
  76. if ($action == 'setrefext' && $user->rights->banque->cheque)
  77. {
  78. $result = $object->fetch(GETPOST('id','int'));
  79. if ($result > 0)
  80. {
  81. $ref_ext = GETPOST('ref_ext');
  82. $result=$object->setValueFrom('ref_ext', $ref_ext, '', null, 'text', '', $user, 'CHECKDEPOSIT_MODIFY');
  83. if ($result < 0)
  84. {
  85. setEventMessages($object->error, $object->errors, 'errors');
  86. }
  87. }
  88. else
  89. {
  90. setEventMessages($object->error, $object->errors, 'errors');
  91. }
  92. }
  93. if ($action == 'setref' && $user->rights->banque->cheque)
  94. {
  95. $result = $object->fetch(GETPOST('id','int'));
  96. if ($result > 0)
  97. {
  98. $ref=GETPOST('ref');
  99. $result=$object->set_number($user,$ref);
  100. if ($result < 0)
  101. {
  102. setEventMessages($object->error, $object->errors, 'errors');
  103. }
  104. }
  105. else
  106. {
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. if ($action == 'create' && $_POST["accountid"] > 0 && $user->rights->banque->cheque)
  111. {
  112. if (is_array($_POST['toRemise']))
  113. {
  114. $result = $object->create($user, $_POST["accountid"], 0, $_POST['toRemise']);
  115. if ($result > 0)
  116. {
  117. if ($object->statut == 1) // If statut is validated, we build doc
  118. {
  119. $object->fetch($object->id); // To force to reload all properties in correct property name
  120. // Define output language
  121. $outputlangs = $langs;
  122. $newlang='';
  123. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  124. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  125. if (! empty($newlang))
  126. {
  127. $outputlangs = new Translate("",$conf);
  128. $outputlangs->setDefaultLang($newlang);
  129. }
  130. $result = $object->generatePdf($_POST["model"], $outputlangs);
  131. }
  132. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  133. exit;
  134. }
  135. else
  136. {
  137. setEventMessages($object->error, $object->errors, 'errors');
  138. }
  139. }
  140. else
  141. {
  142. setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'mesgs');
  143. $action='new';
  144. }
  145. }
  146. if ($action == 'remove' && $id > 0 && $_GET["lineid"] > 0 && $user->rights->banque->cheque)
  147. {
  148. $object->id = $id;
  149. $result = $object->removeCheck($_GET["lineid"]);
  150. if ($result === 0)
  151. {
  152. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  153. exit;
  154. }
  155. else
  156. {
  157. setEventMessages($object->error, $object->errors, 'errors');
  158. }
  159. }
  160. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque)
  161. {
  162. $object->id = $id;
  163. $result = $object->delete();
  164. if ($result == 0)
  165. {
  166. header("Location: index.php");
  167. exit;
  168. }
  169. else
  170. {
  171. setEventMessages($paiement->error, $paiement->errors, 'errors');
  172. }
  173. }
  174. if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->banque->cheque)
  175. {
  176. $result = $object->fetch($id);
  177. $result = $object->validate($user);
  178. if ($result >= 0)
  179. {
  180. // Define output language
  181. $outputlangs = $langs;
  182. $newlang='';
  183. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  184. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  185. if (! empty($newlang))
  186. {
  187. $outputlangs = new Translate("",$conf);
  188. $outputlangs->setDefaultLang($newlang);
  189. }
  190. $result = $object->generatePdf(GETPOST('model'), $outputlangs);
  191. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  192. exit;
  193. }
  194. else
  195. {
  196. setEventMessages($object->error, $object->errors, 'errors');
  197. }
  198. }
  199. if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque)
  200. {
  201. $reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year'));
  202. $rejected_check = GETPOST('bankid');
  203. $object->fetch($id);
  204. $paiement_id = $object->rejectCheck($rejected_check, $reject_date);
  205. if ($paiement_id > 0)
  206. {
  207. setEventMessages($langs->trans("CheckRejectedAndInvoicesReopened"), null, 'mesgs');
  208. //header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id);
  209. //exit;
  210. $action='';
  211. }
  212. else
  213. {
  214. setEventMessages($object->error, $object->errors, 'errors');
  215. $action='';
  216. }
  217. }
  218. if ($action == 'builddoc' && $user->rights->banque->cheque)
  219. {
  220. $result = $object->fetch($id);
  221. // Save last template used to generate document
  222. //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  223. $outputlangs = $langs;
  224. $newlang='';
  225. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  226. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  227. if (! empty($newlang))
  228. {
  229. $outputlangs = new Translate("",$conf);
  230. $outputlangs->setDefaultLang($newlang);
  231. }
  232. $result = $object->generatePdf($_POST["model"], $outputlangs);
  233. if ($result <= 0)
  234. {
  235. dol_print_error($db,$object->error);
  236. exit;
  237. }
  238. else
  239. {
  240. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  241. exit;
  242. }
  243. }
  244. // Remove file in doc form
  245. elseif ($action == 'remove_file' && $user->rights->banque->cheque)
  246. {
  247. if ($object->fetch($id) > 0)
  248. {
  249. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  250. $langs->load("other");
  251. $file=$dir.get_exdir($object->ref,0,1,0,$object,'cheque') . GETPOST('file');
  252. $ret=dol_delete_file($file,0,0,0,$object);
  253. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  254. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  255. }
  256. }
  257. /*
  258. * View
  259. */
  260. if (GETPOST('removefilter'))
  261. {
  262. $filterdate='';
  263. $filteraccountid=0;
  264. }
  265. $title=$langs->trans("Cheques") . " - " . $langs->trans("Card");
  266. $helpurl="";
  267. llxHeader("",$title,$helpurl);
  268. $form = new Form($db);
  269. $formfile = new FormFile($db);
  270. if ($action == 'new')
  271. {
  272. $h=0;
  273. $head[$h][0] = $_SERVER["PHP_SELF"].'?action=new';
  274. $head[$h][1] = $langs->trans("MenuChequeDeposits");
  275. $hselected = $h;
  276. $h++;
  277. print load_fiche_titre($langs->trans("Cheques"));
  278. }
  279. else
  280. {
  281. $result = $object->fetch($id, $ref);
  282. if ($result < 0)
  283. {
  284. dol_print_error($db,$object->error);
  285. exit;
  286. }
  287. $h=0;
  288. $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id;
  289. $head[$h][1] = $langs->trans("CheckReceipt");
  290. $hselected = $h;
  291. $h++;
  292. // $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/cheque/info.php?id='.$object->id;
  293. // $head[$h][1] = $langs->trans("Info");
  294. // $h++;
  295. dol_fiche_head($head, $hselected, $langs->trans("Cheques"), -1, 'payment');
  296. /*
  297. * Confirmation de la suppression du bordereau
  298. */
  299. if ($action == 'delete')
  300. {
  301. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete','','',1);
  302. }
  303. /*
  304. * Confirmation de la validation du bordereau
  305. */
  306. if ($action == 'valide')
  307. {
  308. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_valide','','',1);
  309. }
  310. /*
  311. * Confirm check rejection
  312. */
  313. if ($action == 'reject_check')
  314. {
  315. $formquestion = array(
  316. array('type' => 'hidden','name' => 'bankid','value' => GETPOST('lineid')),
  317. array('type' => 'date','name' => 'rejectdate_','label' => $langs->trans("RejectCheckDate"),'value' => dol_now())
  318. );
  319. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("RejectCheck"), $langs->trans("ConfirmRejectCheck"), 'confirm_reject_check',$formquestion,'',1);
  320. }
  321. }
  322. $accounts = array();
  323. if ($action == 'new')
  324. {
  325. $paymentstatic=new Paiement($db);
  326. $accountlinestatic=new AccountLine($db);
  327. $lines = array();
  328. $now=dol_now();
  329. print $langs->trans("SelectChequeTransactionAndGenerate").'<br><br>'."\n";
  330. print '<form class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  331. print '<input type="hidden" name="action" value="new">';
  332. dol_fiche_head();
  333. print '<table class="border" width="100%">';
  334. //print '<tr><td width="30%">'.$langs->trans('Date').'</td><td width="70%">'.dol_print_date($now,'day').'</td></tr>';
  335. // Filter
  336. print '<tr><td class="titlefieldcreate">'.$langs->trans("DateChequeReceived").'</td><td>';
  337. print $form->selectDate($filterdate, 'fd', 0, 0, 1, '', 1, 1);
  338. print '</td></tr>';
  339. print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
  340. $form->select_comptes($filteraccountid,'accountid',0,'courant <> 2',1);
  341. print '</td></tr>';
  342. print '</table>';
  343. dol_fiche_end();
  344. print '<div class="center">';
  345. print '<input type="submit" class="button" name="filter" value="'.dol_escape_htmltag($langs->trans("ToFilter")).'">';
  346. if ($filterdate || $filteraccountid > 0)
  347. {
  348. print ' &nbsp; ';
  349. print '<input type="submit" class="button" name="removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  350. }
  351. print '</div>';
  352. print '</form>';
  353. print '<br>';
  354. $sql = "SELECT ba.rowid as bid, b.datec as datec, b.dateo as date, b.rowid as transactionid, ";
  355. $sql.= " b.amount, ba.label, b.emetteur, b.num_chq, b.banque,";
  356. $sql.= " p.rowid as paymentid";
  357. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  358. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
  359. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)";
  360. $sql.= " WHERE b.fk_type = 'CHQ'";
  361. $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
  362. $sql.= " AND b.fk_bordereau = 0";
  363. $sql.= " AND b.amount > 0";
  364. if ($filterdate) $sql.=" AND b.dateo = '".$db->idate($filterdate)."'";
  365. if ($filteraccountid > 0) $sql.=" AND ba.rowid= '".$filteraccountid."'";
  366. $sql.= $db->order("b.dateo,b.rowid","ASC");
  367. $resql = $db->query($sql);
  368. if ($resql)
  369. {
  370. $i = 0;
  371. while ( $obj = $db->fetch_object($resql) )
  372. {
  373. $accounts[$obj->bid] = $obj->label;
  374. $lines[$obj->bid][$i]["date"] = $db->jdate($obj->date);
  375. $lines[$obj->bid][$i]["amount"] = $obj->amount;
  376. $lines[$obj->bid][$i]["emetteur"] = $obj->emetteur;
  377. $lines[$obj->bid][$i]["numero"] = $obj->num_chq;
  378. $lines[$obj->bid][$i]["banque"] = $obj->banque;
  379. $lines[$obj->bid][$i]["id"] = $obj->transactionid;
  380. $lines[$obj->bid][$i]["paymentid"] = $obj->paymentid;
  381. $i++;
  382. }
  383. if ($i == 0)
  384. {
  385. print '<div class="opacitymedium">'.$langs->trans("NoWaitingChecks").'</div><br>';
  386. }
  387. }
  388. foreach ($accounts as $bid => $account_label)
  389. {
  390. print '
  391. <script language="javascript" type="text/javascript">
  392. jQuery(document).ready(function()
  393. {
  394. jQuery("#checkall_'.$bid.'").click(function()
  395. {
  396. jQuery(".checkforremise_'.$bid.'").prop(\'checked\', true);
  397. });
  398. jQuery("#checknone_'.$bid.'").click(function()
  399. {
  400. jQuery(".checkforremise_'.$bid.'").prop(\'checked\', false);
  401. });
  402. });
  403. </script>
  404. ';
  405. $num = $db->num_rows($resql);
  406. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  407. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  408. print '<input type="hidden" name="action" value="create">';
  409. print '<input type="hidden" name="accountid" value="'.$bid.'">';
  410. $moreforfilter='';
  411. print '<div class="div-table-responsive-no-min">';
  412. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  413. print '<tr class="liste_titre">';
  414. print '<td style="min-width: 120px">'.$langs->trans("DateChequeReceived").'</td>'."\n";
  415. print '<td style="min-width: 120px">'.$langs->trans("ChequeNumber")."</td>\n";
  416. print '<td style="min-width: 200px">'.$langs->trans("CheckTransmitter")."</td>\n";
  417. print '<td style="min-width: 200px">'.$langs->trans("Bank")."</td>\n";
  418. print '<td align="right" width="100px">'.$langs->trans("Amount")."</td>\n";
  419. print '<td align="center" width="100px">'.$langs->trans("Payment")."</td>\n";
  420. print '<td align="center" width="100px">'.$langs->trans("LineRecord")."</td>\n";
  421. print '<td align="center" width="100px">'.$langs->trans("Select")."<br>";
  422. if ($conf->use_javascript_ajax) print '<a href="#" id="checkall_'.$bid.'">'.$langs->trans("All").'</a> / <a href="#" id="checknone_'.$bid.'">'.$langs->trans("None").'</a>';
  423. print '</td>';
  424. print "</tr>\n";
  425. if (count($lines[$bid]))
  426. {
  427. foreach ($lines[$bid] as $lid => $value)
  428. {
  429. //$account_id = $bid; FIXME not used
  430. // FIXME $accounts[$bid] is a label !
  431. /*if (! isset($accounts[$bid]))
  432. $accounts[$bid]=0;
  433. $accounts[$bid] += 1;*/
  434. print '<tr class="oddeven">';
  435. print '<td>'.dol_print_date($value["date"],'day').'</td>';
  436. print '<td>'.$value["numero"]."</td>\n";
  437. print '<td>'.$value["emetteur"]."</td>\n";
  438. print '<td>'.$value["banque"]."</td>\n";
  439. print '<td align="right">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</td>';
  440. // Link to payment
  441. print '<td align="center">';
  442. $paymentstatic->id=$value["paymentid"];
  443. $paymentstatic->ref=$value["paymentid"];
  444. if ($paymentstatic->id)
  445. {
  446. print $paymentstatic->getNomUrl(1);
  447. }
  448. else
  449. {
  450. print '&nbsp;';
  451. }
  452. print '</td>';
  453. // Link to bank transaction
  454. print '<td align="center">';
  455. $accountlinestatic->rowid=$value["id"];
  456. if ($accountlinestatic->rowid)
  457. {
  458. print $accountlinestatic->getNomUrl(1);
  459. }
  460. else
  461. {
  462. print '&nbsp;';
  463. }
  464. print '</td>';
  465. print '<td align="center">';
  466. print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">';
  467. print '</td>' ;
  468. print '</tr>';
  469. $i++;
  470. }
  471. }
  472. print "</table>";
  473. print '</div>';
  474. print '<div class="tabsAction">';
  475. if ($user->rights->banque->cheque)
  476. {
  477. print '<input type="submit" class="button" value="'.$langs->trans('NewCheckDepositOn',$account_label).'">';
  478. }
  479. else
  480. {
  481. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('NewCheckDepositOn',$account_label).'</a>';
  482. }
  483. print '</div><br>';
  484. print '</form>';
  485. }
  486. }
  487. else
  488. {
  489. $paymentstatic=new Paiement($db);
  490. $accountlinestatic=new AccountLine($db);
  491. $accountstatic=new Account($db);
  492. $accountstatic->fetch($object->account_id);
  493. $linkback='<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  494. $morehtmlref='';
  495. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  496. print '<div class="fichecenter">';
  497. print '<div class="underbanner clearboth"></div>';
  498. print '<table class="border" width="100%">';
  499. print '<tr><td class="titlefield">';
  500. print '<table class="nobordernopadding" width="100%"><tr><td>';
  501. print $langs->trans('Date');
  502. print '</td>';
  503. if ($action != 'editdate') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
  504. print '</tr></table>';
  505. print '</td><td colspan="2">';
  506. if ($action == 'editdate')
  507. {
  508. print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  509. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  510. print '<input type="hidden" name="action" value="setdate">';
  511. print $form->selectDate($object->date_bordereau, 'datecreate_', '', '', '', "setdate");
  512. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  513. print '</form>';
  514. }
  515. else
  516. {
  517. print $object->date_bordereau ? dol_print_date($object->date_bordereau,'day') : '&nbsp;';
  518. }
  519. print '</td>';
  520. print '</tr>';
  521. // External ref
  522. /* Ext ref are not visible field on standard usage
  523. print '<tr><td>';
  524. print '<table class="nobordernopadding" width="100%"><tr><td>';
  525. print $langs->trans('RefExt');
  526. print '</td>';
  527. if ($action != 'editrefext') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editrefext&amp;id='.$object->id.'">'.img_edit($langs->trans('SetRefExt'),1).'</a></td>';
  528. print '</tr></table>';
  529. print '</td><td colspan="2">';
  530. if ($action == 'editrefext')
  531. {
  532. print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  533. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  534. print '<input type="hidden" name="action" value="setrefext">';
  535. print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
  536. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  537. print '</form>';
  538. }
  539. else
  540. {
  541. print $object->ref_ext;
  542. }
  543. print '</td>';
  544. print '</tr>';
  545. */
  546. print '<tr><td>'.$langs->trans('Account').'</td><td colspan="2">';
  547. print $accountstatic->getNomUrl(1);
  548. print '</td></tr>';
  549. // Nb of cheques
  550. print '<tr><td>'.$langs->trans('NbOfCheques').'</td><td colspan="2">';
  551. print $object->nbcheque;
  552. print '</td></tr>';
  553. print '<tr><td>'.$langs->trans('Total').'</td><td colspan="2">';
  554. print price($object->amount);
  555. print '</td></tr>';
  556. /*print '<tr><td>'.$langs->trans('Status').'</td><td colspan="2">';
  557. print $object->getLibStatut(4);
  558. print '</td></tr>';*/
  559. print '</table><br>';
  560. print '</div>';
  561. // List of cheques
  562. $sql = "SELECT b.rowid, b.amount, b.num_chq, b.emetteur,";
  563. $sql.= " b.dateo as date, b.datec as datec, b.banque,";
  564. $sql.= " p.rowid as pid, ba.rowid as bid, p.statut";
  565. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  566. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)";
  567. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
  568. $sql.= " WHERE ba.entity IN (".getEntity('bank_account').")";
  569. $sql.= " AND b.fk_type= 'CHQ'";
  570. $sql.= " AND b.fk_bordereau = ".$object->id;
  571. $sql.= $db->order($sortfield, $sortorder);
  572. $resql = $db->query($sql);
  573. if ($resql)
  574. {
  575. $num = $db->num_rows($resql);
  576. print '<div class="div-table-responsive">';
  577. print '<table class="noborder" width="100%">';
  578. $param="&amp;id=".$object->id;
  579. print '<tr class="liste_titre">';
  580. print_liste_field_titre("Cheques",'','','','','width="30"');
  581. print_liste_field_titre("DateChequeReceived",$_SERVER["PHP_SELF"],"b.dateo,b.rowid", "",$param,'align="center"',$sortfield,$sortorder);
  582. print_liste_field_titre("Numero",$_SERVER["PHP_SELF"],"b.num_chq", "",$param,'align="center"',$sortfield,$sortorder);
  583. print_liste_field_titre("CheckTransmitter",$_SERVER["PHP_SELF"],"b.emetteur", "",$param,"",$sortfield,$sortorder);
  584. print_liste_field_titre("Bank",$_SERVER["PHP_SELF"],"b.banque", "",$param,"",$sortfield,$sortorder);
  585. print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"b.amount", "",$param,'align="right"',$sortfield,$sortorder);
  586. print_liste_field_titre("Payment",$_SERVER["PHP_SELF"],"p.rowid", "",$param,'align="center"',$sortfield,$sortorder);
  587. print_liste_field_titre("LineRecord",$_SERVER["PHP_SELF"],"b.rowid", "",$param,'align="center"',$sortfield,$sortorder);
  588. print_liste_field_titre('');
  589. print "</tr>\n";
  590. $i=1;
  591. if ($num > 0)
  592. {
  593. while ($objp = $db->fetch_object($resql))
  594. {
  595. //$account_id = $objp->bid; FIXME not used
  596. // FIXME $accounts[$objp->bid] is a label
  597. /*if (! isset($accounts[$objp->bid]))
  598. $accounts[$objp->bid]=0;
  599. $accounts[$objp->bid] += 1;*/
  600. print '<tr class="oddeven">';
  601. print '<td align="center">'.$i.'</td>';
  602. print '<td align="center">'.dol_print_date($db->jdate($objp->date),'day').'</td>'; // Date operation
  603. print '<td align="center">'.($objp->num_chq?$objp->num_chq:'&nbsp;').'</td>';
  604. print '<td>'.dol_trunc($objp->emetteur,24).'</td>';
  605. print '<td>'.dol_trunc($objp->banque,24).'</td>';
  606. print '<td align="right">'.price($objp->amount).'</td>';
  607. // Link to payment
  608. print '<td align="center">';
  609. $paymentstatic->id=$objp->pid;
  610. $paymentstatic->ref=$objp->pid;
  611. if ($paymentstatic->id)
  612. {
  613. print $paymentstatic->getNomUrl(1);
  614. }
  615. else
  616. {
  617. print '&nbsp;';
  618. }
  619. print '</td>';
  620. // Link to bank transaction
  621. print '<td align="center">';
  622. $accountlinestatic->rowid=$objp->rowid;
  623. if ($accountlinestatic->rowid)
  624. {
  625. print $accountlinestatic->getNomUrl(1);
  626. }
  627. else
  628. {
  629. print '&nbsp;';
  630. }
  631. print '</td>';
  632. // Action button
  633. print '<td align="right">';
  634. if ($object->statut == 0)
  635. {
  636. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;lineid='.$objp->rowid.'">'.img_delete().'</a>';
  637. }
  638. if ($object->statut == 1 && $objp->statut != 2)
  639. {
  640. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"),'disable').'</a>';
  641. }
  642. if ($objp->statut == 2)
  643. {
  644. print ' &nbsp; '.img_picto($langs->trans('CheckRejected'),'statut8').'</a>';
  645. }
  646. print '</td>';
  647. print '</tr>';
  648. $i++;
  649. }
  650. }
  651. else
  652. {
  653. print '<td colspan="8" class="opacitymedium">';
  654. print $langs->trans("None");
  655. print '</td>';
  656. }
  657. print "</table>";
  658. print "</div>";
  659. }
  660. else
  661. {
  662. dol_print_error($db);
  663. }
  664. dol_fiche_end();
  665. }
  666. /*
  667. * Boutons Actions
  668. */
  669. print '<div class="tabsAction">';
  670. /*if ($user->societe_id == 0 && count($accounts) == 1 && $action == 'new' && $user->rights->banque->cheque)
  671. {
  672. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=create&amp;accountid='.$account_id.'">'.$langs->trans('NewCheckReceipt').'</a>';
  673. }*/
  674. if ($user->societe_id == 0 && ! empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque)
  675. {
  676. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valide&amp;sortfield='.$sortfield.'&amp;sortorder='.$sortorder.'">'.$langs->trans('Validate').'</a>';
  677. }
  678. if ($user->societe_id == 0 && ! empty($object->id) && $user->rights->banque->cheque)
  679. {
  680. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;sortfield='.$sortfield.'&amp;sortorder='.$sortorder.'">'.$langs->trans('Delete').'</a>';
  681. }
  682. print '</div>';
  683. if ($action != 'new')
  684. {
  685. if ($object->statut == 1)
  686. {
  687. $filename=dol_sanitizeFileName($object->ref);
  688. $filedir=$dir.get_exdir($object->ref,0,1,0,$object,'cheque') . dol_sanitizeFileName($object->ref);
  689. $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
  690. print $formfile->showdocuments('remisecheque', $filename, $filedir, $urlsource, 1, 1);
  691. print '<br>';
  692. }
  693. }
  694. // End of page
  695. llxFooter();
  696. $db->close();