New: Now we can correct vat payments

This commit is contained in:
Laurent Destailleur 2008-04-03 20:43:12 +00:00
parent f640786680
commit 27ec0a2ac8
4 changed files with 150 additions and 98 deletions

View File

@ -831,9 +831,10 @@ class AccountLine
/**
* \brief Efface ligne bancaire
* \param user User object that delete
* \return int <0 si KO, >0 si OK
*/
function delete()
function delete($user=0)
{
$nbko=0;

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
*
* This program is free software; you can redistribute it and/or modify
@ -16,8 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
/**
@ -25,7 +23,7 @@
\ingroup facture
\brief Onglet paiement d'un paiement client
\remarks Fichier presque identique a fournisseur/paiement/fiche.php
\version $Revision$
\version $Id$
*/
require('./pre.inc.php');

View File

@ -29,8 +29,9 @@ require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php");
require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php");
$langs->load("compta");
$langs->load("banks");
$id=$_GET["id"];
$id=$_REQUEST["id"];
$mesg = '';
@ -46,8 +47,8 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
$tva->accountid=$_POST["accountid"];
$tva->paymenttype=$_POST["paiementtype"];
$tva->datev=mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
$tva->datep=mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
$tva->datev=dolibarr_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
$tva->datep=dolibarr_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
$tva->amount=$_POST["amount"];
$tva->label=$_POST["label"];
@ -61,13 +62,60 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
else
{
$db->rollback();
$message='<div class="error">'.$tva->error.'</div>';
$mesg='<div class="error">'.$tva->error.'</div>';
$_GET["action"]="create";
}
}
if ($_GET["action"] == 'delete')
{
$tva = new Tva($db);
$result=$tva->fetch($_GET['id']);
if ($tva->rappro == 0)
{
$db->begin();
$ret=$tva->delete($user);
if ($ret > 0)
{
if ($tva->fk_bank)
{
$accountline=new AccountLine($db);
$result=$accountline->fetch($vatpayment->fk_bank);
$result=$accountline->delete($user);
}
if ($result > 0)
{
$db->commit();
header("Location: ".DOL_URL_ROOT.'/compta/tva/reglement.php');
exit;
}
else
{
$tva->error=$accountline->error;
$db->rollback();
$mesg='<div class="error">'.$tva->error.'</div>';
}
}
else
{
$db->rollback();
$mesg='<div class="error">'.$tva->error.'</div>';
}
}
else
{
$mesg='<div class="error">Error try do delete a line linked to a conciliated bank transaction</div>';
}
}
/*
* View
*/
llxHeader();
$html = new Form($db);
@ -91,7 +139,7 @@ if ($_GET["action"] == 'create')
print_fiche_titre($langs->trans("NewVATPayment"));
if ($message) print $message;
if ($mesg) print $mesg;
print '<table class="border" width="100%">';
@ -113,11 +161,11 @@ if ($_GET["action"] == 'create')
if ($conf->banque->enabled)
{
print '<tr><td>'.$langs->trans("Account").'</td><td>';
$html->select_comptes($vatpayment->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant
$html->select_comptes($vatpayment->fk_account,"accountid",0,"courant=1",1); // Affiche liste des comptes courant
print '</td></tr>';
print '<tr><td>'.$langs->trans("Type").'</td><td>';
$html->select_types_paiements($vatpayment->paiementtype, "paiementtype");
print '<tr><td>'.$langs->trans("PaymentMode").'</td><td>';
$html->select_types_paiements($vatpayment->fk_type, "paiementtype");
print "</td>\n";
}
@ -136,89 +184,69 @@ if ($_GET["action"] == 'create')
if ($id)
{
if ($_GET["action"] == 'edit')
if ($mesg) print $mesg;
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/tva/fiche.php?id='.$vatpayment->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
dolibarr_fiche_head($head, 'card', $langs->trans("VATPayment"));
print '<table class="border" width="100%">';
print "<tr>";
print '<td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $vatpayment->ref;
print '</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("DatePayment").'</td><td colspan="3">';
print dolibarr_print_date($vatpayment->datep,'day');
print '</td></tr>';
print '<tr><td>'.$langs->trans("DateValue").'</td><td colspan="3">';
print dolibarr_print_date($vatpayment->datev,'day');
print '</td></tr>';
if ($conf->banque->enabled)
{
if ($mesg) print $mesg.'<br>';
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/tva/fiche.php?id='.$tva->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
dolibarr_fiche_head($head, 'card', $langs->trans("VATPayment"));
print '<table class="border" width="100%">';
print "<tr>";
print '<td>'.$langs->trans("DatePayment").'</td><td>';
print dolibarr_print_date($vatpayment->date);
print '</td></tr>';
print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
print $html->select_date("","datep",'','','','add');
print '</td></tr>';
print '<tr><td>'.$langs->trans("Type").'</td><td>';
$html->select_types_paiements($charge->paiementtype, "paiementtype");
print "</td>\n";
if ($conf->banque->enabled)
{
print '<tr><td>'.$langs->trans("Account").'</td><td>';
$html->select_comptes($charge->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value=""></td></tr>';
}
if ($_GET["action"] != 'edit')
{
if ($mesg) print $mesg.'<br>';
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/tva/fiche.php?id='.$vatpayment->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
dolibarr_fiche_head($head, 'card', $langs->trans("VATPayment"));
print '<table class="border" width="100%">';
print "<tr>";
print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print $vatpayment->ref;
print '</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("DatePayment").'</td><td>';
print dolibarr_print_date($vatpayment->datep,'day');
print '</td></tr>';
print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
print dolibarr_print_date($vatpayment->datev,'day');
print '</td></tr>';
if ($conf->banque->enabled)
{
print '<tr><td>'.$langs->trans("Account").'</td><td>';
print '<tr><td>'.$langs->trans("Account").'</td>';
if ($vatpayment->fk_account > 0)
{
$account=new Account($db);
$result=$account->fetch($vatpayment->fk_account);
print $account->getNomUrl(1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Type").'</td><td>';
print $vatpayment->fk_type ? $langs->trans("PaymentTypeShort".$vatpayment->fk_type) : $langs->trans("Unknown");
print "</td>\n";
print '<td>'.$account->getNomUrl(1).'</td>';
print '<td width="25%">'.$langs->trans("BankLineConciliated").'</td><td width="25%">'.yn($vatpayment->rappro).'</td>';
}
else
{
print '<td colspan="3">&nbsp;</td>';
}
print '</tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($vatpayment->amount).'</td></tr>';
}
print '<tr><td>'.$langs->trans("PaymentMode").'</td><td colspan="3">';
print $vatpayment->fk_type ? $langs->trans("PaymentTypeShort".$vatpayment->fk_type) : '&nbsp;';
print "</td>\n";
}
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="3">'.price($vatpayment->amount).'</td></tr>';
print '</table>';
print '</div>';
/*
* Boutons d'actions
*/
print "<div class=\"tabsAction\">\n";
if ($vatpayment->rappro == 0)
print '<a class="butActionDelete" href="fiche.php?id='.$vatpayment->id.'&action=delete">'.$langs->trans("Delete").'</a>';
else
print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
print "</div>";
}

View File

@ -225,7 +225,8 @@ class Tva extends CommonObject
$sql.= " t.fk_user_creat,";
$sql.= " t.fk_user_modif,";
$sql.= " b.fk_account,";
$sql.= " b.fk_type";
$sql.= " b.fk_type,";
$sql.= " b.rappro";
$sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid";
@ -252,6 +253,7 @@ class Tva extends CommonObject
$this->fk_user_modif = $obj->fk_user_modif;
$this->fk_account = $obj->fk_account;
$this->fk_type = $obj->fk_type;
$this->rappro = $obj->rappro;
}
$this->db->free($resql);
@ -482,11 +484,16 @@ class Tva extends CommonObject
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
return -4;
}
if ($conf->banque->enabled && (empty($this->accountid) || $this->accountid < 0))
if ($conf->banque->enabled && (empty($this->accountid) || $this->accountid <= 0))
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account"));
return -5;
}
if ($conf->banque->enabled && (empty($this->paymenttype) || $this->paymenttype <= 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";
@ -508,19 +515,28 @@ class Tva extends CommonObject
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva
if ($this->id > 0)
{
if ($conf->banque->enabled)
$ok=1;
if ($conf->banque->enabled)
{
// Insertion dans llx_bank
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
$acc = new Account($this->db, $this->accountid);
$acc = new Account($this->db);
$result=$acc->fetch($this->accountid);
if ($result <= 0) dolibarr_print_error($db);
$bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user);
// Mise a jour fk_bank dans llx_tva. On connait ainsi la ligne de tva qui a généré l'écriture bancaire
if ($bank_line_id)
if ($bank_line_id > 0)
{
$this->update_fk_bank($bank_line_id);
}
else
{
$this->error=$acc->error;
$ok=0;
}
// Mise a jour liens (pour chaque charge concernée par le paiement)
//foreach ($paiement->amounts as $key => $value)
@ -533,8 +549,17 @@ class Tva extends CommonObject
// $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom);
//}
}
$this->db->commit();
return $this->id;
if ($ok)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -3;
}
}
else
{