diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php new file mode 100644 index 00000000000..424aa65eb67 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php @@ -0,0 +1,322 @@ + + * 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'; + +$page = GETPOST ( "page" ); +$sortorder = GETPOST ( "sortorder" ); +$search_year = GETPOST ( "search_year" ); +$sortfield = GETPOST ( "sortfield" ); +$action = GETPOST ( 'action', 'alpha' ); + + +// 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); + +if ($sortorder == "") $sortorder = "ASC"; +if ($sortfield == "") $sortfield = "bk.rowid"; + +$offset = $conf->liste_limit * $page; + +$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..338a4aef0e6 --- /dev/null +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php @@ -0,0 +1,332 @@ + + * 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'; + + +$page = GETPOST ( "page" ); +$sortorder = GETPOST ( "sortorder" ); +$search_year = GETPOST ( "search_year" ); +$sortfield = GETPOST ( "sortfield" ); +$action = GETPOST ( 'action', 'alpha' ); + + +// 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); + +if ($sortorder == "") $sortorder = "ASC"; +if ($sortfield == "") $sortfield = "bk.rowid"; + +$offset = $conf->liste_limit * $page; + +$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/lettering.class.php b/htdocs/accountancy/class/lettering.class.php new file mode 100644 index 00000000000..77e1f897f97 --- /dev/null +++ b/htdocs/accountancy/class/lettering.class.php @@ -0,0 +1,327 @@ + + * 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 + */ +error_reporting(0); + +dol_include_once ( "/accountancy/class/bookkeeping.class.php"); +dol_include_once ( "/societe/class/societe.class.php"); +dol_include_once ( "/core/lib/date.lib.php"); // see if not useless for dol(now) + +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') {