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/dev/translation/erp_comparison_translation.txt b/dev/translation/erp_comparison_translation.txt index fb96c17e3f9..c99a5f4cc1c 100644 --- a/dev/translation/erp_comparison_translation.txt +++ b/dev/translation/erp_comparison_translation.txt @@ -12,3 +12,6 @@ Balance ?? Net profit Subledger account Subledger account ?? +Proposal ?? Quotation Proposal is ok but proposition looks better (proposal is for a detailed proposition). We can say also "business proposition or business proposal". + Indian are using "Quotation". + diff --git a/dev/translation/strip_language_file.php b/dev/translation/strip_language_file.php index 647b571c788..92233d71b98 100755 --- a/dev/translation/strip_language_file.php +++ b/dev/translation/strip_language_file.php @@ -303,6 +303,8 @@ foreach($filesToProcess as $fileToProcess) // ----- Process output now ----- + //print "Found primary key = ".$key."\n"; + // Key not in other file if (in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key)) { @@ -321,7 +323,7 @@ foreach($filesToProcess as $fileToProcess) || in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key) ) { - //print "Key $key differs so we add it into new secondary language (line: $cnt).\n"; + //print "Key $key differs (aSecondary=".$aSecondary[$key].", aPrimary=".$aPrimary[$key].", aEnglish=".$aEnglish[$key].") so we add it into new secondary language (line: $cnt).\n"; fwrite($oh, $key."=".(empty($aSecondary[$key])?$aPrimary[$key]:$aSecondary[$key])."\n"); } } 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/card.php b/htdocs/accountancy/bookkeeping/card.php index 9be65e7261a..c6d84ec9b57 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -2,6 +2,7 @@ /* Copyright (C) 2013-2017 Olivier Geffroy * Copyright (C) 2013-2017 Florian Henry * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2017 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,13 +17,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + /** * \file htdocs/accountancy/bookkeeping/card.php * \ingroup Advanced accountancy * \brief Page to show book-entry */ -require '../../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; @@ -38,7 +40,7 @@ if ($user->societe_id > 0) { accessforbidden(); } $action = GETPOST('action','aZ09'); -$mode = GETPOST('mode'); +$mode = GETPOST('mode','aZ09'); // '' or 'tmp' $piece_num = GETPOST("piece_num"); $mesg = ''; @@ -53,15 +55,18 @@ $label_operation= GETPOST('label_operation'); $debit = price2num(GETPOST('debit')); $credit = price2num(GETPOST('credit')); -$save = GETPOST('save'); -if (! empty($save)) { - $action = 'add'; -} -$update = GETPOST('update'); -if (! empty($update)) { - $action = 'confirm_update'; -} +$save = GETPOST('save','alpha'); +if (! empty($save)) $action = 'add'; +$update = GETPOST('update','alpha'); +if (! empty($update)) $action = 'confirm_update'; + $object = new BookKeeping($db); + + +/* + * Actions + */ + if ($action == "confirm_update") { $error = 0; @@ -98,7 +103,14 @@ if ($action == "confirm_update") { if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } + + $debit = 0; + $credit = 0; + $action = ''; } } @@ -108,7 +120,7 @@ if ($action == "confirm_update") { else if ($action == "add") { $error = 0; - if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { + if (empty($debit) && empty($credit)) { setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); $error ++; } @@ -144,7 +156,14 @@ else if ($action == "add") { if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } + + $debit = 0; + $credit = 0; + $action = ''; } } @@ -172,6 +191,11 @@ else if ($action == "confirm_create") { $book = new BookKeeping($db); + if (! GETPOST('code_journal') || GETPOST('code_journal') == '-1') { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); + $action='create'; + $error++; + } if (! GETPOST('next_num_mvt')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumPiece")), null, 'errors'); @@ -196,7 +220,10 @@ else if ($action == "confirm_create") { if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } $action = 'update'; $id=$book->id; $piece_num = $book->piece_num; @@ -210,39 +237,43 @@ if ($action == 'setdate') { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } $action = ''; } } if ($action == 'setjournal') { $journaldoc = trim(GETPOST('code_journal')); - if (!empty($journaldoc)) { - $journaldoc='\''.$journaldoc.'\''; - } $result = $object->updateByMvt($piece_num,'code_journal',$journaldoc,$mode); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } $action = ''; } } if ($action == 'setdocref') { $refdoc = trim(GETPOST('doc_ref')); - if (!empty($refdoc)) { - $refdoc='\''.$refdoc.'\''; - } - $result = $object->updateByMvt(doc_ref,'code_journal',$refdoc,$mode); + $result = $object->updateByMvt($piece_num,'doc_ref',$refdoc,$mode); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); + if ($mode != '_tmp') + { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + } $action = ''; } } +// Validate transaction if ($action == 'valid') { $result = $object->transformTransaction(0,$piece_num); if ($result < 0) { @@ -253,14 +284,17 @@ if ($action == 'valid') { } } + /* * View */ -llxHeader(); + $html = new Form($db); $formaccounting = new FormAccounting($db); $accountjournal = new AccountingJournal($db); +llxHeader('', $langs->trans("CreateMvts")); + // Confirmation to delete the command if ($action == 'delete') { $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id.'&mode='. $mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'confirm_delete', '', 0, 1); @@ -300,7 +334,7 @@ if ($action == 'create') { print ''; print '' . $langs->trans("Codejournal") . ''; - print '' . $formaccounting->select_journal(GETPOST('code_journal'),'code_journal',0,0,array(),1,1) . ''; + print '' . $formaccounting->select_journal(GETPOST('code_journal'),'code_journal',0,1,array(),1,1) . ''; print ''; print ''; @@ -328,29 +362,45 @@ if ($action == 'create') { if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } + if (! empty($book->piece_num)) { - print load_fiche_titre($langs->trans("UpdateMvts"), '' . $langs->trans('BackToList') . ''); + $backlink = '' . $langs->trans('BackToList') . ''; - dol_fiche_head(); + print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); + $head=array(); + $h=0; + $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$book->piece_num.($mode?'&mode='.$mode:''); + $head[$h][1] = $langs->trans("Transaction"); + $head[$h][2] = 'transaction'; + $h++; + + dol_fiche_head($head, 'transaction', '', -1); + + + //dol_banner_tab($book, '', $backlink); + + + print '
'; print '
'; + print '
'; - print ''; + print '
'; // account movement - print ''; + print ''; print ''; print ''; print ''; // date - print ''; print ''; //journal - print ''; print ''; //docref - print ''; print ''; - //doctype - print ''; - print ''; - print ''; - print ''; + print '
' . $langs->trans("NumMvts") . '' . $book->piece_num . '
'; + print '
'; print ''; if ($action != 'editdate') - print 'piece_num .'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('SetDate'),1).''; + print ''; print '
'; print $langs->trans('Docdate'); print 'piece_num .'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('SetDate'),1).'
'; print '
'; if ($action == 'editdate') { @@ -361,18 +411,18 @@ if ($action == 'create') { $form->select_date($book->doc_date ? $book->doc_date : - 1, 'doc_date', '', '', '', "setdate"); print ''; print ''; - } else { - print $book->doc_date ? dol_print_date($book->doc_date, 'daytext') : ' '; + } else { + print $book->doc_date ? dol_print_date($book->doc_date, 'daytext') : ' '; } print '
'; + print '
'; print ''; if ($action != 'editjournal') - print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).''; + print ''; print '
'; print $langs->trans('Codejournal'); print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'
'; print '
'; if ($action == 'editjournal') { @@ -389,12 +439,12 @@ if ($action == 'create') { print '
'; + print '
'; print ''; if ($action != 'editdocref') - print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).''; + print ''; print '
'; print $langs->trans('Docref'); print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'
'; print '
'; if ($action == 'editdocref') { @@ -410,21 +460,25 @@ if ($action == 'create') { } print '
' . $langs->trans("Doctype") . '' . $book->doc_type . '
'; print '
'; print '
'; + print '
'; print ''; + // Doc type + print ''; + print ''; + print ''; + print ''; + // Validate - print ''; + /* + print ''; print ''; print ''; print ''; + */ + // check data - print ''; - print ''; /* + print ''; + print ''; if ($book->doc_type == 'customer_invoice') { $sqlmid = 'SELECT rowid as ref'; @@ -457,14 +513,19 @@ if ($action == 'create') { } else dol_print_error($db); } - */ print ''; + print ''; + */ print "
' . $langs->trans("Doctype") . '' . $book->doc_type . '
' . $langs->trans("Status") . ''; if (empty($book->validated)) { @@ -438,10 +492,12 @@ if ($action == 'create') { } print '
' . $langs->trans("Control") . '
' . $langs->trans("Control") . '' . $ref .'
\n"; - print '
'; + print '
'; + print ''; + print '
'; + print '
'; + $result = $book->fetchAllPerMvt($piece_num, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -490,11 +551,11 @@ if ($action == 'create') { print ''; print_liste_field_titre($langs->trans("AccountAccountingShort")); - print_liste_field_titre($langs->trans("Subledger_account")); + print_liste_field_titre($langs->trans("SubledgerAccount")); print_liste_field_titre($langs->trans("Labelcompte")); - print_liste_field_titre($langs->trans("Labeloperation")); - print_liste_field_titre($langs->trans("Debit"), "", "", "", "", 'align="center"'); - print_liste_field_titre($langs->trans("Credit"), "", "", "", "", 'align="center"'); + print_liste_field_titre($langs->trans("Label")); + print_liste_field_titre($langs->trans("Debit"), "", "", "", "", 'align="right"'); + print_liste_field_titre($langs->trans("Credit"), "", "", "", "", 'align="right"'); print_liste_field_titre($langs->trans("Action"), "", "", "", "", 'width="60" align="center"'); print "\n"; @@ -509,7 +570,16 @@ if ($action == 'create') { print $formaccounting->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, ''); print ''; print ''; - print $formaccounting->select_auxaccount($line->subledger_account, 'subledger_account', 1); + // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not + // use setup of keypress to select thirdparty and this hang browser on large database. + if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) + { + print $formaccounting->select_auxaccount($line->subledger_account, 'subledger_account', 1); + } + else + { + print ''; + } print ''; print ''; print ''; @@ -528,10 +598,14 @@ if ($action == 'create') { print '' . price($line->credit) . ''; print ''; - print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; + print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; print img_edit(); - print ' '; - print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; + print '  '; + + $actiontodelete='detele'; + if ($mode == '_tmp') $actiontodelete='confirm_delete'; + + print ''; print img_delete(); print ''; @@ -551,19 +625,37 @@ if ($action == 'create') { print $formaccounting->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); print ''; print ''; - print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1); + // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not + // use setup of keypress to select thirdparty and this hang browser on large database. + if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) + { + print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1); + } + else + { + print ''; + } print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; } print ''; - if ($mode=='_tmp' && $total_debit == $total_credit && $action=='') { + + if ($mode=='_tmp' && $action=='') + { print '
'; - print ''.$langs->trans("ValidTransaction").''; + if ($total_debit == $total_credit) + { + print ''.$langs->trans("ValidTransaction").''; + } + else + { + print ''.$langs->trans("ValidTransaction").''; + } print "
"; } print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 6f994eb1110..114b765e658 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -399,11 +399,29 @@ print ''; print ''; print '
'; print $langs->trans('From'); -print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); +// TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not +// use setup of keypress to select thirdparty and this hang browser on large database. +if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) +{ + print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); +} +else +{ + print ''; +} print '
'; print '
'; print $langs->trans('to'); -print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); +// TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not +// use setup of keypress to select thirdparty and this hang browser on large database. +if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) +{ + print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); +} +else +{ + print ''; +} print '
'; print ''; print ''; 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/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 51ef317e917..5c5fb022de9 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -430,6 +430,9 @@ class BookKeeping extends CommonObject if (empty($this->debit)) $this->debit = 0; if (empty($this->credit)) $this->credit = 0; + $this->debit = price2num($this->debit, 'MT'); + $this->credit = price2num($this->credit, 'MT'); + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; @@ -609,6 +612,7 @@ class BookKeeping extends CommonObject } } + /** * Load object in memory from the database * @@ -998,6 +1002,9 @@ class BookKeeping extends CommonObject $this->piece_num = trim($this->piece_num); } + $this->debit = price2num($this->debit, 'MT'); + $this->credit = price2num($this->credit, 'MT'); + // Check parameters // Put here code to add a control on parameters values @@ -1068,9 +1075,10 @@ class BookKeeping extends CommonObject public function updateByMvt($piece_num='', $field='', $value='', $mode='') { $this->db->begin(); $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . $mode . " as ab"; - $sql .= ' SET ab.' . $field . '=' . $value; + $sql .= ' SET ab.' . $field . '=' . (is_numeric($value)?$value:"'".$value."'"); $sql .= ' WHERE ab.piece_num=' . $piece_num ; $resql = $this->db->query($sql); + if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); @@ -1093,7 +1101,6 @@ class BookKeeping extends CommonObject * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers * @param string $mode Mode - * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false, $mode='') { @@ -1576,6 +1583,7 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } + /* $sql = "DELETE FROM "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; @@ -1584,6 +1592,7 @@ class BookKeeping extends CommonObject $sql .= " AND asy.rowid = " . $pcgver; $sql .= " AND ab.entity IN (" . getEntity('accountancy') . ")"; $sql .= " ORDER BY account_number ASC"; + */ } /** @@ -1761,4 +1770,4 @@ class BookKeepingLine public $code_journal; public $journal_label; public $piece_num; -} \ No newline at end of file +} diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php new file mode 100644 index 00000000000..70d7a88c55b --- /dev/null +++ b/htdocs/accountancy/class/lettering.class.php @@ -0,0 +1,330 @@ + + * 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 +{ + /** + * lettrageTiers + * + * @param int $socid Thirdparty id + * @return void + */ + 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') {