diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 0500ac4a0a7..77c9a4a135e 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -27,6 +27,7 @@ require '../../main.inc.php'; // Class require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; // Langs $langs->load("accountancy"); @@ -41,12 +42,24 @@ $piece_num = GETPOST("piece_num"); $mesg = ''; -$numero_compte = GETPOST('numero_compte'); +$account_number = GETPOST('account_number'); $code_tiers = GETPOST('code_tiers'); +if ($code_tiers==-1) { + $code_tiers=null; +} $label_compte = GETPOST('label_compte'); $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'; +} + if ($action == "confirm_update") { $error = 0; @@ -63,7 +76,7 @@ if ($action == "confirm_update") { if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - $book->numero_compte = $numero_compte; + $book->numero_compte = $account_number; $book->code_tiers = $code_tiers; $book->label_compte = $label_compte; $book->debit = $debit; @@ -92,15 +105,15 @@ if ($action == "confirm_update") { else if ($action == "add") { $error = 0; - if ((intval($debit) != 0) && (intval($credit) != 0)) { - setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); - $error ++; - } + if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { + setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); + $error ++; + } if (empty($error)) { $book = new BookKeeping($db); - $book->numero_compte = $numero_compte; + $book->numero_compte = $account_number; $book->code_tiers = $code_tiers; $book->label_compte = $label_compte; $book->debit = $debit; @@ -113,11 +126,12 @@ else if ($action == "add") { $book->fk_doc = GETPOST('fk_doc'); $book->fk_docdet = GETPOST('fk_docdet'); - if (! empty($debit)) { + if (floatval($debit) != 0.0) { $book->montant = $debit; $book->sens = 'D'; } - if (! empty($credit)) { + + if (floatval($credit) != 0.0) { $book->montant = $credit; $book->sens = 'C'; } @@ -179,6 +193,7 @@ else if ($action == "confirm_create") { llxHeader(); $html = new Form($db); +$formventilation = new FormVentilation($db); /* * Confirmation to delete the command @@ -281,9 +296,21 @@ if ($action == 'create') { } else { print load_fiche_titre($langs->trans("ListeMvts")); + + print '
'; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print ""; if (count($book->linesmvt) > 0) { + $total_debit=0; + $total_credit=0; + print ''; print_liste_field_titre($langs->trans("Numerocompte")); @@ -301,21 +328,26 @@ if ($action == 'create') { $var = ! $var; print ""; + $total_debit+=$line->debit; + $total_credit+=$line->credit; + if ($action == 'update' && $line->id == $id) { - print ''; - print '' . "\n"; - print '' . "\n"; - print ''; - print ''; + + print ''; + print ''; print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''; @@ -327,10 +359,10 @@ if ($action == 'create') { print ''; print '\n"; } + if ($total_debit!=$total_credit) { + setEventMessages(null, array('MvtNotCorrectlyBalanced',$total_credit,$total_debit),'errors'); + } + if ($action == "" || $action == 'add') { $var = ! $var; print ""; - - print ''; - print '' . "\n"; - print '' . "\n"; - print '' . "\n"; - print '' . "\n"; - print '' . "\n"; - print '' . "\n"; - print '' . "\n"; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; } print '
'; + print $formventilation->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1,''); + print ''; + print $formventilation->select_auxaccount($line->code_tiers, 'code_tiers',1); + print '' . $line->montant . '' . $line->sens . ''; - print ''; - print ''; + print '' . "\n"; + print ''; print '' . $line->numero_compte . '' . $line->sens . ''; - print ''; + print ''; print img_edit(); print ' '; - print ''; + print ''; print img_delete(); print ''; @@ -339,34 +371,32 @@ if ($action == 'create') { print "
'; + print $formventilation->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); + print ''; + print $formventilation->select_auxaccount($code_tiers, 'code_tiers',1); + print '
'; print ''; } } - } - else { + } else { print load_fiche_titre($langs->trans("NoRecords")); } } diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 951a07d3171..84c0661825d 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -19,18 +19,17 @@ */ /** - * \file htdocs/accountancy/bookkeeping/list.php - * \ingroup Accounting Expert - * \brief List operation of book keeping + * \file htdocs/accountancy/bookkeeping/list.php + * \ingroup Accounting Expert + * \brief List operation of book keeping */ - require '../../main.inc.php'; - + // Class -require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; -require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; // Langs $langs->load("accountancy"); @@ -58,11 +57,11 @@ $formother = new FormOther($db); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { - $search_doc_type=""; - $search_doc_ref=""; - $search_account=""; - $search_thirdparty=""; - $search_journal=""; + $search_piece_num = ""; + $search_doc_ref = ""; + $search_account = ""; + $search_thirdparty = ""; + $search_journal = ""; } /* @@ -80,8 +79,7 @@ if ($action == 'delbookkeeping') { setEventMessages($object->error, $object->errors, 'errors'); } } -} -elseif ($action == 'delbookkeepingyear') { +} elseif ($action == 'delbookkeepingyear') { $delyear = GETPOST('delyear', 'int'); @@ -93,8 +91,7 @@ elseif ($action == 'delbookkeepingyear') { setEventMessages($object->error, $object->errors, 'errors'); } } -} -elseif ($action == 'delbookkeepingyear') { +} elseif ($action == 'delbookkeepingyear') { $delyear = GETPOST('delyear', 'int'); @@ -106,7 +103,7 @@ elseif ($action == 'delbookkeepingyear') { setEventMessages($object->error, $object->errors, 'errors'); } } -}// Export +} // Export else if ($action == 'export_csv') { header('Content-Type: text/csv'); @@ -118,19 +115,55 @@ else if ($action == 'export_csv') { setEventMessages($object->error, $object->errors, 'errors'); } - foreach ( $object->linesexport as $line ) { - print $line->id . ','; - print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; - print '"' . $line->code_journal . '",'; - print '"' . $line->numero_compte . '",'; - print '"' . substr($line->code_journal, 0, 2) . '",'; - print '"' . substr($line->doc_ref, 0, 40) . '",'; - print '"' . $line->num_piece . '",'; - print '"' . $line->montant . '",'; - print '"' . $line->sens . '",'; - print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; - print '"' . $conf->currency . '",'; - print "\n"; + // Model classic Export + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) { + + foreach ( $object->linesexport as $line ) { + print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; + print '"' . $line->code_journal . '",'; + print '"' . $line->numero_compte . '",'; + print '"' . substr($line->code_journal, 0, 2) . '",'; + print '"' . substr($line->doc_ref, 0, 40) . '",'; + print '"' . $line->num_piece . '",'; + print '"' . $line->debit . '",'; + print '"' . $line->credit . '",'; + print '"' . $conf->currency . '",'; + print "\n"; + } + } + // Model cegid Export + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) { + foreach ( $object->linesexport as $line ) { + print $line->id . ','; + print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; + print '"' . $line->code_journal . '",'; + print '"' . $line->numero_compte . '",'; + print '"' . substr($line->code_journal, 0, 2) . '",'; + print '"' . substr($line->doc_ref, 0, 40) . '",'; + print '"' . $line->num_piece . '",'; + print '"' . $line->montant . '",'; + print '"' . $line->sens . '",'; + print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; + print '"' . $conf->currency . '",'; + print "\n"; + } + } + // Model Coala Export + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 3) { + foreach ( $object->linesexport as $line ) { + print $line->id . ','; + print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; + print '"' . $line->code_journal . '",'; + print '"' . $line->numero_compte . '",'; + print '"' . substr($line->code_journal, 0, 2) . '",'; + print '"' . substr($line->doc_ref, 0, 40) . '",'; + print '"' . $line->num_piece . '",'; + print '"' . $line->montant . '",'; + print '"' . $line->sens . '",'; + print '"' . dol_print_date($line->doc_date, '%d%m%Y') . '",'; + print '"' . $conf->currency . '",'; + print "\n"; + } } } @@ -138,16 +171,16 @@ else { llxHeader('', $langs->trans("Bookkeeping")); -/* - * List - */ + /* + * List + */ $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 "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; if (dol_strlen(trim($search_doc_type))) { - $sql .= " WHERE bk.doc_type LIKE '%" . $search_doc_type . "%'"; + $sql .= " WHERE bk.piece_num LIKE '%" . $search_piece_num . "%'"; if (dol_strlen(trim($search_doc_ref))) { $sql .= " AND bk.doc_ref LIKE '%" . $search_doc_ref . "%'"; @@ -177,20 +210,20 @@ else { print_barre_liste($langs->trans("Bookkeeping"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num); /*print '
'; - print ''; - print ''; - - print $formventilation->select_bookkeeping_importkey('importkey', GETPOST('importkey')); - - print '
'; - - print '
';*/ + print ''; + print ''; + + print $formventilation->select_bookkeeping_importkey('importkey', GETPOST('importkey')); + + print '
'; + + print '';*/ print '
'; print ''; print ''; - print $formother->select_year(GETPOST('delyear'),'delyear'); + print $formother->select_year(GETPOST('delyear'), 'delyear'); print '
'; @@ -204,7 +237,7 @@ else { print ''; print ''; - print_liste_field_titre($langs->trans("Doctype"), $_SERVER['PHP_SELF'], "bk.doc_type", "", "", "", $sortfield, $sortorder); + print_liste_field_titre($langs->trans("NumPiece"), $_SERVER['PHP_SELF'], "bk.piece_num", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "bk.doc_date", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "bk.doc_ref", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "bk.numero_compte", "", "", "", $sortfield, $sortorder); @@ -215,12 +248,12 @@ else { print_liste_field_titre($langs->trans("Amount"), $_SERVER['PHP_SELF'], "bk.montant", "", "", 'align="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Sens"), $_SERVER['PHP_SELF'], "bk.sens", "", "", 'align="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "bk.code_journal", "", "", "", $sortfield, $sortorder); - print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"",$param,"",'width="60" align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $param, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; @@ -232,9 +265,9 @@ else { print ''; print ''; print ''; print ''; print ''; @@ -247,7 +280,16 @@ else { print ""; - print ''; + /* if ($old_piecenum!=$obj->piece_num) { + $total_debit=0; + $total_credit=0; + } else { + $total_debit+=$obj->debit; + $total_credit+=$obj->credit; + } + */ + + print ''; print ''; print ''; print ''; @@ -260,19 +302,23 @@ else { print ''; print ''; print "\n"; + + //$old_piecenum= $obj->piece_num; $i ++; } print "
  '; - print ''; + print ''; print ' '; - print ''; + print ''; print '
' . $obj->doc_type . '' . $obj->piece_num . '' . dol_print_date($db->jdate($obj->doc_date), 'day') . '' . $obj->doc_ref . '' . length_accountg($obj->numero_compte) . '' . $obj->code_journal . '' . img_edit() . '
"; - + print ''; - + $db->free($resql); } else { dol_print_error($db); } + + llxFooter(); } -llxFooter(); + $db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index f92f5b3ab88..5e838fb475f 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -265,4 +265,81 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } + + /** + * Return list of auxilary thirdparty accounts + * + * @param string $selectid Preselected pcg_type + * @param string $htmlname Name of field in html form + * @param int $showempty Add an empty field + * @param array $event Event options + * + * @return string String with HTML select + */ + function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) { + global $conf; + + $out = ''; + + $aux_account = array (); + + // Auxiliary customer account + $sql = "SELECT DISTINCT code_compta, nom "; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; + $sql .= " ORDER BY code_compta"; + dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + while ( $obj = $this->db->fetch_object($resql) ) { + if (! empty($obj->code_compta)) { + $aux_account[$obj->code_compta] = $obj->code_compta . ' (' . $obj->nom . ')'; + } + } + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); + return - 1; + } + $this->db->free($resql); + + // Auxiliary supplier account + $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; + $sql .= " ORDER BY code_compta"; + dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + while ( $obj = $this->db->fetch_object($resql) ) { + if (! empty($obj->code_compta_fournisseur)) { + $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur . ' (' . $obj->nom . ')'; + } + } + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); + return - 1; + } + $this->db->free($resql); + + + //Build select + if (count($aux_account) > 0) { + + $out .= ajax_combobox($htmlname, $event); + + $out .= ''; + } + + return $out; + } } diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 4800737528d..1fd2dd451fc 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -72,7 +72,7 @@ if (! empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)) { $offset = $limit * $page; if (! $sortfield) - $sortfield = "f.facnumber"; + $sortfield = "f.datef, f.facnumber, l.rowid"; if (! $sortorder) { if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) { diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 10dd38807a4..b33becb3f47 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -355,7 +355,7 @@ if ($action == 'writebookkeeping') $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->doc_type = 'banque'; + $bookkeeping->doc_type = 'bank'; $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_bank"]; $bookkeeping->label_compte = $tabcompany[$key]['name']; @@ -675,6 +675,7 @@ else print ""; + llxFooter(); } -llxFooter(); + $db->close(); diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index b603c1863bb..2346df27c77 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -5,7 +5,7 @@ * Copyright (C) 2012 Regis Houssin * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2013-2014 Olivier Geffroy - * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2016 Florian Henry * * 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 @@ -487,7 +487,9 @@ if ($action == 'export_csv') } print ""; - + + // End of page + llxFooter(); } -llxFooter(); + $db->close(); diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 51f4766cc18..b0ebc8e8df7 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -531,6 +531,7 @@ if ($action == 'export_csv') print ""; + llxFooter(); } -llxFooter(); + $db->close(); diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql index 5e53d259376..66107385bd5 100755 --- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql +++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql @@ -571,5 +571,5 @@ insert into llx_c_chargesociales (id, libelle, deductible, active, code, fk_pays insert into llx_c_chargesociales (id, libelle, deductible, active, code, fk_pays) values (4108, 'Mitarbeitervorsorgekasse', 1,1,'TAXATMVK' ,'41'); insert into llx_c_chargesociales (id, libelle, deductible, active, code, fk_pays) values (4109, 'Familienlastenausgleichsfond', 1,1,'TAXATFLAF' ,'41'); -ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN doc_ref varchar(255) NOT NULL; +ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN doc_ref varchar(300) NOT NULL; diff --git a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql index dca4b70a5d5..0f0c3d4ebf9 100644 --- a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql +++ b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql @@ -22,7 +22,7 @@ CREATE TABLE llx_accounting_bookkeeping rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, doc_date date NOT NULL, doc_type varchar(30) NOT NULL, -- facture_client/reglement_client/facture_fournisseur/reglement_fournisseur - doc_ref varchar(255) NOT NULL, -- facture_client/reglement_client/... reference number + doc_ref varchar(300) NOT NULL, -- facture_client/reglement_client/... reference number fk_doc integer NOT NULL, -- facture_client/reglement_client/... rowid fk_docdet integer NOT NULL, -- facture_client/reglement_client/... line rowid code_tiers varchar(24), -- code tiers diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index dad6b236d92..d7db34b1105 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -169,3 +169,5 @@ Param=Additionnal parameters EnabledProduct=In Product EnabledTiers=In Tiers EnabledVat=In Vat + +MvtNotCorrectlyBalanced=Mouvement not correctly balanced. Credit = %s. Debit = %s \ No newline at end of file