diff --git a/dev/resources/iso-normes/sample_FEC_file.txt b/dev/resources/iso-normes/sample_FEC_file.txt index 5ca795af5c2..8ca50c92617 100644 --- a/dev/resources/iso-normes/sample_FEC_file.txt +++ b/dev/resources/iso-normes/sample_FEC_file.txt @@ -1,4 +1,4 @@ -JOURNALCODE JOURNALLIB ECRITURENUM ECRITUREDATE COMPTENUM COMPTELIB COMPAUXNUM COMPAUXLIB PIECEREF PIECEDATE ECRITURELIB DEBIT CREDIT ECRITURELET DATELET VALIDDATE MONTANTDEVISE IDEVISE +JOURNALCODE JOURNALLIB ECRITURENUM ECRITUREDATE COMPTENUM COMPTELIB COMPAUXNUM COMPAUXLIB PIECEREF PIECEDATE ECRITURELIB DEBIT CREDIT ECRITURELET DATELET VALIDDATE MONTANTDEVISE IDEVISE Banque Banque 17293 20170109 401PPRO PUBLI-PROV L08 20170109 PPRO domiciliation 1TR 187,20 0,00 20170109 Banque Banque 17293 20170109 5121CRA CR AGRICOLE L08 20170109 PPRO domiciliation 1TR 0,00 187,20 20170109 Banque Banque 17295 20170109 401ORPA ORANGE PARIS Report 20170109 ORPA adsl par 12 96,00 0,00 20170109 diff --git a/dev/tools/rmphpclosingtag.sh b/dev/tools/rmphpclosingtag.sh deleted file mode 100755 index ec755bc399b..00000000000 --- a/dev/tools/rmphpclosingtag.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# vim:ft=sh:ts=3:sts=3:sw=3:et: - -### -# Strips the closing php tag `?>` and any following blank lines from the -# end of any PHP file in the current working directory and sub-directories. Files -# with non-whitespace characters following the closing tag will not be affected. -# -# Author: Bryan C. Geraghty -# Date: 2009-10-28 -# Source: http://bryan.ravensight.org/2010/07/remove-php-closing-tag/ -## - -FILES=$(pcregrep -rnM --include='^.*\.php$' '^\?\>(?=([\s\n]+)?$(?!\n))' .); - -for MATCH in $FILES; -do - FILE=`echo $MATCH | awk -F ':' '{print $1}'`; - TARGET=`echo $MATCH | awk -F ':' '{print $2}'`; - LINE_COUNT=`wc -l $FILE | awk -F " " '{print $1}'`; - echo "Removing lines ${TARGET} through ${LINE_COUNT} from file $FILE..."; - sed -i "${TARGET},${LINE_COUNT}d" $FILE; -done; diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php index fd8c67246f4..f9200a575be 100644 --- a/htdocs/accountancy/admin/categories.php +++ b/htdocs/accountancy/admin/categories.php @@ -46,7 +46,7 @@ if ($cat_id == 0) { } // Security check -if (! empty($user->rights->accountancy->chartofaccount)) +if (empty($user->rights->accounting->chartofaccount)) { accessforbidden(); } @@ -104,7 +104,7 @@ $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0 print ''; print ''; -if (! empty($cat_id)) +if (! empty($cat_id)) { $return = $accountingcategory->getAccountsWithNoCategory($cat_id); if ($return < 0) { @@ -164,4 +164,4 @@ if ($action == 'display' || $action == 'delete') { llxFooter(); -$db->close(); \ No newline at end of file +$db->close(); diff --git a/htdocs/accountancy/admin/categories_list.php b/htdocs/accountancy/admin/categories_list.php index cb852d82e0c..270d882eac7 100644 --- a/htdocs/accountancy/admin/categories_list.php +++ b/htdocs/accountancy/admin/categories_list.php @@ -57,7 +57,7 @@ $rowid=GETPOST('rowid','alpha'); $code=GETPOST('code','alpha'); // Security access -if (! empty($user->rights->accountancy->chartofaccount)) +if (empty($user->rights->accounting->chartofaccount)) { accessforbidden(); } diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php index 9cf4d2977fd..ce99bd6296c 100644 --- a/htdocs/accountancy/admin/defaultaccounts.php +++ b/htdocs/accountancy/admin/defaultaccounts.php @@ -42,7 +42,7 @@ $langs->load("salaries"); $langs->load("loan"); // Security check -if (! empty($user->rights->accountancy->chartofaccount)) +if (empty($user->rights->accounting->chartofaccount)) { accessforbidden(); } diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php index 7a209be45b1..433448fa688 100644 --- a/htdocs/accountancy/admin/export.php +++ b/htdocs/accountancy/admin/export.php @@ -38,7 +38,7 @@ $langs->load("admin"); $langs->load("accountancy"); // Security check -if (empty($user->admin) || ! empty($user->rights->accountancy->chartofaccount)) +if (empty($user->admin) && empty($user->rights->accounting->chartofaccount)) { accessforbidden(); } diff --git a/htdocs/accountancy/admin/fiscalyear_card.php b/htdocs/accountancy/admin/fiscalyear_card.php index 7a8ab0673a7..fa817942a54 100644 --- a/htdocs/accountancy/admin/fiscalyear_card.php +++ b/htdocs/accountancy/admin/fiscalyear_card.php @@ -43,10 +43,10 @@ $id = GETPOST('id', 'int'); // List of statut static $tmpstatut2label = array ( '0' => 'OpenFiscalYear', - '1' => 'CloseFiscalYear' + '1' => 'CloseFiscalYear' ); $statut2label = array ( - '' + '' ); foreach ( $tmpstatut2label as $key => $val ) $statut2label[$key] = $langs->trans($val); @@ -69,7 +69,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") { } else { setEventMessages($object->error, $object->errors, 'errors'); } -} +} else if ($action == 'add') { if (! GETPOST('cancel', 'alpha')) { @@ -113,7 +113,7 @@ else if ($action == 'add') { header("Location: ./fiscalyear.php"); exit(); } -} +} // Update record else if ($action == 'update') { @@ -126,7 +126,7 @@ else if ($action == 'update') { $object->statut = GETPOST('statut', 'int'); $result = $object->update($user); - + if ($result > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit(); @@ -151,7 +151,7 @@ llxHeader("",$title,$helpurl); $form = new Form($db); -if ($action == 'create') +if ($action == 'create') { print load_fiche_titre($langs->trans("NewFiscalYear")); @@ -184,7 +184,7 @@ if ($action == 'create') print $form->selectarray('statut', $statut2label, GETPOST('statut')); print ''; */ - + print ''; dol_fiche_end(); @@ -306,9 +306,9 @@ if ($action == 'create') print '
'; print '' . $langs->trans('Modify') . ''; - + // print '' . $langs->trans('Delete') . ''; - + print '
'; } } diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index ead997a5d8c..b6aceb52ad4 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -266,7 +266,7 @@ if (! empty($user->admin)) } -// Param a user $user->rights->accountancy->chartofaccount can access +// Param a user $user->rights->accounting->chartofaccount can access foreach ($list as $key) { print ''; diff --git a/htdocs/accountancy/admin/journals_list.php b/htdocs/accountancy/admin/journals_list.php index dca29fd28b8..a3912aebc89 100644 --- a/htdocs/accountancy/admin/journals_list.php +++ b/htdocs/accountancy/admin/journals_list.php @@ -41,7 +41,7 @@ $rowid=GETPOST('rowid','alpha'); $code=GETPOST('code','alpha'); // Security access -if (! empty($user->rights->accountancy->chartofaccount)) +if (empty($user->rights->accounting->chartofaccount)) { accessforbidden(); } @@ -134,6 +134,7 @@ $elementList = array(); '2' => $langs->trans('AccountingJournalType2'), '3' => $langs->trans('AccountingJournalType3'), '4' => $langs->trans('AccountingJournalType4'), + '5' => $langs->trans('AccountingJournalType5'), '9' => $langs->trans('AccountingJournalType9') ); @@ -743,4 +744,4 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') print ''; } } -} \ No newline at end of file +} diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php new file mode 100644 index 00000000000..cddeff27651 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php @@ -0,0 +1,331 @@ + + * Copyright (C) 2005 Laurent Destailleur + * Copyright (C) 2013 Olivier Geffroy + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Alexandre Spangaro + * + * 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 3 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, see . + * + */ + +/** + * \file accounting/bookkeeping/thirdparty_lettrage.php + * \ingroup Accounting Expert + * \brief Onglet de gestion de parametrages des ventilations + */ + +require '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; +require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; + +$action=GETPOST('action','aZ09'); +$massaction=GETPOST('massaction','alpha'); +$show_files=GETPOST('show_files','int'); +$confirm=GETPOST('confirm','alpha'); +$toselect = GETPOST('toselect', 'array'); + +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if ($sortorder == "") $sortorder = "ASC"; +if ($sortfield == "") $sortfield = "bk.rowid"; + +$search_year = GETPOST ( "search_year" ); + +// Security check +$socid = GETPOST("socid",'int'); +// if ($user->societe_id) $socid=$user->societe_id; + +$object = new Societe($db); +$object->id = $socid; +$object->fetch($socid); + + +$form = new Form($db); +$BookKeeping = new lettering($db); +$formaccounting = new FormAccounting($db); + + +/* + * Action + */ + +if ($action == 'lettering') { + + $result = $BookKeeping->updatelettrage($_POST['ids']); + +// var_dump($result); + if( $result < 0 ){ + setEventMessages('', $BookKeeping->errors, 'errors' ); + $error++; + + } +} + +if ($action == 'autolettrage') { + + $result = $BookKeeping->LettrageTiers($socid); + + if( $result < 0 ){ + setEventMessages('', $BookKeeping->errors, 'errors' ); + $error++; + + } + +} + + +llxHeader ( '', 'Compta - Grand Livre' ); + + + /* + * Affichage onglets + */ + $head = societe_prepare_head($object); + + dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); + + dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); + + + + + print ''; + print ''; + + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + + + print ''; + print ''; + print ''; + + $langs->load('compta'); + print ''; + print ''; + print ''; + + + // Address + print ''; + + // Zip / Town + print ''; + print ''; + + // Country + print ''; + + print '
'.$langs->trans("ThirdPartyName").''; + $object->next_prev_filter="te.fournisseur = 1"; + print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); + print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans("CustomerCode"). ''; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + print '
'; + print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); + print ''; + print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); + print '
'.$langs->trans("Address").''; + dol_print_address($object->address,'gmap','thirdparty',$object->id); + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'
'.$langs->trans("Country").''; + //$img=picto_from_langcode($object->country_code); + $img=''; + if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); + else print ($img?$img.' ':'').$object->country; + print '
'; + + + + + + $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE (bk.code_tiers = '" . $object->code_compta . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER. "' )" ; + + + + if (dol_strlen ( $search_year )) { + $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; + } + + + $sql .= " ORDER BY bk.lettering_code ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); + +// echo $sql; +// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); + $resql = $db->query ( $sql ); + if ($resql) { + $num = $db->num_rows ( $resql ); + $i = 0; + + + print '
'; + print ''; + print ''; + + print ""; + print ''; + print ''; + print_liste_field_titre ( $langs->trans ( "Doctype" ), "liste.php", "bk.doc_type" ); + print_liste_field_titre ( $langs->trans ( "Docdate" ), "liste.php", "bk.doc_date" ); + print_liste_field_titre ( $langs->trans ( "Docref" ), "liste.php", "bk.doc_ref" ); +// print_liste_field_titre ( $langs->trans ( "Numerocompte" ), "liste.php", "bk.numero_compte" ); +// print_liste_field_titre ( $langs->trans ( "Code_tiers" ), "liste.php", "bk.code_tiers" ); + print_liste_field_titre ( $langs->trans ( "Labelcompte" ), "liste.php", "bk_label_compte" ); + print_liste_field_titre ( $langs->trans ( "Debit" ), "liste.php", "bk.debit" ); + print_liste_field_titre ( $langs->trans ( "Credit" ), "liste.php", "bk.credit" ); +// print_liste_field_titre ( $langs->trans ( "Amount" ), "liste.php", "bk.montant" ); +// print_liste_field_titre ( $langs->trans ( "Sens" ), "liste.php", "bk.sens" ); + print_liste_field_titre ( $langs->trans ( "Codejournal" ), "liste.php", "bk.code_journal" ); + print ''; + print ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var = false; + + $debit = 0; + $credit = 0; + $solde = 0; + $tmp = ''; + while ( $i < $num ) { + $obj = $db->fetch_object ( $resql ); + + if($tmp !=$obj->lettering_code || empty($tmp) ) + $tmp =$obj->lettering_code; + + if($tmp !=$obj->lettering_code || empty($obj->lettering_code)) + $var = ! $var; + + + $debit+= $obj->debit; + $credit+= $obj->credit; + + $solde+=($obj->credit-$obj->debit); + print ""; + + print ''; + if(empty($obj->lettering_code)){ + print '' . "\n"; + } + else + print '' . "\n"; + + + + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + + if(empty($obj->lettering_code)){ + print ''; + } + else + print ''; + + print "\n"; + + $i ++; + + + + + } + + print ''; + + print '' . "\n"; + print ''; + // print ''; + // print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + print ""; + print '' . "\n"; + // print ''; + // print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + print "
     '; + print ''; + print '   
