diff --git a/build/pad/Dolibarr v2.2.pml b/build/pad/Dolibarr v2.2.pml index 6fb8e2232b4..d6833e13763 100644 --- a/build/pad/Dolibarr v2.2.pml +++ b/build/pad/Dolibarr v2.2.pml @@ -59,11 +59,11 @@ http://www.dolibarr.org http://www.dolibarr.org/images/dolibarr_screenshot2.png http://www.dolibarr.org/images/dolibarr.gif - http://www.dolibarr.org/component/option,com_docman/task,doc_download/gid,17/Itemid,36/index.php + http://www.dolibarr.org/images/pad_dolibarr.xml - http://www.dolibarr.org/component/option,com_docman/task,doc_download/gid,1/Itemid,36/index.php - + http://www.dolibarr.org/images/dolibarr.tgz + http://www.dolibarr.org/images/dolibarr.tgz diff --git a/build/pad/pad_dolibarr.htm b/build/pad/pad_dolibarr.htm index ba5a09e361e..2982c81ad2b 100644 Binary files a/build/pad/pad_dolibarr.htm and b/build/pad/pad_dolibarr.htm differ diff --git a/build/pad/pad_dolibarr.xml b/build/pad/pad_dolibarr.xml index 7029596991e..3617a000c5a 100644 --- a/build/pad/pad_dolibarr.xml +++ b/build/pad/pad_dolibarr.xml @@ -89,11 +89,11 @@ http://www.dolibarr.org http://www.dolibarr.org/images/dolibarr_screenshot2.png http://www.dolibarr.org/images/dolibarr.gif - http://www.dolibarr.org/component/option,com_docman/task,doc_download/gid,17/Itemid,36/index.php + http://www.dolibarr.org/images/pad_dolibarr.xml - http://www.dolibarr.org/component/option,com_docman/task,doc_download/gid,1/Itemid,36/index.php - + http://www.dolibarr.org/images/dolibarr.tgz + http://www.dolibarr.org/images/dolibarr.tgz diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index 21b30faa6b2..3ea11ffc451 100644 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -29,9 +29,10 @@ $script_file=__FILE__; if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]); -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You use PHP for CGI mode. To execute $script_file as a command line program, you must use PHP for CLI mode (try php-cli).\n"; - exit; +if (substr($sapi_type, 0, 3) == 'cgi') +{ + echo "Error: You use PHP for CGI mode. To execute $script_file as a command line program, you must use PHP for CLI mode (try php-cli).\n"; + exit; } // Include Dolibarr environment @@ -263,7 +264,7 @@ foreach($property as $key => $prop) $varprop.="\t\t\$sql.= \" "; if ($prop['istime']) $varprop.="\".\$this->db->pdate('"; $varprop.="t.".$prop['field']; - if ($prop['istime']) $varprop.="').\""; + if ($prop['istime']) $varprop.="').\" as ".$prop['field']; if ($i < sizeof($property)) $varprop.=","; $varprop.="\";"; $varprop.="\n"; diff --git a/htdocs/compta/bank/index.php b/htdocs/compta/bank/index.php index 8223a65c344..b83ea7e58eb 100644 --- a/htdocs/compta/bank/index.php +++ b/htdocs/compta/bank/index.php @@ -15,20 +15,18 @@ * 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$ */ /** \file htdocs/compta/bank/index.php \ingroup banque \brief Page accueil banque - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); $langs->load("banks"); diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index caa66dcfc05..9b65e33bf8d 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -28,7 +28,7 @@ */ require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); if (!$user->admin && !$user->rights->tax->charges->lire) accessforbidden(); diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php index 3e840e2b9ce..949caba7171 100644 --- a/htdocs/compta/deplacement/index.php +++ b/htdocs/compta/deplacement/index.php @@ -26,7 +26,7 @@ */ require("./pre.inc.php"); -require("../../tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); $langs->load("companies"); $langs->load("users"); diff --git a/htdocs/compta/resultat/bilan.php b/htdocs/compta/resultat/bilan.php index ad11218b1bb..82329346fd3 100644 --- a/htdocs/compta/resultat/bilan.php +++ b/htdocs/compta/resultat/bilan.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -14,27 +14,26 @@ * 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$ - * $Source$ - * */ /** \file htdocs/compta/resultat/pre.inc.php \ingroup compta \brief Fichier gestionnaire du menu paramétrage de la compta + \version $Id$ */ require("./pre.inc.php"); -require("../../tva.class.php"); -require("../../chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); -/* - * - */ if (!$user->rights->compta->resultat->lire) accessforbidden(); + +/* + * Views + */ + llxHeader(); $year=$_GET["year"]; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 1876e41c614..77fb64f2c56 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -15,18 +15,16 @@ * 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$ */ /** \file htdocs/compta/resultat/clientfourn.php \brief Page reporting resultat - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.inc.php"); diff --git a/htdocs/compta/resultat/compteres.php b/htdocs/compta/resultat/compteres.php index 573b60d1789..fff2ec7df08 100644 --- a/htdocs/compta/resultat/compteres.php +++ b/htdocs/compta/resultat/compteres.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -14,21 +14,20 @@ * 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$ - * $Source$ - * */ -require("./pre.inc.php"); -require("../../tva.class.php"); -require("../../chargesociales.class.php"); -/* - * - */ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); + + if (!$user->rights->compta->resultat->lire) accessforbidden(); +/* +* Views +*/ llxHeader(); $year=$_GET["year"]; diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php index 9960b0f220b..5b423aa455f 100644 --- a/htdocs/compta/tva/clients.php +++ b/htdocs/compta/tva/clients.php @@ -29,7 +29,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); $langs->load("bills"); $langs->load("compta"); @@ -121,7 +121,7 @@ if ($modetax==0) // Invoice for goods, payment for services $productsup=$langs->trans("Description"); $amountsup=$langs->trans("AmountHT"); $vatsup=$langs->trans("VATPayed"); - if ($conf->global->FACTURE_TVAOPTION != 'franchise') $vatsup.=' ('.$langs->trans("TogetBack").')'; + if ($conf->global->FACTURE_TVAOPTION != 'franchise') $vatsup.=' ('.$langs->trans("ToGetBack").')'; } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index 293d1c1bff2..e1eaa1ac1bb 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -25,13 +25,13 @@ */ require("./pre.inc.php"); -require("../../tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); $langs->load("compta"); $id=$_GET["id"]; - $mesg = ''; @@ -72,6 +72,17 @@ llxHeader(); $html = new Form($db); +if ($id) +{ + $vatpayment = new Tva($db); + $result = $vatpayment->fetch($id); + if ($result <= 0) + { + dolibarr_print_error($db); + exit; + } +} + // Formulaire saisie tva if ($_GET["action"] == 'create') { @@ -102,11 +113,11 @@ if ($_GET["action"] == 'create') if ($conf->banque->enabled) { print ''.$langs->trans("Account").''; - $html->select_comptes($charge->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant + $html->select_comptes($vatpayment->accountid,"accountid",0,"courant=1",1); // Affiche liste des comptes courant print ''; print ''.$langs->trans("Type").''; - $html->select_types_paiements($charge->paiementtype, "paiementtype"); + $html->select_types_paiements($vatpayment->paiementtype, "paiementtype"); print "\n"; } @@ -125,11 +136,7 @@ if ($_GET["action"] == 'create') if ($id) { - print_fiche_titre($langs->trans("VATPayment")); - - $vatpayment = new Tva($db); - - if ($vatpayment->fetch($id) > 0) + if ($_GET["action"] == 'edit') { if ($mesg) print $mesg.'
'; @@ -166,7 +173,52 @@ if ($id) print ''.$langs->trans("Amount").''; } - + + + 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 ''; + + print ""; + print ''; + + print ""; + print ''; + + print ''; + + if ($conf->banque->enabled) + { + print ''; + + print '\n"; + } + + print ''; + } } diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 61d6d76b9e6..76f837b4110 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Éric Seigne - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -16,20 +16,16 @@ * 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$ - * $Source$ - * */ /** \file htdocs/compta/tva/index.php \ingroup tax \brief Page des societes - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); -require("../../tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); $langs->load("other"); diff --git a/htdocs/compta/tva/quadri.php b/htdocs/compta/tva/quadri.php index 39ac08d0bd0..6e5374c770f 100644 --- a/htdocs/compta/tva/quadri.php +++ b/htdocs/compta/tva/quadri.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Éric Seigne - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2006 Yannick Warnier * * This program is free software; you can redistribute it and/or modify @@ -28,7 +28,7 @@ */ require("./pre.inc.php"); -require("../../tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); $year=$_GET["year"]; if ($year == 0 ) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index b8f9f3a1901..f7570275f20 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -30,7 +30,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); @@ -153,318 +153,317 @@ if (! is_array($x_coll) || ! is_array($x_paye)) { print ''; //print ''; - break; } - -$x_both = array(); -//now, from these two arrays, get another array with one rate per line -foreach(array_keys($x_coll) as $my_coll_rate) +else { - $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; - $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; - $x_both[$my_coll_rate]['paye']['totalht'] = 0; - $x_both[$my_coll_rate]['paye']['vat'] = 0; - $x_both[$my_coll_rate]['coll']['links'] = ''; - $x_both[$my_coll_rate]['coll']['detail'] = array(); - foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) + $x_both = array(); + //now, from these two arrays, get another array with one rate per line + foreach(array_keys($x_coll) as $my_coll_rate) { - $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; - $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; - $x_both[$my_coll_rate]['coll']['detail'][] = array( - 'id' =>$x_coll[$my_coll_rate]['facid'][$id], - 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], - 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], - 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], - 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], - 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], - 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], - 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], - 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], - 'link' =>$invoice_customer->getNomUrl(1)); - //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; - } -} -// tva payed -foreach(array_keys($x_paye) as $my_paye_rate){ - $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; - $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; - if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){ - $x_both[$my_paye_rate]['coll']['totalht'] = 0; - $x_both[$my_paye_rate]['coll']['vat'] = 0; - } - $x_both[$my_paye_rate]['paye']['links'] = ''; - $x_both[$my_paye_rate]['paye']['detail'] = array(); - - foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) - { - $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; - $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; - $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_rate]['facid'][$id], - 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], - 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], - 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], - 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], - 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], - 'ftotal_ttc'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id], - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - 'link' =>$invoice_supplier->getNomUrl(1)); - //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; - } -} -//now we have an array (x_both) indexed by rates for coll and paye - - -//print table headers for this quadri - incomes first - -$x_coll_sum = 0; -$x_coll_ht = 0; -$x_paye_sum = 0; -$x_paye_ht = 0; - -$span=3; -if ($modetax == 0) $span+=2; - -//print ''; - -print ''; -print ''; -print ''; -if ($modetax == 0) -{ - print ''; - print ''; -} -print ''; -print ''; -print ''; -foreach(array_keys($x_coll) as $rate) -{ - $subtot_coll_total_ht = 0; - $subtot_coll_vat = 0; - - if (is_array($x_both[$rate]['coll']['detail'])) - { - $var=true; - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['coll']['detail'] as $index => $fields) + $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; + $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; + $x_both[$my_coll_rate]['paye']['totalht'] = 0; + $x_both[$my_coll_rate]['paye']['vat'] = 0; + $x_both[$my_coll_rate]['coll']['links'] = ''; + $x_both[$my_coll_rate]['coll']['detail'] = array(); + foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) { - $var=!$var; - print ''; - // Ref - print ''; - //Description - print ''; - // Amount line - if ($modetax == 0) - { - print ''; - } - // Payment - $ratiopaymentinvoice=1; - if ($modetax == 0) - { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); - print ''; - } - print ''; - // VAT - print ''; - print ''; - - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; + $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; + $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; + $x_both[$my_coll_rate]['coll']['detail'][] = array( + 'id' =>$x_coll[$my_coll_rate]['facid'][$id], + 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], + 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], + 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], + 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], + 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], + 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], + 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], + 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], + 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], + 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], + 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], + 'link' =>$invoice_customer->getNomUrl(1)); + //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; } } - print ''; - print ''; - print ''; - if ($modetax == 0) - { - print ''; - print ''; - } - print ''; - print ''; - print ''; -} + // tva payed + foreach(array_keys($x_paye) as $my_paye_rate){ + $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; + $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; + if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){ + $x_both[$my_paye_rate]['coll']['totalht'] = 0; + $x_both[$my_paye_rate]['coll']['vat'] = 0; + } + $x_both[$my_paye_rate]['paye']['links'] = ''; + $x_both[$my_paye_rate]['paye']['detail'] = array(); - -print ''; - -//print table headers for this quadri - expenses now -//imprime les en-tete de tables pour ce quadri - maintenant les dépenses -print ''; -print ''; -print ''; -if ($modetax == 0) -{ - print ''; - print ''; -} -print ''; -print ''; -print ''."\n"; -foreach(array_keys($x_paye) as $rate) -{ - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; - - if(is_array($x_both[$rate]['paye']['detail'])) - { - $var=true; - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) + foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) { - $var=!$var; - print ''; - print ''; - print ''; - // Amount line - if ($modetax == 0) - { - print ''; - } - // Payment - $ratiopaymentinvoice=1; - if ($modetax == 0) - { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); - print ''; - } - print ''; - // VAT - print ''; - print ''; - - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; + $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; + $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_rate]['facid'][$id], + 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], + 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], + 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id], + 'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id], + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id], + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1)); + //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; } } - - print ''; - print ''; - print ''; - if ($modetax == 0) + //now we have an array (x_both) indexed by rates for coll and paye + + + //print table headers for this quadri - incomes first + + $x_coll_sum = 0; + $x_coll_ht = 0; + $x_paye_sum = 0; + $x_paye_ht = 0; + + $span=3; + if ($modetax == 0) $span+=2; + + //print ''; + + print ''; + print ''; + print ''; + if ($modetax == 0) { - print ''; - print ''; + print ''; + print ''; } - print ''; - print ''; + print ''; + print ''; print ''; -} + foreach(array_keys($x_coll) as $rate) + { + $subtot_coll_total_ht = 0; + $subtot_coll_vat = 0; -print ''; + if (is_array($x_both[$rate]['coll']['detail'])) + { + $var=true; + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['coll']['detail'] as $index => $fields) + { + $var=!$var; + print ''; + // Ref + print ''; + //Description + print ''; + // Amount line + if ($modetax == 0) + { + print ''; + } + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + print ''; + // VAT + print ''; + print ''; + + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } -print ''; -print ''; -print ''."\n"; -$diff = $x_coll_sum - $x_paye_sum; -print ""; -print ''; -print '\n"; -print "\n"; + print ''; -print ''."\n"; + //print table headers for this quadri - expenses now + //imprime les en-tete de tables pour ce quadri - maintenant les dépenses + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''."\n"; + foreach(array_keys($x_paye) as $rate) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; -$i++; + if(is_array($x_both[$rate]['paye']['detail'])) + { + $var=true; + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) + { + $var=!$var; + print ''; + print ''; + print ''; + // Amount line + if ($modetax == 0) + { + print ''; + } + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + print ''; + // VAT + print ''; + print ''; + + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + print ''; + + print ''; + print ''; + print ''."\n"; + + $diff = $x_coll_sum - $x_paye_sum; + print ""; + print ''; + print '\n"; + print "\n"; + + print ''."\n"; + + $i++; +} echo '
'.$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").''; + $account=new Account($db); + $result=$account->fetch($vatpayment->fk_account); + print $account->getNomUrl(1); + print '
'.$langs->trans("Type").''; + print $vatpayment->fk_type ? $langs->trans("PaymentTypeShort".$vatpayment->fk_type) : $langs->trans("Unknown"); + print "
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'..')
'.$elementcust.''.$productcust.''.$amountcust.''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'.$langs->trans("AmountHTVATRealReceived").''.$vatcust.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; - if ($fields['pid']) - { - $product_static->id=$fields['pid']; - $product_static->ref=$fields['pref']; - $product_static->type=$fields['ptype']; - print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; - } - else - { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; - } - print dolibarr_trunc($fields['descr'],16).''; - print price($fields['totalht']); - if ($fields['ftotal_ttc']) - { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) - { - $payment_static->rowid=$fields['payment_id']; - print $payment_static->getNomUrl(2); - } - print $fields['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; - print ''; - $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - print price(price2num($temp_ht,'MT')); - print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; - print price(price2num($temp_vat,'MT')); - //print price($fields['vat']); - print '
'.$langs->trans("Total").':  '.price(price2num($subtot_coll_total_ht,'MT')).''.price(price2num($subtot_coll_vat,'MT')).'
 
'.$elementsup.''.$productsup.''.$amountsup.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealPayed").''.$vatsup.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; - if ($fields['pid']) - { - $product_static->id=$fields['pid']; - $product_static->ref=$fields['pref']; - $product_static->type=$fields['ptype']; - print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; - } - else - { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; - } - print dolibarr_trunc($fields['descr'],24).''; - print price($fields['totalht']); - if ($fields['ftotal_ttc']) - { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) - { - $paymentfourn_static->rowid=$fields['payment_id']; - print $paymentfourn_static->getNomUrl(2); - } - print $fields['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; - print ''; - $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - print price(price2num($temp_ht,'MT')); - print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; - print price(price2num($temp_vat,'MT')); - //print price($fields['vat']); - print '
 '.$langs->trans("Total").':
'..')
'.$elementcust.''.$productcust.'  '.$amountcust.''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'.price(price2num($subtot_paye_total_ht,'MT')).''.price(price2num($subtot_paye_vat,'MT')).''.$langs->trans("AmountHTVATRealReceived").''.$vatcust.'
 
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) + { + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if ($fields['descr']) print ' - '; + } + else + { + if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '; + } + print dolibarr_trunc($fields['descr'],16).''; + print price($fields['totalht']); + if ($fields['ftotal_ttc']) + { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $payment_static->rowid=$fields['payment_id']; + print $payment_static->getNomUrl(2); + } + print $fields['payment_amount']; + if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + print ''; + $temp_ht=$fields['totalht']; + if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat=$fields['vat']*$ratiopaymentinvoice; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
'.$langs->trans("Total").':  '.price(price2num($subtot_coll_total_ht,'MT')).''.price(price2num($subtot_coll_vat,'MT')).'
'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").' '.$q.':
'.price(price2num($diff,'MT'))."
 
 
'.$elementsup.''.$productsup.''.$amountsup.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealPayed").''.$vatsup.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) + { + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if ($fields['descr']) print ' - '; + } + else + { + if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '; + } + print dolibarr_trunc($fields['descr'],24).''; + print price($fields['totalht']); + if ($fields['ftotal_ttc']) + { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $paymentfourn_static->rowid=$fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + print $fields['payment_amount']; + if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + print ''; + $temp_ht=$fields['totalht']; + if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat=$fields['vat']*$ratiopaymentinvoice; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
 '.$langs->trans("Total").':  '.price(price2num($subtot_paye_total_ht,'MT')).''.price(price2num($subtot_paye_vat,'MT')).'
 
'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").' '.$q.':
'.price(price2num($diff,'MT'))."
 
'; - $db->close(); llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 196e7ea9704..4c4be8b320f 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -15,19 +15,17 @@ * 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$ */ /** \file htdocs/compta/tva/reglement.php \ingroup tax \brief Liste des règlements de TVA effectués - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); $langs->load("compta"); $langs->load("compta"); @@ -35,7 +33,7 @@ $langs->load("compta"); llxHeader(); -$tva = new Tva($db); +$tva_static = new Tva($db); print_titre($langs->trans("VATPayments")); @@ -52,6 +50,7 @@ if ($result) print '
'; print ''; print ''; + print ''; print ''; print ""; print ""; @@ -62,6 +61,10 @@ if ($result) $obj = $db->fetch_object($result); $var=!$var; print ""; + + $tva_static->id=$obj->rowid; + $tva_static->ref=$obj->rowid; + print "\n"; print '\n"; print "\n"; $total = $total + $obj->amount; @@ -71,7 +74,7 @@ if ($result) $i++; } - print ''; + print ''; print ""; print "
'.$langs->trans("Ref").''.$langs->trans("Date").'".$langs->trans("Label")."".$langs->trans("Amount")."
".$tva_static->getNomUrl(1)."'.dolibarr_print_date($obj->dm,'day')."".$obj->label."
'.$langs->trans("Total").'
'.$langs->trans("Total").'".price($total)."
"; diff --git a/htdocs/compta/tva/tva.class.php b/htdocs/compta/tva/tva.class.php new file mode 100644 index 00000000000..d1548d56afe --- /dev/null +++ b/htdocs/compta/tva/tva.class.php @@ -0,0 +1,601 @@ + + * Copyright (C) 2004-2008 Laurent Destailleur + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +/** + \file htdocs/compta/tva/tva.class.php + \ingroup tax + \version $Id$ + \author Laurent Destailleur +*/ + +// Put here all includes required by your class file +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); + + +/** + \class Tva + \brief Put here description of your class + \remarks Initialy built by build_class_from_table on 2008-04-03 21:01 +*/ +class Tva extends CommonObject +{ + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + //var $element='tva'; //!< Id that identify managed objects + //var $table_element='tva'; //!< Name of table without prefix where object is stored + + var $id; + + var $tms; + var $datep; + var $datev; + var $amount; + var $label; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + + + + /** + * \brief Constructor + * \param DB Database handler + */ + function Tva($DB) + { + $this->db = $DB; + return 1; + } + + + /** + * \brief Create in database + * \param user User that create + * \return int <0 si ko, >0 si ok + */ + function create($user) + { + global $conf, $langs; + + // Clean parameters + + $this->amount=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 + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva("; + + $sql.= "tms,"; + $sql.= "datep,"; + $sql.= "datev,"; + $sql.= "amount,"; + $sql.= "label,"; + $sql.= "note,"; + $sql.= "fk_bank,"; + $sql.= "fk_user_creat,"; + $sql.= "fk_user_modif"; + + $sql.= ") VALUES ("; + + $sql.= " ".$this->db->idate($this->tms).","; + $sql.= " ".$this->db->idate($this->datep).","; + $sql.= " ".$this->db->idate($this->datev).","; + $sql.= " '".$this->amount."',"; + $sql.= " '".$this->label."',"; + $sql.= " '".$this->note."',"; + $sql.= " ".($this->fk_bank <= 0 ? "NULL" : "'".$this->fk_bank."'").","; + $sql.= " '".$this->fk_user_creat."',"; + $sql.= " '".$this->fk_user_modif."'"; + + $sql.= ")"; + + dolibarr_syslog("Tva::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + return $this->id; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog("Tva::create ".$this->error, LOG_ERR); + return -1; + } + } + + /* + * \brief Update database + * \param user User that modify + * \param notrigger 0=no, 1=yes (no update trigger) + * \return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + + // Clean parameters + + $this->amount=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 + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET"; + + $sql.= " tms=".$this->db->idate($this->tms).","; + $sql.= " datep=".$this->db->idate($this->datep).","; + $sql.= " datev=".$this->db->idate($this->datev).","; + $sql.= " amount='".$this->amount."',"; + $sql.= " label='".addslashes($this->label)."',"; + $sql.= " note='".addslashes($this->note)."',"; + $sql.= " fk_bank='".$this->fk_bank."',"; + $sql.= " fk_user_creat='".$this->fk_user_creat."',"; + $sql.= " fk_user_modif='".$this->fk_user_modif."'"; + + + $sql.= " WHERE rowid=".$this->id; + + dolibarr_syslog("Tva::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog("Tva::update ".$this->error, LOG_ERR); + return -1; + } + + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + return 1; + } + + + /* + * \brief Load object in memory from database + * \param id id object + * \param user User that load + * \return int <0 if KO, >0 if OK + */ + function fetch($id, $user=0) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " ".$this->db->pdate('t.tms')." as tms,"; + $sql.= " ".$this->db->pdate('t.datep')." as datep,"; + $sql.= " ".$this->db->pdate('t.datev')." as datev,"; + $sql.= " t.amount,"; + $sql.= " t.label,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " b.fk_account,"; + $sql.= " b.fk_type"; + + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; + $sql.= " WHERE t.rowid = ".$id; + + dolibarr_syslog("Tva::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->tms = $obj->tms; + $this->datep = $obj->datep; + $this->datev = $obj->datev; + $this->amount = $obj->amount; + $this->label = $obj->label; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + $this->fk_account = $obj->fk_account; + $this->fk_type = $obj->fk_type; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog("Tva::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + + /* + * \brief Delete object in database + * \param user User that delete + * \return int <0 if KO, >0 if OK + */ + function delete($user) + { + global $conf, $langs; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva"; + $sql.= " WHERE rowid=".$this->id; + + dolibarr_syslog("Tva::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog("Tva::delete ".$this->error, LOG_ERR); + return -1; + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + return 1; + } + + + /** + * \brief Initialise object with example values + * \remarks id must be 0 if object instance is a specimen. + */ + function initAsSpecimen() + { + $this->id=0; + + $this->tms=''; + $this->datep=''; + $this->datev=''; + $this->amount=''; + $this->label=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /* + * \brief Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de TVA, non ? + * + */ + function solde($year = 0) + { + + $reglee = $this->tva_sum_reglee($year); + + $payee = $this->tva_sum_payee($year); + $collectee = $this->tva_sum_collectee($year); + + $solde = $reglee - ($collectee - $payee) ; + + return $solde; + } + + /* + * \brief Total de la TVA des factures emises par la societe. + * + */ + + function tva_sum_collectee($year = 0) + { + + $sql = "SELECT sum(f.tva) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; + + if ($year) + { + $sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result); + return $obj->amount; + } + else + { + return 0; + } + + $this->db->free(); + + } + else + { + print $this->db->error(); + return -1; + } + } + + /* + * \brief Tva payée + * + */ + + function tva_sum_payee($year = 0) + { + + $sql = "SELECT sum(f.total_tva) as total_tva"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + + if ($year) + { + $sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result); + return $obj->total_tva; + } + else + { + return 0; + } + + $this->db->free(); + + } + else + { + print $this->db->error(); + return -1; + } + } + + + /* + * \brief Tva réglée + * Total de la TVA réglee aupres de qui de droit + * + */ + + function tva_sum_reglee($year = 0) + { + + $sql = "SELECT sum(f.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as f"; + + if ($year) + { + $sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result); + return $obj->amount; + } + else + { + return 0; + } + + $this->db->free(); + + } + else + { + print $this->db->error(); + return -1; + } + } + + + /* + * \brief Ajoute un paiement de TVA + * \param user Object user that insert + * \return int <0 if KO, rowid in tva table if OK + */ + function addPayment($user) + { + global $conf,$langs; + + $this->db->begin(); + + // Check parameters + $this->amount=price2num($this->amount); + if (! $this->label) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); + return -3; + } + if ($this->amount <= 0) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); + return -4; + } + if ($conf->banque->enabled && (empty($this->accountid) || $this->accountid < 0)) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account")); + 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"; + $sql.= ") "; + $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; + $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; + if ($this->note) $sql.=", '".addslashes($this->note)."'"; + if ($this->label) $sql.=", '".addslashes($this->label)."'"; + $sql.=", '".$user->id."', NULL"; + $sql.= ")"; + + dolibarr_syslog("Tva::addPayment sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva + if ($this->id > 0) + { + 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); + $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) + { + $this->update_fk_bank($bank_line_id); + } + + // Mise a jour liens (pour chaque charge concernée par le paiement) + //foreach ($paiement->amounts as $key => $value) + //{ + // $chid = $key; + // $fac = new Facture($db); + // $fac->fetch($chid); + // $fac->fetch_client(); + // $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); + // $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; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * \brief Mise a jour du lien entre le paiement tva et la ligne générée dans llx_bank + * \param id_bank Id compte bancaire + * \return int <0 if KO, >0 if OK + */ + function update_fk_bank($id_bank) + { + $sql = 'UPDATE llx_tva set fk_bank = '.$id_bank; + $sql.= ' WHERE rowid = '.$this->id; + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + + /** + \brief Renvoie nom clicable (avec eventuellement le picto) + \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + \param option Sur quoi pointe le lien + \return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + $picto='payment'; + $label=$langs->trans("ShowVatPayment").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; + } + +} +?> diff --git a/htdocs/tva.class.php b/htdocs/tva.class.php deleted file mode 100644 index 63a25529282..00000000000 --- a/htdocs/tva.class.php +++ /dev/null @@ -1,303 +0,0 @@ - - * Copyright (C) 2004-2005 Laurent Destailleur - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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$ - */ - -/** - \file htdocs/tva.class.php - \ingroup compta - \brief Fichier de la classe de tva - \remarks La tva collectée n'est calculée que sur les factures payées. - \version $Revision$ -*/ - - -/** \class Tva - \brief Classe permettant la gestion de la tva -*/ -class Tva -{ - var $db; - var $note; - - /* - * \brief Constructeur - * \param DB Handler d'accès base - */ - function Tva($DB) - { - $this->db = $DB; - - return 1; - } - - /* - * \brief Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de TVA, non ? - * - */ - function solde($year = 0) - { - - $reglee = $this->tva_sum_reglee($year); - - $payee = $this->tva_sum_payee($year); - $collectee = $this->tva_sum_collectee($year); - - $solde = $reglee - ($collectee - $payee) ; - - return $solde; - } - - /* - * \brief Total de la TVA des factures emises par la societe. - * - */ - - function tva_sum_collectee($year = 0) - { - - $sql = "SELECT sum(f.tva) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; - - if ($year) - { - $sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; - } - - $result = $this->db->query($sql); - - if ($result) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object($result); - return $obj->amount; - } - else - { - return 0; - } - - $this->db->free(); - - } - else - { - print $this->db->error(); - return -1; - } - } - - /* - * \brief Tva payée - * - */ - - function tva_sum_payee($year = 0) - { - - $sql = "SELECT sum(f.total_tva) as total_tva"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - - if ($year) - { - $sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; - } - $result = $this->db->query($sql); - - if ($result) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object($result); - return $obj->total_tva; - } - else - { - return 0; - } - - $this->db->free(); - - } - else - { - print $this->db->error(); - return -1; - } - } - - - /* - * \brief Tva réglée - * Total de la TVA réglee aupres de qui de droit - * - */ - - function tva_sum_reglee($year = 0) - { - - $sql = "SELECT sum(f.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as f"; - - if ($year) - { - $sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' "; - } - - $result = $this->db->query($sql); - - if ($result) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object($result); - return $obj->amount; - } - else - { - return 0; - } - - $this->db->free(); - - } - else - { - print $this->db->error(); - return -1; - } - } - - - /* - * \brief Ajoute un paiement de TVA - * \param user Object user that insert - * \return int <0 if KO, rowid in tva table if OK - */ - function addPayment($user) - { - global $conf,$langs; - - $this->db->begin(); - - // Check parameters - $this->amount=price2num($this->amount); - if (! $this->label) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); - return -3; - } - if ($this->amount <= 0) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); - return -4; - } - if ($conf->banque->enabled && ! $this->accountid) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account")); - 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"; - $sql.= ") "; - $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; - $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; - if ($this->note) $sql.=", '".addslashes($this->note)."'"; - if ($this->label) $sql.=", '".addslashes($this->label)."'"; - $sql.=", '".$user->id."'"; - $sql.= ")"; - - $result = $this->db->query($sql); - if ($result) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva - if ($this->id > 0) - { - 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); - $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) - { - $this->update_fk_bank($bank_line_id); - } - - // Mise a jour liens (pour chaque charge concernée par le paiement) - //foreach ($paiement->amounts as $key => $value) - //{ - // $chid = $key; - // $fac = new Facture($db); - // $fac->fetch($chid); - // $fac->fetch_client(); - // $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); - // $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; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -2; - } - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } - - /** - * \brief Mise a jour du lien entre le paiement tva et la ligne générée dans llx_bank - * \param id_bank Id compte bancaire - * \return int <0 if KO, >0 if OK - */ - function update_fk_bank($id_bank) - { - $sql = 'UPDATE llx_tva set fk_bank = '.$id_bank; - $sql.= ' WHERE rowid = '.$this->id; - $result = $this->db->query($sql); - if ($result) - { - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - -} -?> diff --git a/mysql/migration/2.2.0-2.4.0.sql b/mysql/migration/2.2.0-2.4.0.sql index c661867a7ea..8facc488e1b 100644 --- a/mysql/migration/2.2.0-2.4.0.sql +++ b/mysql/migration/2.2.0-2.4.0.sql @@ -240,3 +240,5 @@ insert into llx_c_chargesociales (id, libelle, deductible, active, actioncompta) alter table llx_socpeople add priv smallint NOT NULL DEFAULT 0 after jabberid; +alter table llx_tva modify fk_bank integer; + diff --git a/mysql/tables/llx_tva.sql b/mysql/tables/llx_tva.sql index 5d1f13e4c85..8ca871cf565 100644 --- a/mysql/tables/llx_tva.sql +++ b/mysql/tables/llx_tva.sql @@ -27,7 +27,7 @@ create table llx_tva amount real NOT NULL DEFAULT 0, label varchar(255), note text, - fk_bank integer NOT NULL, + fk_bank integer, fk_user_creat integer, -- utilisateur qui a créé l'info fk_user_modif integer -- utilisateur qui a modifié l'info )type=innodb;