From 27ec0a2ac8169695a76dfcaa1f0df2c306201573 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 3 Apr 2008 20:43:12 +0000 Subject: [PATCH] New: Now we can correct vat payments --- htdocs/compta/bank/account.class.php | 3 +- htdocs/compta/paiement/fiche.php | 6 +- htdocs/compta/tva/fiche.php | 200 +++++++++++++++------------ htdocs/compta/tva/tva.class.php | 39 +++++- 4 files changed, 150 insertions(+), 98 deletions(-) diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index f431a067524..6d7dfd5305e 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -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; diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index 8ceeee53ae3..d1101fc76ce 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * * 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'); diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index e1eaa1ac1bb..d4d34a974c1 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -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='
'.$tva->error.'
'; + $mesg='
'.$tva->error.'
'; $_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='
'.$tva->error.'
'; + } + } + else + { + $db->rollback(); + $mesg='
'.$tva->error.'
'; + } + } + else + { + $mesg='
Error try do delete a line linked to a conciliated bank transaction
'; + } +} +/* +* 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 ''; @@ -113,11 +161,11 @@ if ($_GET["action"] == 'create') if ($conf->banque->enabled) { print ''; - print '\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 '
'.$langs->trans("Account").''; - $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 '
'.$langs->trans("Type").''; - $html->select_types_paiements($vatpayment->paiementtype, "paiementtype"); + print '
'.$langs->trans("PaymentMode").''; + $html->select_types_paiements($vatpayment->fk_type, "paiementtype"); print "
'; + + print ""; + print ''; + + print ""; + print ''; + + print ''; + + if ($conf->banque->enabled) { - if ($mesg) print $mesg.'
'; - - $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 '
'.$langs->trans("Ref").''; + print $vatpayment->ref; + print '
'.$langs->trans("DatePayment").''; + print dolibarr_print_date($vatpayment->datep,'day'); + print '
'.$langs->trans("DateValue").''; + print dolibarr_print_date($vatpayment->datev,'day'); + print '
'; - - print ""; - print ''; - - print ''; - - print '\n"; - - if ($conf->banque->enabled) - { - print ''; - } - - print ''; - } - - - 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 '
'.$langs->trans("DatePayment").''; - print dolibarr_print_date($vatpayment->date); - print '
'.$langs->trans("DateValue").''; - print $html->select_date("","datep",'','','','add'); - print '
'.$langs->trans("Type").''; - $html->select_types_paiements($charge->paiementtype, "paiementtype"); - print "
'.$langs->trans("Account").''; - $html->select_comptes($charge->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant - print '
'.$langs->trans("Amount").'
'; - - print ""; - print ''; - - print ""; - print ''; - - print ''; - - if ($conf->banque->enabled) - { - print ''; + if ($vatpayment->fk_account > 0) + { $account=new Account($db); $result=$account->fetch($vatpayment->fk_account); - print $account->getNomUrl(1); - print ''; - - print '\n"; + print ''; + print ''; } + else + { + print ''; + } + print ''; - print ''; - } + print '\n"; + } + + print ''; + + print '
'.$langs->trans("Ref").''; - print $vatpayment->ref; - print '
'.$langs->trans("DatePayment").''; - print dolibarr_print_date($vatpayment->datep,'day'); - print '
'.$langs->trans("DateValue").''; - print dolibarr_print_date($vatpayment->datev,'day'); - print '
'.$langs->trans("Account").''; + print '
'.$langs->trans("Account").'
'.$langs->trans("Type").''; - print $vatpayment->fk_type ? $langs->trans("PaymentTypeShort".$vatpayment->fk_type) : $langs->trans("Unknown"); - print "'.$account->getNomUrl(1).''.$langs->trans("BankLineConciliated").''.yn($vatpayment->rappro).' 
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans("PaymentMode").''; + print $vatpayment->fk_type ? $langs->trans("PaymentTypeShort".$vatpayment->fk_type) : ' '; + print "
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'; + + print ''; + + /* + * Boutons d'actions + */ + print "
\n"; + if ($vatpayment->rappro == 0) + print ''.$langs->trans("Delete").''; + else + print ''.$langs->trans("Delete").''; + print "
"; } diff --git a/htdocs/compta/tva/tva.class.php b/htdocs/compta/tva/tva.class.php index d1548d56afe..38ce1b4d6f0 100644 --- a/htdocs/compta/tva/tva.class.php +++ b/htdocs/compta/tva/tva.class.php @@ -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 {