' . $obj->rowid . ''; + print img_edit (); + print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering_code . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; + + print ''; + print 'auto lettering'; + print ""; + $db->free($resql); + } else { + dol_print_error($db); + } + + +// End of page +llxFooter(); +$db->close(); + diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php new file mode 100644 index 00000000000..7dfb7067a31 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php @@ -0,0 +1,335 @@ + + * Copyright (C) 2005 Laurent Destailleur + * Copyright (C) 2013 Olivier Geffroy + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Alexandre Spangaro + * + * 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 3 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, see . + * + */ + +/** + * \file accounting/bookkeeping/thirdparty_lettrage.php + * \ingroup Accounting Expert + * \brief Onglet de gestion de parametrages des ventilations + */ + +// Dolibarr environment +require '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; +require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; + + +$action=GETPOST('action','aZ09'); +$massaction=GETPOST('massaction','alpha'); +$show_files=GETPOST('show_files','int'); +$confirm=GETPOST('confirm','alpha'); +$toselect = GETPOST('toselect', 'array'); + +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if ($sortorder == "") $sortorder = "ASC"; +if ($sortfield == "") $sortfield = "bk.rowid"; + +$search_year = GETPOST ( "search_year" ); + + +// Security check +$socid = GETPOST("socid",'int'); +// if ($user->societe_id) $socid=$user->societe_id; + +$object = new Societe($db); +$object->id = $socid; +$object->fetch($socid); + +$form = new Form($db); +$BookKeeping = new lettering($db); +$formaccounting = new FormAccounting($db); + + +/* + * Action + */ +if ($action == 'lettering') { + + $result = $BookKeeping->updatelettrage($_POST['ids']); + +// var_dump($result); + if( $result < 0 ){ + setEventMessages('', $BookKeeping->errors, 'errors' ); + $error++; + + } +} + +if ($action == 'autolettrage') { + + $result = $BookKeeping->LettrageTiers($socid); + + if( $result < 0 ){ + setEventMessages('', $BookKeeping->errors, 'errors' ); + $error++; + + } + +} + + +llxHeader ( '', 'Compta - Grand Livre' ); + + + /* + * Affichage onglets + */ + $head = societe_prepare_head($object); + + dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); + + dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); + + + + + print ''; + print ''; + + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + + + print ''; + print ''; + print ''; + + $langs->load('compta'); + print ''; + print ''; + print ''; + + + // Address + print ''; + + // Zip / Town + print ''; + print ''; + + // Country + print ''; + + print '
'.$langs->trans("ThirdPartyName").''; + $object->next_prev_filter="te.fournisseur = 1"; + print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); + print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans("SupplierCode"). ''; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print '
'; + print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); + print ''; + print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); + print '
'.$langs->trans("Address").''; + dol_print_address($object->address,'gmap','thirdparty',$object->id); + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'
'.$langs->trans("Country").''; + //$img=picto_from_langcode($object->country_code); + $img=''; + if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); + else print ($img?$img.' ':'').$object->country; + print '
'; + +// print_r($soc); +// exit; +// [code_compta] => 411DOUA +// [code_compta_fournisseur] => 401SUPPCODE + +/* + * Mode Liste + * + * + * + */ + + $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE (bk.code_tiers = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER. "' )" ; + + + + if (dol_strlen ( $search_year )) { + $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; + } + + + $sql .= " ORDER BY bk.lettering ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); + +// echo $sql; +// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); + $resql = $db->query ( $sql ); + if ($resql) { + $num = $db->num_rows ( $resql ); + $i = 0; + + + print '
'; + print ''; + print ''; + + print ""; + print ''; + print ''; + print_liste_field_titre ( $langs->trans ( "Doctype" ), "liste.php", "bk.doc_type" ); + print_liste_field_titre ( $langs->trans ( "Docdate" ), "liste.php", "bk.doc_date" ); + print_liste_field_titre ( $langs->trans ( "Docref" ), "liste.php", "bk.doc_ref" ); +// print_liste_field_titre ( $langs->trans ( "Numerocompte" ), "liste.php", "bk.numero_compte" ); +// print_liste_field_titre ( $langs->trans ( "Code_tiers" ), "liste.php", "bk.code_tiers" ); + print_liste_field_titre ( $langs->trans ( "Labelcompte" ), "liste.php", "bk_label_compte" ); + print_liste_field_titre ( $langs->trans ( "Debit" ), "liste.php", "bk.debit" ); + print_liste_field_titre ( $langs->trans ( "Credit" ), "liste.php", "bk.credit" ); + print_liste_field_titre ( $langs->trans ( "Amount" ), "liste.php", "bk.montant" ); + print_liste_field_titre ( $langs->trans ( "Sens" ), "liste.php", "bk.sens" ); + print_liste_field_titre ( $langs->trans ( "Codejournal" ), "liste.php", "bk.code_journal" ); + print ''; + print ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var = false; + + $debit = 0; + $credit = 0; + $solde = 0; + $tmp = ''; + while ( $i < $num ) { + $obj = $db->fetch_object ( $resql ); + + if($tmp !=$obj->lettering || empty($tmp) ) + $tmp =$obj->lettering; + + if($tmp !=$obj->lettering || empty($obj->lettering)) + $var = ! $var; + + + $debit+= $obj->debit; + $credit+= $obj->credit; + + $solde+=($obj->credit-$obj->debit); + print ""; + + print ''; + if(empty($obj->lettering)){ + print '' . "\n"; + } + else + print '' . "\n"; + + + + print ''; + print ''; +// print ''; +// print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if(empty($obj->lettering)){ + print ''; + } + else + print ''; + + print "\n"; + + $i ++; + } + + print ''; + + print '' . "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + print ""; + print '' . "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + print "
     '; + print ''; + print '   
