PageRenderTime 188ms CodeModel.GetById 100ms app.highlight 39ms RepoModel.GetById 42ms app.codeStats 0ms

/htdocs/compta/bank/ligne.php

https://github.com/asterix14/dolibarr
PHP | 603 lines | 477 code | 74 blank | 52 comment | 94 complexity | d25e968bc86ceef3e8c92f4a355d297f MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2003      Xavier DUTOIT        <doli@sydesy.com>
  4 * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  5 * Copyright (C) 2004      Christophe Combelles <ccomb@free.fr>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 2 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21/**
 22 *	\file       htdocs/compta/bank/ligne.php
 23 *	\ingroup    compta
 24 *	\brief      Page to edit a bank transaction record
 25 */
 26
 27require("./pre.inc.php");
 28
 29if (! $user->rights->banque->lire && ! $user->rights->banque->consolidate)
 30accessforbidden();
 31
 32$langs->load("banks");
 33$langs->load("compta");
 34$langs->load("bills");
 35$langs->load("categories");
 36if ($conf->adherent->enabled) $langs->load("members");
 37
 38$action=GETPOST('action');
 39$rowid=GETPOST("rowid");
 40$ref=GETPOST("ref");
 41$orig_account=GETPOST("orig_account");
 42$accountid=GETPOST('accountid');
 43$confirm=GETPOST('confirm');
 44
 45$form = new Form($db);
 46
 47/*
 48 * Actions
 49 */
 50
 51if ($user->rights->banque->consolidate && $_GET["action"] == 'dvnext')
 52{
 53    $ac = new Account($db);
 54    $ac->datev_next($_GET["rowid"]);
 55}
 56
 57if ($user->rights->banque->consolidate && $_GET["action"] == 'dvprev')
 58{
 59    $ac = new Account($db);
 60    $ac->datev_previous($_GET["rowid"]);
 61}
 62
 63if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->banque->modifier)
 64{
 65    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".GETPOST("cat1");
 66    if (! $db->query($sql))
 67    {
 68        dol_print_error($db);
 69    }
 70}
 71
 72if ($action == 'class')
 73{
 74    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".$_POST["cat1"];
 75    if (! $db->query($sql))
 76    {
 77        dol_print_error($db);
 78    }
 79
 80    $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$_GET["rowid"].", ".$_POST["cat1"].")";
 81    if (! $db->query($sql))
 82    {
 83        dol_print_error($db);
 84    }
 85}
 86
 87if ($action == "update")
 88{
 89    // Avant de modifier la date ou le montant, on controle si ce n'est pas encore rapproche
 90    $conciliated=0;
 91    $sql = "SELECT b.rappro FROM ".MAIN_DB_PREFIX."bank as b WHERE rowid=".$rowid;
 92    $result = $db->query($sql);
 93    if ($result)
 94    {
 95        $objp = $db->fetch_object($result);
 96        $conciliated=$objp->rappro;
 97    }
 98
 99    $db->begin();
100
101    $amount = price2num($_POST['amount']);
102    $dateop = dol_mktime(12,0,0,$_POST["dateomonth"],$_POST["dateoday"],$_POST["dateoyear"]);
103    $dateval= dol_mktime(12,0,0,$_POST["datevmonth"],$_POST["datevday"],$_POST["datevyear"]);
104    $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
105    $sql.= " SET ";
106    // Always opened
107    if (isset($_POST['value']))      $sql.=" fk_type='".$db->escape($_POST['value'])."',";
108    if (isset($_POST['num_chq']))    $sql.=" num_chq='".$db->escape($_POST["num_chq"])."',";
109    if (isset($_POST['banque']))     $sql.=" banque='".$db->escape($_POST["banque"])."',";
110    if (isset($_POST['emetteur']))   $sql.=" emetteur='".$db->escape($_POST["emetteur"])."',";
111    // Blocked when conciliated
112    if (! $conciliated)
113    {
114        if (isset($_POST['label']))      $sql.=" label='".$db->escape($_POST["label"])."',";
115        if (isset($_POST['amount']))     $sql.=" amount='".$amount."',";
116        if (isset($_POST['dateomonth'])) $sql.=" dateo = '".$db->idate($dateop)."',";
117        if (isset($_POST['datevmonth'])) $sql.=" datev = '".$db->idate($dateval)."',";
118    }
119    $sql.= " fk_account = ".$accountid;
120    $sql.= " WHERE rowid = ".$rowid;
121
122    $result = $db->query($sql);
123    if ($result)
124    {
125        $mesg=$langs->trans("RecordSaved");
126        $db->commit();
127    }
128    else
129    {
130        $db->rollback();
131        dol_print_error($db);
132    }
133}
134
135// Reconcile
136if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == 'setreconcile'))
137{
138    $num_rel=trim($_POST["num_rel"]);
139    $rappro=$_POST['reconciled']?1:0;
140
141    // Check parameters
142    if ($rappro && empty($num_rel))
143    {
144        $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountStatement"));
145        $error++;
146    }
147
148    if (! $error)
149    {
150        $db->begin();
151
152        $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
153        $sql.= " SET num_releve=".($num_rel?"'".$num_rel."'":"null");
154        if (empty($num_rel)) $sql.= ", rappro = 0";
155        else $sql.=", rappro = ".$rappro;
156        $sql.= " WHERE rowid = ".$rowid;
157
158        dol_syslog("ligne.php sql=".$sql, LOG_DEBUG);
159        $result = $db->query($sql);
160        if ($result)
161        {
162            $mesg=$langs->trans("RecordSaved");
163            $db->commit();
164        }
165        else
166        {
167            $db->rollback();
168            dol_print_error($db);
169        }
170    }
171}
172
173
174
175/*
176 * View
177 */
178
179llxHeader();
180
181// On initialise la liste des categories
182$sql = "SELECT rowid, label";
183$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ";
184$sql.= " ORDER BY label";
185$result = $db->query($sql);
186if ($result)
187{
188    $var=True;
189    $num = $db->num_rows($result);
190    $i = 0;
191    $options = "<option value=\"0\" selected=\"true\">&nbsp;</option>";
192    while ($i < $num)
193    {
194        $obj = $db->fetch_object($result);
195        $options .= "<option value=\"$obj->rowid\">$obj->label</option>\n";
196        $i++;
197    }
198    $db->free($result);
199}
200
201$var=False;
202$h=0;
203
204
205$head[$h][0] = DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$_GET["rowid"];
206$head[$h][1] = $langs->trans('Card');
207$hselected=$h;
208$h++;
209
210$head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$_GET["rowid"];
211$head[$h][1] = $langs->trans("Info");
212$h++;
213
214dol_fiche_head($head, $hselected, $langs->trans('LineRecord'),0,'account');
215
216dol_htmloutput_mesg($mesg);
217
218$sql = "SELECT b.rowid,b.dateo as do,b.datev as dv, b.amount, b.label, b.rappro,";
219$sql.= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,";
220$sql.= " b.emetteur,b.banque";
221$sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
222$sql.= " WHERE rowid=".$rowid;
223$sql.= " ORDER BY dateo ASC";
224$result = $db->query($sql);
225if ($result)
226{
227    $i = 0; $total = 0;
228    if ($db->num_rows($result))
229    {
230        $objp = $db->fetch_object($result);
231
232        $total = $total + $objp->amount;
233
234        $acct=new Account($db);
235        $acct->fetch($objp->fk_account);
236        $account = $acct->id;
237
238        $bankline = new AccountLine($db);
239        $bankline->fetch($rowid,$ref);
240
241        $links=$acct->get_url($rowid);
242        $bankline->load_previous_next_ref('','rowid');
243
244        // Confirmations
245        if ($action == 'delete_categ')
246        {
247            $ret=$form->form_confirm("ligne.php?rowid=".$rowid."&cat1=".GETPOST("fk_categ")."&orig_account=".$orig_account, $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1);
248            if ($ret == 'html') print '<br>';
249        }
250
251        print '<form name="update" method="post" action="ligne.php?rowid='.$rowid.'">';
252        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
253        print '<input type="hidden" name="action" value="update">';
254        print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
255        print '<input type="hidden" name="accountid" value="'.$acct->id.'">';
256
257        print '<table class="border" width="100%">';
258
259        // Ref
260        print '<tr><td width="20%">'.$langs->trans("Ref")."</td>";
261        print '<td colspan="4">';
262        print $form->showrefnav($bankline,'rowid','',1,'rowid','rowid');
263        print '</td>';
264        print '</tr>';
265
266        $i++;
267
268
269        // Bank account
270        print "<tr><td>".$langs->trans("Account")."</td>";
271        print '<td colspan="4">';
272        print $acct->getNomUrl(1,'transactions');
273        print '</td>';
274        print '</tr>';
275
276        // Show links of bank transactions
277        if (count($links))
278        {
279            print "<tr><td>".$langs->trans("Links")."</td>";
280            print '<td colspan="4">';
281            foreach($links as $key=>$val)
282            {
283                if ($key) print '<br>';
284                if ($links[$key]['type']=='payment') {
285                    print '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$links[$key]['url_id'].'">';
286                    print img_object($langs->trans('ShowPayment'),'payment').' ';
287                    print $langs->trans("Payment");
288                    print '</a>';
289                }
290                else if ($links[$key]['type']=='payment_supplier') {
291                    print '<a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$links[$key]['url_id'].'">';
292                    print img_object($langs->trans('ShowPayment'),'payment').' ';
293                    print $langs->trans("Payment");
294                    print '</a>';
295                }
296                else if ($links[$key]['type']=='company') {
297                    print '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$links[$key]['url_id'].'">';
298                    print img_object($langs->trans('ShowThirdParty'),'company').' ';
299                    print $links[$key]['label'];
300                    print '</a>';
301                }
302                else if ($links[$key]['type']=='sc') {
303                    print '<a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$links[$key]['url_id'].'">';
304                    print img_object($langs->trans('ShowSocialContribution'),'bill').' ';
305                    print $langs->trans("SocialContribution").($links[$key]['label']?' - '.$links[$key]['label']:'');
306                    print '</a>';
307                }
308                else if ($links[$key]['type']=='payment_sc') {
309                    print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$links[$key]['url_id'].'">';
310                    print img_object($langs->trans('ShowPayment'),'payment').' ';
311                    print $langs->trans("SocialContributionPayment");
312                    print '</a>';
313                }
314                else if ($links[$key]['type']=='payment_vat') {
315                    print '<a href="'.DOL_URL_ROOT.'/compta/tva/fiche.php?id='.$links[$key]['url_id'].'">';
316                    print img_object($langs->trans('ShowVAT'),'payment').' ';
317                    print $langs->trans("VATPayment");
318                    print '</a>';
319                }
320                else if ($links[$key]['type']=='member') {
321                    print '<a href="'.DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$links[$key]['url_id'].'">';
322                    print img_object($langs->trans('ShowMember'),'user').' ';
323                    print $links[$key]['label'];
324                    print '</a>';
325                }
326                else if ($links[$key]['type']=='banktransfert') {
327                    print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$links[$key]['url_id'].'">';
328                    print img_object($langs->trans('ShowTransaction'),'payment').' ';
329                    print $langs->trans("TransactionOnTheOtherAccount");
330                    print '</a>';
331                }
332                else {
333                    print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
334                    print img_object('','generic').' ';
335                    print $links[$key]['label'];
336                    print '</a>';
337                }
338            }
339            print '</td></tr>';
340        }
341
342        $rowspan=0;
343
344        //$user->rights->banque->modifier=false;
345        //$user->rights->banque->consolidate=true;
346
347        // Type of payment / Number
348        print "<tr><td>".$langs->trans("Type")." / ".$langs->trans("Numero");
349        print "</td>";
350        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
351        {
352            print '<td colspan="3">';
353            print $form->select_types_paiements($objp->fk_type,"value",'',2);
354            print '<input type="text" class="flat" name="num_chq" value="'.(empty($objp->num_chq) ? '' : $objp->num_chq).'">';
355            if ($objp->receiptid)
356            {
357                include_once(DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php');
358                $receipt=new RemiseCheque($db);
359                $receipt->fetch($objp->receiptid);
360                print ' &nbsp; &nbsp; '.$langs->trans("CheckReceipt").': '.$receipt->getNomUrl(2);
361
362            }
363            print '</td>';
364            $rowspan=7;
365            print '<td align="center" rowspan="'.$rowspan.'" width="20%"><input type="submit" class="button" value="'.$langs->trans("Update").'">';
366            print '</td>';
367        }
368        else
369        {
370            print '<td colspan="4">'.$objp->fk_type.' '.$objp->num_chq.'</td>';
371        }
372        print "</tr>";
373
374        // Bank of cheque
375        print "<tr><td>".$langs->trans("Bank")."</td>";
376        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
377        {
378            print '<td colspan="3">';
379            print '<input type="text" class="flat" size="40" name="banque" value="'.(empty($objp->banque) ? '' : $objp->banque).'">';
380            print '</td>';
381        }
382        else
383        {
384            print '<td colspan="'.($rowspan?'3':'4').'">'.$objp->banque.'</td>';
385        }
386        print "</tr>";
387
388        // Transmitter
389        print "<tr><td>".$langs->trans("CheckTransmitter")."</td>";
390        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
391        {
392            print '<td colspan="3">';
393            print '<input type="text" class="flat" size="40" name="emetteur" value="'.(empty($objp->emetteur) ? '' : stripslashes($objp->emetteur)).'">';
394            print '</td>';
395        }
396        else
397        {
398            print '<td colspan="'.($rowspan?'3':'4').'">'.$objp->emetteur.'</td>';
399        }
400        print "</tr>";
401
402        // Date ope
403        print '<tr><td>'.$langs->trans("DateOperation").'</td>';
404        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
405        {
406            print '<td colspan="3">';
407            print $form->select_date($db->jdate($objp->do),'dateo','','','','update',1,0,1,$objp->rappro);
408            print '</td>';
409        }
410        else
411        {
412            print '<td colspan="'.($rowspan?'3':'4').'">';
413            print dol_print_date($db->jdate($objp->do),"day");
414            print '</td>';
415        }
416        print '</tr>';
417
418        // Value date
419        print "<tr><td>".$langs->trans("DateValue")."</td>";
420        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
421        {
422            print '<td colspan="3">';
423            print $form->select_date($db->jdate($objp->dv),'datev','','','','update',1,0,1,$objp->rappro);
424            if (! $objp->rappro)
425            {
426                print ' &nbsp; ';
427                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$_GET["account"].'&amp;rowid='.$objp->rowid.'">';
428                print img_edit_remove() . "</a> ";
429                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$_GET["account"].'&amp;rowid='.$objp->rowid.'">';
430                print img_edit_add() ."</a>";
431            }
432            print '</td>';
433        }
434        else
435        {
436            print '<td colspan="'.($rowspan?'3':'4').'">';
437            print dol_print_date($db->jdate($objp->dv),"day");
438            print '</td>';
439        }
440        print "</tr>";
441
442        // Description
443        print "<tr><td>".$langs->trans("Label")."</td>";
444        if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
445        {
446            print '<td colspan="3">';
447            print '<input name="label" class="flat" '.($objp->rappro?' disabled="disabled"':'').' value="';
448            if (preg_match('/^\((.*)\)$/i',$objp->label,$reg))
449            {
450                // Label generique car entre parentheses. On l'affiche en le traduisant
451                print $langs->trans($reg[1]);
452            }
453            else
454            {
455                print $objp->label;
456            }
457            print '" size="50">';
458            print '</td>';
459        }
460        else
461        {
462            print '<td colspan="'.($rowspan?'3':'4').'">';
463            if (preg_match('/^\((.*)\)$/i',$objp->label,$reg))
464            {
465                // Label generique car entre parentheses. On l'affiche en le traduisant
466                print $langs->trans($reg[1]);
467            }
468            else
469            {
470                print $objp->label;
471            }
472            print '</td>';
473        }
474        print '</tr>';
475
476        // Amount
477        print "<tr><td>".$langs->trans("Amount")."</td>";
478        if ($user->rights->banque->modifier)
479        {
480            print '<td colspan="3">';
481            print '<input name="amount" class="flat" size="10" '.($objp->rappro?' disabled="disabled"':'').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$conf->monnaie);
482            print '</td>';
483        }
484        else
485        {
486            print '<td colspan="'.($rowspan?'3':'4').'">';
487            print price($objp->amount);
488            print '</td>';
489        }
490        print "</tr>";
491
492        print "</table>";
493        print "</form>";
494
495        // Releve rappro
496        if ($acct->canBeConciliated() > 0)  // Si compte rapprochable
497        {
498            print '<br>'."\n";
499            print_fiche_titre($langs->trans("Reconciliation"),'','');
500            print "<form method=\"post\" action=\"ligne.php?rowid=$objp->rowid\">";
501            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
502            print '<input type="hidden" name="action" value="setreconcile">';
503            print "<input type=\"hidden\" name=\"orig_account\" value=\"".$orig_account."\">";
504
505            print '<table class="border" width="100%">';
506
507            print '<tr><td width="20%">'.$langs->trans("Conciliation")."</td>";
508            if ($user->rights->banque->consolidate)
509            {
510                print '<td colspan="3">';
511                if ($objp->rappro)
512                {
513                    print $langs->trans("AccountStatement").' <input name="num_rel_bis" class="flat" value="'.$objp->num_releve.'"'.($objp->rappro?' disabled="disabled"':'').'>';
514                    print '<input name="num_rel" type="hidden" value="'.$objp->num_releve.'">';
515                }
516                else
517                {
518                    print $langs->trans("AccountStatement").' <input name="num_rel" class="flat" value="'.$objp->num_releve.'"'.($objp->rappro?' disabled="disabled"':'').'>';
519                }
520                print '</td><td align="center" rowspan="2" width="20%"><input type="submit" class="button" value="'.$langs->trans("Update").'"></td>';
521            }
522            else
523            {
524                print '<td colspan="4">'.$objp->num_releve.'&nbsp;</td>';
525            }
526            print '</tr>';
527
528            print "<tr><td>".$langs->trans("BankLineConciliated")."</td>";
529            if ($user->rights->banque->consolidate)
530            {
531                print '<td colspan="3">';
532                print '<input type="checkbox" name="reconciled" class="flat" '.(isset($_POST["reconciled"])?($_POST["reconciled"]?' checked="checked"':''):($objp->rappro?' checked="checked"':'')).'">';
533                print '</td>';
534            }
535            else
536            {
537                print '<td colspan="4">'.yn($objp->rappro).'</td>';
538            }
539            print '</tr>';
540
541            print "</table>";
542            print '</form>';
543        }
544
545    }
546
547    $db->free($result);
548}
549else dol_print_error($db);
550print '</div>';
551
552
553
554// List of bank categories
555
556print '<br>';
557print '<table class="noborder" width="100%">';
558
559print "<form method=\"post\" action=\"ligne.php?rowid=$rowid&amp;account=$account\">";
560print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
561print "<input type=\"hidden\" name=\"action\" value=\"class\">";
562print "<input type=\"hidden\" name=\"orig_account\" value=\"".$orig_account."\">";
563print "<tr class=\"liste_titre\"><td>".$langs->trans("Rubriques")."</td><td colspan=\"2\">";
564print "<select class=\"flat\" name=\"cat1\">".$options."</select>&nbsp;";
565print '<input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
566print "</tr>";
567print "</form>";
568
569$sql = "SELECT c.label, c.rowid";
570$sql.= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c";
571$sql.= " WHERE a.lineid=".$rowid." AND a.fk_categ = c.rowid";
572$sql.= " ORDER BY c.label";
573$result = $db->query($sql);
574if ($result)
575{
576    $var=True;
577    $num = $db->num_rows($result);
578    $i = 0; $total = 0;
579    while ($i < $num)
580    {
581        $objp = $db->fetch_object($result);
582
583        $var=!$var;
584        print "<tr ".$bc[$var].">";
585
586        print "<td>".$objp->label."</td>";
587        print "<td align=\"center\"><a href=\"budget.php?bid=".$objp->rowid."\">".$langs->trans("ListBankTransactions")."</a></td>";
588        if ($user->rights->banque->modifier)
589        {
590            print "<td align=\"right\"><a href=\"ligne.php?action=delete_categ&amp;rowid=".$rowid."&amp;fk_categ=$objp->rowid\">".img_delete($langs->trans("Remove"))."</a></td>";
591        }
592        print "</tr>";
593
594        $i++;
595    }
596    $db->free($result);
597}
598print "</table>";
599
600$db->close();
601
602llxFooter();
603?>