diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index ef75e8746d1e4527541a4046fa227ff21144f686..711ccc62f1ff2943adb7292c4fa391740b57df09 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -1,6 +1,7 @@ <?php /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +42,8 @@ class Tva extends CommonObject var $datep; var $datev; var $amount; + var $type_payment; + var $num_payment; var $label; var $note; var $fk_bank; @@ -215,6 +218,8 @@ class Tva extends CommonObject $sql.= " t.datep,"; $sql.= " t.datev,"; $sql.= " t.amount,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; $sql.= " t.label,"; $sql.= " t.note,"; $sql.= " t.fk_bank,"; @@ -242,6 +247,8 @@ class Tva extends CommonObject $this->datep = $this->db->jdate($obj->datep); $this->datev = $this->db->jdate($obj->datev); $this->amount = $obj->amount; + $this->type_payment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; $this->label = $obj->label; $this->note = $obj->note; $this->fk_bank = $obj->fk_bank; @@ -479,7 +486,12 @@ class Tva extends CommonObject // Clean parameters $this->amount=price2num(trim($this->amount)); - + $this->label=trim($this->label); + $this->note=trim($this->note); + $this->fk_bank=trim($this->fk_bank); + $this->fk_user_creat=trim($this->fk_user_creat); + $this->fk_user_modif=trim($this->fk_user_modif); + // Check parameters if (! $this->label) { @@ -496,23 +508,35 @@ class Tva extends CommonObject $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account")); return -5; } - if (! empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0)) + if (! empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) { $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); return -5; } - // Insertion dans table des paiement tva - $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount"; - if ($this->note) $sql.=", note"; - if ($this->label) $sql.=", label"; - $sql.= ", fk_user_creat, fk_bank, entity"; + // Insertion dans la table d'un paiement tva + $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep"; + $sql.= ", datev"; + $sql.= ", amount"; + $sql.= ", fk_typepayment"; + $sql.= ", num_payment"; + if ($this->note) $sql.= ", note"; + if ($this->label) $sql.= ", label"; + $sql.= ", fk_user_creat"; + $sql.= ", fk_bank"; + $sql.= ", entity"; $sql.= ") "; - $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; - $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; - if ($this->note) $sql.=", '".$this->db->escape($this->note)."'"; + $sql.= " VALUES ("; + $sql.= "'".$this->db->idate($this->datep)."'"; + $sql.= ", '".$this->db->idate($this->datev)."'"; + $sql.= ", ".$this->amount; + $sql.= ", '".$this->type_payment."'"; + $sql.= ", '".$this->num_payment."'"; + if ($this->note) $sql.=", '".$this->db->escape($this->note)."'"; if ($this->label) $sql.=", '".$this->db->escape($this->label)."'"; - $sql.=", '".$user->id."', NULL, ".$conf->entity; + $sql.= ", '".$user->id."'"; + $sql.= ", NULL"; + $sql.= ", ".$conf->entity; $sql.= ")"; dol_syslog(get_class($this)."::addPayment sql=".$sql); @@ -540,7 +564,7 @@ class Tva extends CommonObject $result=$acc->fetch($this->accountid); if ($result <= 0) dol_print_error($this->db); - $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); + $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), '', '', $user); // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction if ($bank_line_id > 0) diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index a0d181e8f81d5599eebbe1526fcf8c50da602611..d4accc5134dedc6a355002661d3ec9e822e8b2e5 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -58,31 +58,51 @@ if ($_POST["cancel"] == $langs->trans("Cancel")) if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) { - $db->begin(); + $error=0; - $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]); + $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]); $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]); - $tva->accountid=$_POST["accountid"]; - $tva->paymenttype=$_POST["paiementtype"]; + $tva->accountid=GETPOST("accountid"); + $tva->type_payment=GETPOST("type_payment"); + $tva->num_payment=GETPOST("num_payment"); $tva->datev=$datev; $tva->datep=$datep; - $tva->amount=$_POST["amount"]; - $tva->label=$_POST["label"]; + $tva->amount=GETPOST("amount"); + $tva->label=GETPOST("label"); + $tva->note=GETPOST("note"); + + if (empty($tva->type_payment) || $tva->type_payment < 0) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentMode")),'errors'); + $error++; + } + if (empty($tva->amount)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")),'errors'); + $error++; + } - $ret=$tva->addPayment($user); - if ($ret > 0) - { - $db->commit(); - header("Location: reglement.php"); - exit; - } - else - { - $db->rollback(); - setEventMessage($tva->error, 'errors'); - $action="create"; - } + if (! $error) + { + $db->begin(); + + $ret=$tva->addPayment($user); + if ($ret > 0) + { + $db->commit(); + header("Location: reglement.php"); + exit; + } + else + { + $db->rollback(); + setEventMessage($tva->error, 'errors'); + $action="create"; + } + } + + $action='create'; } if ($action == 'delete') @@ -180,10 +200,16 @@ if ($action == 'create') $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant print '</td></tr>'; - print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>'; - $form->select_types_paiements($_POST["paiementtype"], "paiementtype"); - print "</td>\n"; - print "</tr>"; + // Type payment + print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>'; + $form->select_types_paiements(GETPOST("type_payment"), "type_payment"); + print "</td>\n"; + print "</tr>"; + + // Number + print '<tr><td>'.$langs->trans('Numero'); + print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>'; + print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n"; } // Other attributes diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index ea9f7ea445dc77d3bc778c5a5c3d44261c19134b..a35c03076cb2f744215a6bf84e6da40c393a8bd7 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com> + * Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; $langs->load("compta"); -$langs->load("compta"); +$langs->load("bills"); // Security check $socid = isset($_GET["socid"])?$_GET["socid"]:''; @@ -46,9 +47,10 @@ $tva_static = new Tva($db); print_fiche_titre($langs->trans("VATPayments")); -$sql = "SELECT rowid, amount, label, f.datev as dm"; -$sql.= " FROM ".MAIN_DB_PREFIX."tva as f "; -$sql.= " WHERE f.entity = ".$conf->entity; +$sql = "SELECT t.rowid, t.amount, t.label, t.datev as dm, t.num_payment, pst.code as payment_code"; +$sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id"; +$sql.= " WHERE t.entity = ".$conf->entity; $sql.= " ORDER BY dm DESC"; $result = $db->query($sql); @@ -63,7 +65,8 @@ if ($result) print '<td class="nowrap" align="left">'.$langs->trans("Ref").'</td>'; print "<td>".$langs->trans("Label")."</td>"; print '<td class="nowrap" align="left">'.$langs->trans("DatePayment").'</td>'; - print "<td align=\"right\">".$langs->trans("PayedByThisPayment")."</td>"; + print '<td class="nowrap" align="left">'.$langs->trans("Type").'</td>'; + print "<td align=\"right\">".$langs->trans("PayedByThisPayment")."</td>"; print "</tr>\n"; $var=1; while ($i < $num) @@ -77,14 +80,16 @@ if ($result) print "<td>".$tva_static->getNomUrl(1)."</td>\n"; print "<td>".dol_trunc($obj->label,40)."</td>\n"; print '<td align="left">'.dol_print_date($db->jdate($obj->dm),'day')."</td>\n"; + // Type + print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>'; + // Amount $total = $total + $obj->amount; - - print "<td align=\"right\">".price($obj->amount)."</td>"; + print "<td align=\"right\">".price($obj->amount)."</td>"; print "</tr>\n"; $i++; } - print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td>'; + print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Total").'</td>'; print "<td align=\"right\"><b>".price($total)."</b></td></tr>"; print "</table>";