' . $obj->rowid . ''; + print img_edit (); + print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; + + print ''; + print 'auto lettering'; + print ""; + $db->free ( $resql ); + } else { + dol_print_error ( $db ); + } + + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 66f72ea9bf6..a7bab16b30d 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -539,8 +539,9 @@ class AccountancyCategory /** * get cpts of category * - * @param int $cat_id Category id - * @return array Result in table + * @param int $cat_id Id accounting account category + * + * @return array Result in table */ public function getCptsCat($cat_id) { global $mysoc; diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php new file mode 100644 index 00000000000..f6101f2ccf4 --- /dev/null +++ b/htdocs/accountancy/class/lettering.class.php @@ -0,0 +1,324 @@ + + * Copyright (C) 2013 Olivier Geffroy + * Copyright (C) 2013 Alexandre Spangaro + * + * 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, see . + */ + +/** + * \file accountancy/class/bookkeeping.class.php + * \ingroup Accounting Expert + * \brief Fichier de la classe des comptes comptable + */ + +include_once DOL_DOCUMENT_ROOT."/accountancy/class/bookkeeping.class.php"; +include_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"; +include_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"; + + +/** + * Class lettering + */ +class lettering extends BookKeeping { + + public function LettrageTiers($socid){ + + $db = $this->db; + + $object = new Societe($this->db); + $object->id = $socid; + $object->fetch($socid); + + + if( $object->code_compta == '411CUSTCODE') + $object->code_compta = ''; + + if( $object->code_compta_fournisseur == '401SUPPCODE') + $object->code_compta_fournisseur = ''; + + + + $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.lettering_code, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE code_journal = 'BQ' AND ( "; + if(!empty($object->code_compta) ) + $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; + if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " OR "; + if(!empty($object->code_compta_fournisseur) ) + $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + + $sql .= " ) AND ( bk.date_lettering ='' OR bk.date_lettering IS NULL ) AND bk.lettering_code !='' "; + + $sql .= " GROUP BY bk.lettering_code "; + + + $resql = $db->query ( $sql ); + if ($resql) { + $num = $db->num_rows ( $resql ); + $i = 0; + + while ( $i < $num ) { + $obj = $db->fetch_object ( $resql ); + $i++; + + $sql = "SELECT bk.rowid "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE bk.lettering_code = '".$obj->lettering_code."' "; + $sql .= " AND ( "; + if(!empty($object->code_compta) ) + $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; + if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " OR "; + if(!empty($object->code_compta_fournisseur) ) + $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + $sql .= " ) "; +// echo $sql; + $resql2 = $db->query ( $sql ); + if ($resql2) { + $num2 = $db->num_rows ( $resql2 ); + $i2 = 0; + $ids = array(); + while ( $i2 < $num2 ) { + $obj2 = $db->fetch_object ( $resql2 ); + $i2++; + $ids[] = $obj2->rowid; + } + + + if(count($ids) > 1 ){ + $result = $this->updatelettrage($ids); + + // var_dump($result); +// if( $result < 0 ){ +// setEventMessages('', $BookKeeping->errors, 'errors' ); +// $error++; +// +// } + } + } + } + } + + + /** + Prise en charge des lettering complexe avec prelevment , virement + */ + $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu ON(bk.fk_doc = bu.fk_bank AND bu.type IN ('payment', 'payment_supplier') ) "; + $sql .= " WHERE code_journal = 'BQ' AND ( "; + if(!empty($object->code_compta) ) + $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; + if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " OR "; + if(!empty($object->code_compta_fournisseur) ) + $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + + $sql .= " ) AND date_lettering ='' "; + $sql .= " GROUP BY bk.lettering_code "; + +// echo $sql; +// + $resql = $db->query ( $sql ); + if ($resql) { + $num = $db->num_rows ( $resql ); + $i = 0; + + while ( $i < $num ) { + $obj = $db->fetch_object ( $resql ); + $ids = array(); + $i++; + + // print_r($obj); + + + + if($obj->type =='payment_supplier' ) { + $ids[] = $obj->rowid; + + $sql= 'SELECT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank '; + $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; + $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; + $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; + $sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.ref) "; + // $sqlmid.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid=facf.fk_soc"; + // $sqlmid.= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement as payc ON payc.id=payf.fk_paiement"; + $sql .= " WHERE 1 "; + $sql .= " AND fk_paiementfourn = '".$obj->url_id."' "; + // $sql .= " AND (bk.numero_compte = '" . $object->code_compta . "' OR bk.numero_compte = '" . $object->code_compta_fournisseur . "') "; + $sql .= " AND ( "; + if(!empty($object->code_compta) ) + $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; + if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " OR "; + if(!empty($object->code_compta_fournisseur) ) + $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + $sql .= " ) "; + // echo $sql; + // exit; + } + elseif($obj->type =='payment' ){ + $ids[] = $obj->rowid; + + $sql= 'SELECT bk.rowid,fac.facnumber , pay.fk_bank '; + $sql.= " FROM " . MAIN_DB_PREFIX . "facture fac "; + $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; + $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; + $sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid) "; + $sql .= " WHERE 1 "; + $sql .= " AND payfac.fk_paiement = '".$obj->url_id."' "; + $sql .= " AND ( "; + if(!empty($object->code_compta) ) + $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; + if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " OR "; + if(!empty($object->code_compta_fournisseur) ) + $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + $sql .= " ) "; + + // echo $sql; + } + + + + $resql2 = $db->query ( $sql ); + if ($resql2) { + $num2 = $db->num_rows ( $resql2 ); + $i2 = 0; + + while ( $i2 < $num2 ) { + $obj2 = $db->fetch_object ( $resql2 ); + $i2++; + $ids[] = $obj2->rowid; + } + + // print_r($ids); + // exit; + if(count($ids) > 1 ){ + $result = $this->updatelettrage($ids); + + // var_dump($result); +// if( $result < 0 ){ +// setEventMessages('', $BookKeeping->errors, 'errors' ); +// $error++; +// +// } + } + + // exit; + } + } + } + + + } + + + public function updatelettrage($ids, $notrigger=false){ + $error = 0; + + $sql = "SELECT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; + $sql .= " lettering_code != '' GROUP BY lettering_code ORDER BY lettering_code DESC limit 1; "; +// echo $sql; + $result = $this->db->query ( $sql ); + if ($result) { + $obj = $this->db->fetch_object ( $result ); + $lettre = (empty($obj->lettering_code)? 'AAA' : $obj->lettering_code ); + if(!empty($obj->lettering_code)) + $lettre++; + } + else{ + $this->errors[] = 'Error'.$this->db->lasterror();; + $error++; + } +// var_dump(__line__, $error); + + $sql = "SELECT SUM(ABS(debit)) as deb, SUM(ABS(credit)) as cred FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; + $sql .= " rowid IN (".implode(',', $ids).") "; + $result = $this->db->query ( $sql ); + if ($result) { + $obj = $this->db->fetch_object ( $result ); +// print_r($obj); + if( !(round(abs($obj->deb),2) === round(abs($obj->cred),2)) ){ +// echo $sql; +// print_r($obj); + $this->errors[] = 'Total not exacts '.round(abs($obj->deb),2).' vs '. round(abs($obj->cred),2); + $error++; + } + } + else{ + $this->errors[] = 'Erreur sql'.$this->db->lasterror();; + $error++; + } + + + // Update request + + $now = dol_now(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; + $sql.= " lettering_code='".$lettre."'"; + $sql.= " , date_lettering = " .$now ; // todo correct date it's false + $sql.= " WHERE rowid IN (".implode(',', $ids).") "; +// echo $sql ; +// +// var_dump(__line__, $error); +// print_r($this->errors); +// exit; + $this->db->begin(); + + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/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; } + //// End call triggers + } + } +// var_dump(__line__, $error); + // Commit or rollback + if ($error) + { +// foreach($this->errors as $errmsg) +// { +// dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); +// $this->error.=($this->error?', '.$errmsg:$errmsg); +// } + $this->db->rollback(); +// echo $this->error; +// var_dump(__line__, $error); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + +} + diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 75c1a59aa30..2663ab1d779 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -189,7 +189,8 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accounta $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version"; $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; $sql .= " AND product_type <= 2"; -$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')"; +$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='' OR p.accountancy_code_sell NOT IN + (SELECT aa.account_number FROM " . MAIN_DB_PREFIX . "accounting_account as aa , " . MAIN_DB_PREFIX . "accounting_system as asy WHERE fk_pcg_version = asy.pcg_version AND asy.rowid ='" . $conf->global->CHARTOFACCOUNTS . "'))"; // Add search filter like if ($search_lineid) { $sql .= natural_search("l.rowid", $search_lineid, 1); diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index ed8d1d7501a..056f3644770 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -75,7 +75,7 @@ $date_endyear = GETPOST('date_endyear'); $in_bookkeeping = GETPOST('in_bookkeeping'); $now = dol_now(); -$action = GETPOST('action','alpha'); +$action = GETPOST('action','aZ09'); // Security check if ($user->societe_id > 0 && empty($id_journal)) @@ -612,7 +612,7 @@ if (! $error && $action == 'writebookkeeping') { } // Export -if ($action == 'export_csv') { +if ($action == 'exportcsv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -760,7 +760,7 @@ if (empty($action) || $action == 'view') {