diff --git a/.travis.yml b/.travis.yml index 8655b27d4ed..8e1aa2aa10b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -287,10 +287,13 @@ script: php upgrade.php 3.9.0 4.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade390400.log php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade390400-2.log php step5.php 3.9.0 4.0.0 > $TRAVIS_BUILD_DIR/upgrade390400-3.log + php upgrade.php 4.0.0 5.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade400500.log + php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade400500-2.log + php step5.php 4.0.0 5.0.0 > $TRAVIS_BUILD_DIR/upgrade400500-3.log cd - set +e echo - #cat $TRAVIS_BUILD_DIR/upgrade390400-2.log + #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log #cat /tmp/dolibarr_install.log - | diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 736aec48644..736581e9248 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -23,6 +23,7 @@ * \ingroup Advanced accountancy * \brief Balance of book keeping */ + require '../../main.inc.php'; // Class @@ -184,7 +185,7 @@ else { print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "t.label_compte", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); - print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; @@ -213,6 +214,9 @@ else { $total_debit = 0; $total_credit = 0; + $sous_total_debit = 0; + $sous_total_credit = 0; + $displayed_account = ""; foreach ( $object->lines as $line ) { $var = ! $var; @@ -220,33 +224,59 @@ else { $total_debit += $line->debit; $total_credit += $line->credit; $description = $object->get_compte_desc($line->numero_compte); // Search description of the account + $root_account_description = $object->get_compte_racine($line->numero_compte); if(empty($description)){ $link = '' . img_edit_add() .''; } print ''; + + // Permet d'afficher le compte comptable + if ($root_account_description != $displayed_account) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account != "") { + print ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''. $root_account_description .''; + print ''; + + $displayed_account = $root_account_description; + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + // $object->get_compte_racine($line->numero_compte); + + print '' . length_accountg($line->numero_compte) . ''; print '' . $description . ''; print '' . number_format($line->debit, 2, ',', ' ') . ''; - print '' . number_format($line->credit, 2, ',', ' ') . ''; - print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; + print '' . number_format($line->credit, 2, ',', ' ') . ''; + print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; print '' . $link; print ''; print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + } - print ''; - print ''; - print ''; - print ''; - print price($total_debit); - print ''; - print ''; - print price($total_credit); - print ''; - print '' . price($total_credit - $total_debit) . ''; - print ''; - print ''; + print ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + + print ''.$langs->trans("AccountBalance") . ':'.price($total_debit).''.price($total_credit).''.price($total_credit-$total_debit).''; + print " \n"; + print ''; + print ""; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 23148213aa0..5eafa920973 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -258,7 +258,6 @@ if ($action == 'export_csv') { */ $title_page = $langs->trans("Bookkeeping") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); - llxHeader('', $title_page); // List @@ -315,6 +314,7 @@ print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield print '
'; print '
' . "\n"; +print ''; print '
'; print ''; print '
'; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php new file mode 100644 index 00000000000..ce62655465d --- /dev/null +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -0,0 +1,348 @@ + + * largely based on the great work of : + * - Copyright (C) 2013-2016 Olivier Geffroy + * - Copyright (C) 2013-2016 Florian Henry + * - Copyright (C) 2013-2016 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 htdocs/accountancy/bookkeeping/listbyaccount.php + * \ingroup Advanced accountancy + * \brief List operation of book keeping ordered by account number + */ + +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'; + +// Langs +$langs->load("accountancy"); + +$page = GETPOST("page"); +$sortorder = GETPOST("sortorder"); +$sortfield = GETPOST("sortfield"); +$action = GETPOST('action', 'alpha'); +$search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); +$search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); +$search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); + + + +$search_accountancy_code = GETPOST("search_accountancy_code"); + +$search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); +if ($search_accountancy_code_start == - 1) { + $search_accountancy_code_start = ''; +} +$search_label_account = GETPOST('search_label_account', 'alpha'); + +$search_mvt_label = GETPOST('search_mvt_label', 'alpha'); +$search_direction = GETPOST('search_direction', 'alpha'); +$search_ledger_code = GETPOST('search_ledger_code', 'alpha'); + +$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; +if ($page == -1) { $page = 0 ; } +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + +$object = new BookKeeping($db); + +$formventilation = new FormVentilation($db); +$formother = new FormOther($db); +$form = new Form($db); + + + + +if (empty($search_date_start)) { + $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); + $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); +} +if ($sortorder == "") + $sortorder = "ASC"; +if ($sortfield == "") + $sortfield = "t.rowid"; + + +$options = ''; +$filter = array (); + +if (! empty($search_date_start)) { + $filter['t.doc_date>='] = $search_date_start; + $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); +} +if (! empty($search_date_end)) { + $filter['t.doc_date<='] = $search_date_end; + $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); +} +if (! empty($search_doc_date)) { + $filter['t.doc_date'] = $search_doc_date; + $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); +} + + +if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + if (! empty($search_accountancy_code_start)) { + $filter['t.numero_compte'] = $search_accountancy_code_start; + $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + } + if (! empty($search_label_account)) { + $filter['t.label_compte'] = $search_label_account; + $options .= '&search_label_account=' . $search_label_account; + } + if (! empty($search_mvt_label)) { + $filter['t.label_compte'] = $search_mvt_label; + $options .= '&search_mvt_label=' . $search_mvt_label; + } + if (! empty($search_direction)) { + $filter['t.sens'] = $search_direction; + $options .= '&search_direction=' . $search_direction; + } + if (! empty($search_ledger_code)) { + $filter['t.code_journal'] = $search_ledger_code; + $options .= '&search_ledger_code=' . $search_ledger_code; + } +} + +/* + * Action + */ + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_doc_date = ''; + $search_accountancy_code = ''; + $search_accountancy_code_start = ''; + $search_label_account = ''; + $search_mvt_label = ''; + $search_direction = ''; + $search_ledger_code = ''; +} + +if ($action == 'delmouvconfirm') { + + $mvt_num = GETPOST('mvt_num', 'int'); + + if (! empty($mvt_num)) { + $result = $object->deleteMvtNum($mvt_num); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + Header("Location: listbyaccount.php"); + exit(); + } +} + + +/* + * View + */ + +$title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); + +llxHeader('', $title_page); + +// List + +$nbtotalofrecords = 0; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter); + if ($nbtotalofrecords < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +$result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter); +if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); +} +$nbtotalofrecords = $result; + +if ($action == 'delmouv') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1); + print $formconfirm; +} +if ($action == 'delbookkeepingyear') { + + $form_question = array (); + $delyear = GETPOST('delyear'); + + if (empty($delyear)) { + $delyear = dol_print_date(dol_now(), '%Y'); + } + $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); + + $form_question['delyear'] = array ( + 'name' => 'delyear', + 'type' => 'select', + 'label' => $langs->trans('DelYear'), + 'values' => $year_array, + 'default' => $delyear + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1); + print $formconfirm; +} + + + + +print ''; + +print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'',0,'','',$limit); + +// Reverse sort order +if ( preg_match('/^asc/i', $sortorder) ) + $sortorder = "asc"; +else + $sortorder = "desc"; + +print '
' . "\n"; +print ''; +print '
'; + +print ''; +print ''; +print ''; +print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); +print ''; +print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); +print "\n"; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print ''; + +$var = True; + +$total_debit = 0; +$total_credit = 0; +$sous_total_debit = 0; +$sous_total_credit = 0; +$displayed_account_number = ""; + +foreach ( $object->lines as $line ) { + $var = ! $var; + + $total_debit += $line->debit; + $total_credit += $line->credit; + + // Permet d'afficher le compte comptable + if (length_accountg($line->numero_compte) != $displayed_account_number) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account_number != "") { + print ''; + print "\n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''; + print ''; + + $displayed_account_number = length_accountg($line->numero_compte); + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + print ''; + print ''; + print ''; + print ''; + + // Affiche un lien vers la facture client/fournisseur + $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref); + if ($line->doc_type == 'supplier_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + elseif ($line->doc_type == 'customer_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + else + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + + + print ''; + print ''; + print ''; + print ''; + print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + +} + +// Affiche un Sous-Total du dernier compte comptable affiché +print ''; +print "\n"; +print ''; + + +// Affiche le Total +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print "
' . $langs->trans("AccountAccounting") . '' . $langs->trans("SuppliersInvoices") . ' / ' . $langs->trans("CustomersInvoices") . '
' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . ''; +print $langs->trans('From') . ': '; +print $form->select_date($search_date_start, 'date_start', 0, 0, 1); +print '
'; +print $langs->trans('to') . ': '; +print $form->select_date($search_date_end, 'date_end', 0, 0, 1); +print '
  '; +$searchpitco=$form->showFilterAndCheckAddButtons(0); +print $searchpitco; +print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte).'
 ' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . price($line->debit) . '' . price($line->credit) . '' . $line->code_journal . ''; + print '' . img_edit() . ' '; + print '' . img_delete() . ''; + print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.$langs->trans("Total").':'; +print price($total_debit); +print ''; +print price($total_credit); +print '
"; +print ''; + +llxFooter(); + + +$db->close(); diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 79e66ab7cce..5832d44cd52 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -53,14 +53,14 @@ class BookKeeping extends CommonObject * * @var string Name of table without prefix where object is stored */ - public $table_element = 'accounting_bookkeeping'; - + public $table_element = 'accounting_bookkeeping'; + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - + /** * * @var int ID @@ -84,10 +84,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -97,24 +97,22 @@ class BookKeeping extends CommonObject $this->db = $db; return 1; } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - - global $langs; - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -160,32 +158,32 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + $this->db->begin(); - + $this->piece_num = 0; - + // first check if line not yet in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; + $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; $sql .= " AND fk_docdet = " . $this->fk_docdet; - $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; - - dol_syslog(get_class($this) . ":: create ", LOG_DEBUG); + $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); if ($row->nb == 0) { - + // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -196,7 +194,7 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -204,19 +202,18 @@ class BookKeeping extends CommonObject $this->piece_num = $objnum->maxpiecenum; } } + dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $this->piece_num = 1; } - - dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); - + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; } - + $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; - + $sql .= "doc_date"; $sql .= ", doc_type"; $sql .= ", doc_ref"; @@ -233,33 +230,33 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - + $sql .= ") VALUES ("; - - $sql .= "'" . $this->db->idate($this->doc_date) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; + + $sql .= "'" . $this->doc_date . "'"; + $sql .= ",'" . $this->doc_type . "'"; + $sql .= ",'" . $this->doc_ref . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->db->escape($this->code_tiers) . "'"; - $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; + $sql .= ",'" . $this->code_tiers . "'"; + $sql .= ",'" . $this->numero_compte . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->db->escape($this->sens) . "'"; + $sql .= ",'" . $this->sens . "'"; $sql .= ",'" . $this->fk_user_author . "'"; $sql .= ",'" . $this->date_create . "'"; - $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; + $sql .= ",'" . $this->code_journal . "'"; $sql .= "," . $this->piece_num; - + $sql .= ")"; - - dol_syslog(get_class($this) . ":: create", LOG_DEBUG); + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if ($id > 0) { $this->id = $id; $result = 0; @@ -267,67 +264,67 @@ class BookKeeping extends CommonObject $result = - 2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 3; $error ++; - $this->errors[] = $langs->trans('BookeppingLineAlreayExists'); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' '. implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $result; } } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -373,13 +370,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add control on parameters values - + // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; @@ -396,9 +393,9 @@ class BookKeeping extends CommonObject $sql .= 'import_key,'; $sql .= 'code_journal,'; $sql .= 'piece_num'; - + $sql .= ') VALUES ('; - + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -415,58 +412,58 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); - + $sql .= ')'; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } - + /** * Load object in memory from the database * * @param int $id Id object * @param string $ref Ref - * + * * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null) { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -483,22 +480,22 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; } else { $sql .= ' WHERE t.rowid = ' . $id; } - + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); if ($numrows) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_type = $obj->doc_type; $this->doc_ref = $obj->doc_ref; @@ -517,7 +514,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -526,12 +523,12 @@ class BookKeeping extends CommonObject } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - - /** + + /** * Load object in memory from the database * * @param string $sortorder Sort Order @@ -540,15 +537,15 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -565,9 +562,9 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -582,33 +579,36 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=' . $value; } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; - } else { + } elseif ($key == 't.label_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + }else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + // Affichage par compte comptable + $sql .= ' ORDER BY t.numero_compte ASC'; if (! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= ', ' . $sortfield . ' ' .$sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -625,20 +625,21 @@ class BookKeeping extends CommonObject $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + + /** * Load object in memory from the database * @@ -648,20 +649,34 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ - public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.doc_date,"; + $sql .= " t.doc_type,"; + $sql .= " t.doc_ref,"; + $sql .= " t.fk_doc,"; + $sql .= " t.fk_docdet,"; + $sql .= " t.code_tiers,"; $sql .= " t.numero_compte,"; - $sql .= " SUM(t.debit) as debit,"; - $sql .= " SUM(t.credit) as credit"; - - + $sql .= " t.label_compte,"; + $sql .= " t.debit,"; + $sql .= " t.credit,"; + $sql .= " t.montant,"; + $sql .= " t.sens,"; + $sql .= " t.fk_user_author,"; + $sql .= " t.import_key,"; + $sql .= " t.code_journal,"; + $sql .= " t.piece_num"; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -681,13 +696,11 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - - $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -695,45 +708,141 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + + $line->id = $obj->rowid; + + $line->doc_date = $this->db->jdate($obj->doc_date); + $line->doc_type = $obj->doc_type; + $line->doc_ref = $obj->doc_ref; + $line->fk_doc = $obj->fk_doc; + $line->fk_docdet = $obj->fk_docdet; + $line->code_tiers = $obj->code_tiers; + $line->numero_compte = $obj->numero_compte; + $line->label_compte = $obj->label_compte; + $line->debit = $obj->debit; + $line->credit = $obj->credit; + $line->montant = $obj->montant; + $line->sens = $obj->sens; + $line->fk_user_author = $obj->fk_user_author; + $line->import_key = $obj->import_key; + $line->code_journal = $obj->code_journal; + $line->piece_num = $obj->piece_num; + + $this->lines[] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= " t.numero_compte,"; + $sql .= " SUM(t.debit) as debit,"; + $sql .= " SUM(t.credit) as credit"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + + // Manage filter + $sqlwhere = array (); + if (count($filter) > 0) { + foreach ( $filter as $key => $value ) { + if ($key == 't.doc_date') { + $sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\''; + } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { + $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; + } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') { + $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; + } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { + $sqlwhere[] = $key . '=' . $value; + } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + } else { + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + } + + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); + } + + $sql .= ' GROUP BY t.numero_compte'; + + if (! empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (! empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array (); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ( $obj = $this->db->fetch_object($resql) ) { + $line = new BookKeepingLine(); + $line->numero_compte = $obj->numero_compte; $line->debit = $obj->debit; $line->credit = $obj->credit; $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Update object into database * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function update(User $user, $notrigger = false) { $error = 0; - + dol_syslog(__METHOD__, LOG_DEBUG); - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -779,13 +888,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add a control on parameters values - + // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - + $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; @@ -802,71 +911,71 @@ class BookKeeping extends CommonObject $sql .= ' import_key = ' . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ','; $sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ','; $sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); - + $sql .= ' WHERE rowid=' . $this->id; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error && ! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_MODIFY',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete object in database * * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_DELETE',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } } - + if (! $error) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - + $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -874,19 +983,19 @@ class BookKeeping extends CommonObject dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete bookkepping by importkey * @@ -895,14 +1004,14 @@ class BookKeeping extends CommonObject */ function deleteByImportkey($importkey) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE import_key = '" . $importkey . "'"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -912,11 +1021,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -925,14 +1034,14 @@ class BookKeeping extends CommonObject */ function deleteByYear($delyear) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE YEAR(doc_date) = " . $delyear; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -942,54 +1051,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - - /** - * Delete bookkepping by year - * - * @param string $delyear year to delete - * @param string $deljournal journal to delete - * @return int Result - */ - function deleteByYearAndJournal($delyear,$deljournal) { - $this->db->begin(); - - $sqlwhere=array(); - - // first check if line not yet in bookkeeping - $sql = "DELETE"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - if (!empty($delyear)) { - $sqlwhere[] .= " YEAR(doc_date) = " . $delyear; - } - if (!empty($deljournal)) { - $sqlwhere[] .= " code_journal = '" . $this->db->escape($deljournal)."'"; - } - - if (count($sqlwhere)>0) { - $sql.=" WHERE ".implode(' AND ', $sqlwhere); - - $resql = $this->db->query($sql); - - if (! $resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - foreach ( $this->errors as $errmsg ) { - dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); - } - $this->db->rollback(); - return - 1; - } - - $this->db->commit(); - - } - return 1; - } - + /** * Delete bookkepping by piece number * @@ -998,14 +1064,14 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1015,57 +1081,57 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone - * + * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); - + global $user; $error = 0; $object = new Accountingbookkeeping($this->db); - + $this->db->begin(); - + // Load source object $object->fetch($fromid); // Reset object $object->id = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); - + return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1074,7 +1140,7 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { $this->id = 0; - + $this->doc_date = ''; $this->doc_type = ''; $this->doc_ref = ''; @@ -1092,7 +1158,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1103,12 +1169,12 @@ class BookKeeping extends CommonObject $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1119,10 +1185,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1130,13 +1196,13 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $obj = $this->db->fetch_object($result); - + return $obj->max; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1144,7 +1210,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1158,17 +1224,17 @@ class BookKeeping extends CommonObject $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1183,7 +1249,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1191,10 +1257,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1207,20 +1273,20 @@ class BookKeeping extends CommonObject $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1235,11 +1301,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1247,40 +1313,114 @@ class BookKeeping extends CommonObject return - 1; } } + + + + /** + * Return list of accounts with label by chart of accounts + * + * @param string $selectid Preselected chart of accounts + * @param string $htmlname Name of field in html form + * @param int $showempty Add an empty field + * @param array $event Event options + * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1) + * @param int $select_out set value returned by select 0=rowid (default), 1=account_number + * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number + * + * @return string String with HTML select + */ + function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { + global $conf; + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; + + $pcgver = $conf->global->CHARTOFACCOUNTS; + + $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version"; + $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"; + $sql .= " AND aa.active = 1"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " ORDER BY account_number ASC"; + + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); + return -1; + } + + $out = ajax_combobox($htmlname, $event); + + $options = array(); + $selected = null; + + while ($obj = $this->db->fetch_object($resql)) { + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; + $label = dol_trunc($label, $trunclength); + + $select_value_in = $obj->rowid; + $select_value_out = $obj->rowid; + + if ($select_in == 1) { + $select_value_in = $obj->account_number; + } + if ($select_out == 1) { + $select_value_out = $obj->account_number; + } + + // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number + // Because same account_number can be share between different accounting_system and do have the same meaning + if (($selectid != '') && $selectid == $select_value_in) { + $selected = $select_value_out; + } + + $options[$select_value_out] = $label; + } + + $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300'); + $this->db->free($resql); + return $out; + } + + + /** - * Description of accounting account + * Description of a root accounting account * * @param string $account Accounting account - * @return string + * @return string */ - function get_compte_desc($account = null) - { + function get_compte_racine($account = null) + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; - $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa "; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql .= " AND aa.account_number = '" . $account . "'"; - $sql .= " AND asy.rowid = " . $pcgver; - $sql .= " AND aa.active = 1"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; + + $sql = "SELECT root.account_number, root.label as label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as parent ON aa.account_parent = parent.rowid"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as root ON parent.account_parent = root.rowid"; + $sql .= " WHERE aa.account_number = '" . $account . "'"; + $sql .= " AND parent.active = 1"; + $sql .= " AND root.active = 1"; + dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - } - - if(empty($obj->category)){ - return $obj->label; - }else{ - return $obj->label.' ('.$obj->category.')'; - + $obj = $this->db->fetch_object($resql); } + + return $obj->label; + } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); @@ -1288,7 +1428,46 @@ class BookKeeping extends CommonObject return -1; } } - + + + /** + * Description of accounting account + * + * @param string $account Accounting account + * @return string + */ + function get_compte_desc($account = null) + { + global $conf; + $pcgver = $conf->global->CHARTOFACCOUNTS; + $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND aa.account_number = '" . $account . "'"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " AND aa.active = 1"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; + dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $obj = ''; + if ($this->db->num_rows($resql)) { + $obj = $this->db->fetch_object($resql); + } + + if(empty($obj->category)){ + return $obj->label; + }else{ + return $obj->label.' ('.$obj->category.')'; + + } + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + return -1; + } + } + } /** diff --git a/htdocs/accountancy/tpl/export_journal.tpl.php b/htdocs/accountancy/tpl/export_journal.tpl.php index e9b7c8c005c..f69b47a8017 100644 --- a/htdocs/accountancy/tpl/export_journal.tpl.php +++ b/htdocs/accountancy/tpl/export_journal.tpl.php @@ -1,5 +1,6 @@ + * Copyright (C) 2016 Charlie Benke * * 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,12 +17,12 @@ */ $prefix = $conf->global->ACCOUNTING_EXPORT_PREFIX_SPEC; $format = $conf->global->ACCOUNTING_EXPORT_FORMAT; +$nodateexport = $conf->global->ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME; $date_export = dol_print_date($now, '%Y%m%d%H%M%S'); header('Content-Type: text/csv'); -if ($prefix) - $filename = $prefix . "_" . "journal_" . $journal . $date_export . "." . $format; -else - $filename = "journal_" . $journal . $date_export . "." . $format; -header('Content-Disposition: attachment;filename=' . $filename); \ No newline at end of file + +$filename = ($prefix?$prefix . "_":""). "journal_" . $journal . ($nodateexport?"":$date_export) . "." . $format; + +header('Content-Disposition: attachment;filename=' . $filename); diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 256a31fd947..8ead3188ae7 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -46,6 +46,8 @@ if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherent if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; $langs->load("companies"); +$langs->load('banks'); + if (! empty($conf->contrat->enabled)) $langs->load("contracts"); if (! empty($conf->commande->enabled)) $langs->load("orders"); if (! empty($conf->expedition->enabled)) $langs->load("sendings"); @@ -124,7 +126,15 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - // customer preferred shipping method + // Bank account + if ($action == 'setbankaccount' && $user->rights->societe->creer) + { + $object->fetch($id); + $result=$object->setBankAccount(GETPOST('fk_account','int')); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } + + // customer preferred shipping method if ($action == 'setshippingmethod' && $user->rights->societe->creer) { $object->fetch($id); @@ -337,6 +347,26 @@ if ($id > 0) print ""; print ''; + // Compte bancaire par défaut + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if (($action != 'editbankaccount') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1); + } + else + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none'); + } + print ""; + print ''; + + // Relative discounts (Discounts-Drawbacks-Rebates) print ''; print ''; - print ''; diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 4d0ab65a941..48797dd0432 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -35,6 +35,19 @@ $element = GETPOST('element','alpha',2); $table_element = GETPOST('table_element','alpha',2); $fk_element = GETPOST('fk_element','alpha',2); +/* Example: +field:editval_ref_customer (8 first chars will removed to know name of property) +element:contrat +table_element:contrat +fk_element:4 +type:string +value:aaa +loadmethod: +savemethod: +savemethodname: +*/ + + /* * View */ @@ -81,7 +94,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ } else $newelement = $element; - if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->write) + if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->create) || ! empty($user->rights->$newelement->write) || (isset($subelement) && (! empty($user->rights->$newelement->$subelement->creer) || ! empty($user->rights->$newelement->$subelement->write))) || ($element == 'payment' && $user->rights->facture->paiement) || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->creer)) diff --git a/htdocs/core/class/doleditor.class.php b/htdocs/core/class/doleditor.class.php index ff31823976e..3bfcf9b781e 100644 --- a/htdocs/core/class/doleditor.class.php +++ b/htdocs/core/class/doleditor.class.php @@ -99,7 +99,7 @@ class DolEditor $this->editor->Value = $content; $this->editor->Height = $height; if (! empty($width)) $this->editor->Width = $width; - $this->editor->ToolbarSet = $shorttoolbarname; + $this->editor->ToolbarSet = $shorttoolbarname; // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js $this->editor->Config['AutoDetectLanguage'] = 'true'; $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In'; $this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded; diff --git a/htdocs/core/class/genericobject.class.php b/htdocs/core/class/genericobject.class.php index 32960664c17..c89b5c31fea 100644 --- a/htdocs/core/class/genericobject.class.php +++ b/htdocs/core/class/genericobject.class.php @@ -24,8 +24,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; /** - * \class GenericObject - * \brief Class of a generic business object + * Class of a generic business object */ class GenericObject extends CommonObject diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 1a7425b0a55..a71ed57ab2c 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -142,7 +142,8 @@ class HookManager 'formObjectOptions', 'formattachOptions', 'formBuilddocLineOptions', - 'getIdProfUrl', + 'getFormMail', + 'getIdProfUrl', 'moveUploadedFile', 'pdf_build_address', 'pdf_writelinedesc', diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 8279702f49c..2ef445bcac3 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -79,7 +79,9 @@ function societe_prepare_head(Societe $object) if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) { $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id; + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); $head[$h][1] = $langs->trans("ContactsAddresses"); + if ($nbContact > 0) $head[$h][1].= ' '.$nbContact.''; $head[$h][2] = 'contact'; $h++; } diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 562dcf9d223..a0d61144582 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -117,12 +117,24 @@ function dol_time_plus_duree($time, $duration_value, $duration_unit) if ($duration_value == 0) return $time; if ($duration_unit == 'h') return $time + (3600*$duration_value); if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); - if ($duration_value > 0) $deltastring="+".abs($duration_value); - if ($duration_value < 0) $deltastring="-".abs($duration_value); - if ($duration_unit == 'd') { $deltastring.=" day"; } - if ($duration_unit == 'm') { $deltastring.=" month"; } - if ($duration_unit == 'y') { $deltastring.=" year"; } - return strtotime($deltastring,$time); + + $deltastring='P'; + + if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; } + if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; } + if ($duration_unit == 'd') { $deltastring.="D"; } + if ($duration_unit == 'm') { $deltastring.="M"; } + if ($duration_unit == 'y') { $deltastring.="Y"; } + + $date = new DateTime(); + $date->setTimezone(new DateTimeZone('UTC')); + $date->setTimestamp($time); + $interval = new DateInterval($deltastring); + + if($sub) $date->sub($interval); + else $date->add( $interval ); + + return $date->getTimestamp(); } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 136e31bd23a..7d7697bd91f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4267,7 +4267,7 @@ function picto_required() * Clean a string from all HTML tags and entities * * @param string $StringHtml String to clean - * @param integer $removelinefeed Replace also all lines feeds by a space, otherwise only last one are removed + * @param integer $removelinefeed 1=Replace also all lines feeds by a space, 0=Only last one are removed * @param string $pagecodeto Encoding of input/output string * @return string String cleaned * @@ -5257,7 +5257,7 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode= if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg)) { $substitutionarray=array(); - complete_substitutions_array($substitutionarray,$langs,$object); + complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2])); $label=make_substitutions($reg[1], $substitutionarray); } else $label=$langs->trans($values[2]); @@ -5277,7 +5277,7 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode= if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg)) { $substitutionarray=array(); - complete_substitutions_array($substitutionarray,$langs,$object); + complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2])); $label=make_substitutions($reg[1], $substitutionarray); } else $label=$langs->trans($values[2]); diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 7ab1a53d230..c45c045e11d 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1971,6 +1971,11 @@ function getElementProperties($element_type) $module='resource'; $subelement='dolresource'; } + if ($element_type == 'propaldet') { + $classpath = 'comm/propal/class'; + $module='propal'; + $subelement='propaleligne'; + } $classfile = strtolower($subelement); $classname = ucfirst($subelement); diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index e8977c11789..8d35ff63225 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -206,7 +206,7 @@ class ExportCsv extends ModeleExports foreach($array_selected_sorted as $code => $value) { $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); // newvalue is now $outputlangs->charset_output encoded - $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); + $newvalue=$this->csvClean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); } @@ -250,7 +250,7 @@ class ExportCsv extends ModeleExports // Translation newvalue if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) $newvalue=$outputlangs->transnoentities($reg[1]); - $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); + $newvalue=$this->csvClean($newvalue,$outputlangs->charset_output); if (preg_match('/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7)) { @@ -292,24 +292,36 @@ class ExportCsv extends ModeleExports /** * Clean a cell to respect rules of CSV file cells + * Note: It uses $this->separator + * Note: We keep this function public to be able to test * * @param string $newvalue String to clean * @param string $charset Input AND Output character set * @return string Value cleaned */ - function csv_clean($newvalue, $charset) + public function csvClean($newvalue, $charset) { + global $conf; $addquote=0; + // Rule Dolibarr: No HTML - //print $charset.' '.$newvalue."\n"; - $newvalue=dol_string_nohtmltag($newvalue,1,$charset); - //print $charset.' '.$newvalue."\n"; - - // Rule 1 CSV: No CR, LF in cells + //print $charset.' '.$newvalue."\n"; + //$newvalue=dol_string_nohtmltag($newvalue,0,$charset); + $newvalue=dol_htmlcleanlastbr($newvalue); + //print $charset.' '.$newvalue."\n"; + + // Rule 1 CSV: No CR, LF in cells (except if USE_STRICT_CSV_RULES is on, we can keep record as it is but we must add quotes) + $oldvalue=$newvalue; $newvalue=str_replace("\r",'',$newvalue); $newvalue=str_replace("\n",'\n',$newvalue); - + if (! empty($conf->global->USE_STRICT_CSV_RULES) && $oldvalue != $newvalue) + { + // If strict use of CSV rules, we just add quote + $newvalue=$oldvalue; + $addquote=1; + } + // Rule 2 CSV: If value contains ", we must escape with ", and add " if (preg_match('/"/',$newvalue)) { diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index 0d0720d7440..8224673f1a2 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -44,7 +44,7 @@ class modAgenda extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 2400; @@ -392,10 +392,14 @@ class modAgenda extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'actioncomm as ac'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id'; + if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR ac.fk_soc IS NULL)'; + if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' AND acr.fk_element = '.$user->id; $this->export_sql_end[$r] .=' ORDER BY ac.datep'; } diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index ec11708641c..7d38a427e1c 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -45,7 +45,7 @@ class modCommande extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 25; @@ -191,6 +191,7 @@ class modCommande extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c'; @@ -204,6 +205,7 @@ class modCommande extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index 19ef73f37bc..c1e9c092ff6 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -39,7 +39,7 @@ class modDeplacement extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 75 ; @@ -124,8 +124,16 @@ class modDeplacement extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'deplacement as d'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid'; $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('deplacement',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR d.fk_soc IS NULL)'; + + $childids = $user->getAllChildIds(); + $childids[]=$user->id; + + if (!$user->rights->deplacement->readall && !$user->rights->deplacement->lire_tous) $sql.=' AND d.fk_user IN ('.join(',',$childids).')'; + } diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 13d72baebc1..8116186219d 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -43,7 +43,7 @@ class modExpedition extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 80; @@ -257,6 +257,7 @@ class modExpedition extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'expedition as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'expedition_extrafields as extra ON c.rowid = extra.fk_object,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expeditiondet as ed'; @@ -271,6 +272,7 @@ class modExpedition extends DolibarrModules } $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('shipment',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index c4f9dc20243..794032c59f5 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -42,7 +42,7 @@ class modFacture extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 30; @@ -205,6 +205,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; @@ -217,6 +218,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -232,6 +234,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; @@ -245,6 +248,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; } diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 3cf63b6cfb9..794b6cb50ff 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -42,7 +42,7 @@ class modFournisseur extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 40; @@ -366,6 +366,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -375,6 +376,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -428,6 +430,7 @@ class modFournisseur extends DolibarrModules // End add extra fields object $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -436,6 +439,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; // Order $r++; @@ -532,6 +536,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -543,6 +548,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index 32ebb340e71..e9fe448baf7 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -43,7 +43,7 @@ class modPropale extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 20; @@ -184,6 +184,7 @@ class modPropale extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s '; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'propal as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid'; @@ -196,6 +197,7 @@ class modPropale extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('propal',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index baf680f0352..c238470ce6f 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -43,7 +43,7 @@ class modSociete extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 1; @@ -274,7 +274,8 @@ class modSociete extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid'; $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe', 1).')'; - + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; + // Export list of contacts and attributes $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -295,10 +296,12 @@ class modSociete extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid'; $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity("societe", 1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; // Imports diff --git a/htdocs/core/modules/modWebsites.class.php b/htdocs/core/modules/modWebsites.class.php index 30795c6c0fa..a510e569b60 100644 --- a/htdocs/core/modules/modWebsites.class.php +++ b/htdocs/core/modules/modWebsites.class.php @@ -99,7 +99,7 @@ class modWebsites extends DolibarrModules $this->rights[$r][0] = 10002; $this->rights[$r][1] = 'Create/modify website content'; $this->rights[$r][3] = 0; - $this->rights[$r][4] = 'create'; + $this->rights[$r][4] = 'write'; $r++; $this->rights[$r][0] = 10003; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e38ebd977e1..d434e7df6c1 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1924,6 +1924,8 @@ else if ($id || $ref) // Tableau des substitutions $formmail->setSubstitFromObject($object); $formmail->substit['__SHIPPINGREF__']=$object->ref; + $formmail->substit['__SHIPPINGTRACKNUM__']=$object->tracking_number; + $formmail->substit['__SHIPPINGTRACKNUMURL__']=$object->tracking_url; //Find the good contact adress if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) { diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 496092b7f73..48c34acd128 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -526,7 +526,7 @@ class Export return -1; } - // Creation de la classe d'export du model ExportXXX + // Creation of class to export using model ExportXXX $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; $file = "export_".$model.".modules.php"; $classname = "Export".$model; diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 11ae0fc9218..02a650a2e10 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -638,7 +638,14 @@ if ($step == 2 && $datatoexport) if ($step == 3 && $datatoexport) { - llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); + if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired + { + // Switch to step 2 + header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport); + exit; + } + + llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets @@ -792,6 +799,13 @@ if ($step == 3 && $datatoexport) if ($step == 4 && $datatoexport) { + if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired + { + // Switch to step 2 + header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport); + exit; + } + asort($array_selected); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); @@ -1017,6 +1031,13 @@ if ($step == 4 && $datatoexport) if ($step == 5 && $datatoexport) { + if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired + { + // Switch to step 2 + header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport); + exit; + } + asort($array_selected); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 54053c26606..02b87940916 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','4.0.0-rc'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-alpha'); if (! defined('EURO')) define('EURO',chr(128)); diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 6af57716648..7a94e686173 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -169,9 +169,6 @@ if ($lastUpdate) print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''."\n"; } else print $langs->trans('None'); - - - print "
\n"; $result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user. diff --git a/htdocs/holiday/view_log.php b/htdocs/holiday/view_log.php index e4b5070f097..1b0e779488a 100644 --- a/htdocs/holiday/view_log.php +++ b/htdocs/holiday/view_log.php @@ -60,7 +60,14 @@ $log_holiday = $cp->fetchLog('ORDER BY cpl.rowid DESC', " AND date_action BETWEE print load_fiche_titre($langs->trans('LogCP'), '', 'title_hrm.png'); print '
'.$langs->trans('LastUpdateCP').': '."\n"; -if ($cp->getConfCP('lastUpdate')) print ''.dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser').''; +$lastUpdate = $cp->getConfCP('lastUpdate'); +if ($lastUpdate) +{ + $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; + $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3]; + print ''.dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser').''; + print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''."\n"; +} else print $langs->trans('None'); print "

\n"; @@ -108,8 +115,8 @@ foreach($cp->logs as $logs_CP) if ($log_holiday == '2') { - print ''; - print ''; + print ''; + print ''; print ''; } diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 9e21b994780..66a9f7f77bb 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -392,7 +392,8 @@ else array('from'=>'3.6.0', 'to'=>'3.7.0'), array('from'=>'3.7.0', 'to'=>'3.8.0'), array('from'=>'3.8.0', 'to'=>'3.9.0'), - array('from'=>'3.9.0', 'to'=>'4.0.0') + array('from'=>'3.9.0', 'to'=>'4.0.0'), + array('from'=>'4.0.0', 'to'=>'5.0.0') ); $count=0; diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 8d040e06ed4..d0cf9a4a385 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -369,7 +369,7 @@ if (! empty($force_install_message)) -
'; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index aaa8bf123cd..6523688fd8d 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -59,24 +59,24 @@ class Propal extends CommonObject * ID of the client * @var int */ - var $socid; + public $socid; - var $contactid; - var $author; - var $ref_client; + public $contactid; + public $author; + public $ref_client; /** * Status of the quote * @var int * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED */ - var $statut; + public $statut; /** * @deprecated * @see date_creation */ - var $datec; + public $datec; /** * Creation date @@ -88,7 +88,7 @@ class Propal extends CommonObject * @deprecated * @see date_validation */ - var $datev; + public $datev; /** * Validation date @@ -100,71 +100,73 @@ class Propal extends CommonObject * Date of the quote * @var */ - var $date; + public $date; /** * @deprecated * @see date */ - var $datep; - var $date_livraison; - var $fin_validite; + public $datep; + public $date_livraison; + public $fin_validite; - var $user_author_id; - var $user_valid_id; - var $user_close_id; + public $user_author_id; + public $user_valid_id; + public $user_close_id; /** * @deprecated * @see total_ht */ - var $price; + public $price; /** * @deprecated * @see total_tva */ - var $tva; + public $tva; /** * @deprecated * @see total_ttc */ - var $total; + public $total; - var $cond_reglement_code; - var $mode_reglement_code; - var $remise; - var $remise_percent; - var $remise_absolue; - var $fk_address; - var $address_type; - var $address; - var $availability_id; - var $availability_code; - var $demand_reason_id; - var $demand_reason_code; + public $cond_reglement_code; + public $mode_reglement_code; + public $remise; + public $remise_percent; + public $remise_absolue; + public $fk_address; + public $address_type; + public $address; + public $availability_id; + public $availability_code; + public $demand_reason_id; + public $demand_reason_code; - var $products=array(); - var $extraparams=array(); + public $products=array(); + public $extraparams=array(); /** * @var PropaleLigne[] */ - var $lines = array(); - var $line; + public $lines = array(); + public $line; - var $labelstatut=array(); - var $labelstatut_short=array(); + public $labelstatut=array(); + public $labelstatut_short=array(); - var $specimen; + public $specimen; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; - + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; + + public $oldcopy; + /** * Draft status */ @@ -273,7 +275,7 @@ class Propal extends CommonObject $line->tva_tx=$tva_tx; $line->fk_unit=$prod->fk_unit; if ($tva_npr) $line->info_bits = 1; - + $this->lines[]=$line; } } @@ -444,7 +446,7 @@ class Propal extends CommonObject return -3; } } - + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -452,7 +454,7 @@ class Propal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -529,7 +531,7 @@ class Propal extends CommonObject $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // Mise en option de la ligne if (empty($qty) && empty($special_code)) $this->line->special_code=3; @@ -627,7 +629,7 @@ class Propal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -639,7 +641,7 @@ class Propal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; if ($remise_percent > 0) @@ -800,7 +802,7 @@ class Propal extends CommonObject $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + dol_syslog(get_class($this)."::create"); // Check parameters @@ -1110,7 +1112,7 @@ class Propal extends CommonObject $clonedObj->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); $clonedObj->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); $clonedObj->fk_delivery_address = ''; - + /*if (!empty($conf->projet->enabled)) { $project = new Project($db); @@ -1610,11 +1612,12 @@ class Propal extends CommonObject /** * Define proposal date * - * @param User $user Object user that modify - * @param int $date Date - * @return int <0 if KO, >0 if OK + * @param User $user Object user that modify + * @param int $date Date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_date($user, $date) + function set_date($user, $date, $notrigger=0) { if (empty($date)) { @@ -1625,20 +1628,50 @@ class Propal extends CommonObject if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'"; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_date", LOG_DEBUG); - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->date = $date; - $this->datep = $date; // deprecated - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date = $date; + $this->datep = $date; // deprecated + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1646,25 +1679,59 @@ class Propal extends CommonObject /** * Define end validity date * - * @param User $user Object user that modify - * @param int $date_fin_validite End of validity date - * @return int <0 if KO, >0 if OK + * @param User $user Object user that modify + * @param int $date_fin_validite End of validity date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_echeance($user, $date_fin_validite) + function set_echeance($user, $date_fin_validite, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null'); $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fin_validite = $date_fin_validite; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fin_validite = $date_fin_validite; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1672,28 +1739,59 @@ class Propal extends CommonObject /** * Set delivery date * - * @param User $user Object user that modify - * @param int $date_livraison Delivery date - * @return int <0 if ko, >0 if ok + * @param User $user Object user that modify + * @param int $date_livraison Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if ko, >0 if ok */ - function set_date_livraison($user, $date_livraison) + function set_date_livraison($user, $date_livraison, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null'); $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->date_livraison = $date_livraison; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date_livraison = $date_livraison; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_date_livraison Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1703,26 +1801,57 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param int $id Availability id + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_availability($user, $id) + function set_availability($user, $id, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET fk_availability = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_availability = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_availability = $id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_availability Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1732,26 +1861,59 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param int $id Input reason id + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_demand_reason($user, $id) + function set_demand_reason($user, $id, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET fk_input_reason = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_input_reason = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_input_reason = $id; + } + + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_demand_reason Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1761,26 +1923,56 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param string $ref_client Customer reference + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_ref_client($user, $ref_client) + function set_ref_client($user, $ref_client, $notrigger=0) { if (! empty($user->rights->propal->creer)) { - dol_syslog('Propale::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); $sql.= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->ref_client = $ref_client; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog('Propale::set_ref_client Erreur '.$this->error.' - '.$sql); - return -2; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -1793,10 +1985,11 @@ class Propal extends CommonObject * Set an overall discount on the proposal * * @param User $user Object user that modify - * @param double $remise Amount discount + * @param double $remise Amount discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise_percent($user, $remise) + function set_remise_percent($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; @@ -1804,19 +1997,50 @@ class Propal extends CommonObject { $remise = price2num($remise); + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_percent = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_percent = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1825,11 +2049,12 @@ class Propal extends CommonObject /** * Set an absolute overall discount on the proposal * - * @param User $user Object user that modify - * @param double $remise Amount discount + * @param User $user Object user that modify + * @param double $remise Amount discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; @@ -1837,20 +2062,51 @@ class Propal extends CommonObject { $remise = price2num($remise); + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET remise_absolue = ".$remise; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_absolue = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_absolue = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1924,9 +2180,10 @@ class Propal extends CommonObject * @param User $user Object user that close * @param int $statut Statut * @param string $note Comment + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function cloture($user, $statut, $note) + function cloture($user, $statut, $note, $notrigger=0) { global $langs,$conf; @@ -1981,15 +2238,24 @@ class Propal extends CommonObject $this->generateDocument($modelpdf, $outputlangs); } - // Call trigger - $result=$this->call_trigger($trigger_name,$user); - if ($result < 0) { $error++; } - // End call triggers + if (! $error) + { + $this->oldcopy= clone $this; + $this->statut = $statut; + $this->date_cloture = $now; + $this->note_private = $note; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger($trigger_name,$user); + if ($result < 0) { $error++; } + // End call triggers + } if ( ! $error ) { - $this->statut = $statut; - $this->db->commit(); return 1; } @@ -2010,20 +2276,55 @@ class Propal extends CommonObject /** * Class invoiced the Propal * - * @return int <0 si ko, >0 si ok + * @param User $user Object user + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 si ko, >0 si ok */ - function classifyBilled() + function classifyBilled(User $user, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT.' ;'; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; $this->statut=self::STATUS_BILLED; - return 1; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_print_error($this->db); + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2032,7 +2333,7 @@ class Propal extends CommonObject * * @return int <0 si ko, >0 si ok * @deprecated - * @see classifyBilled() + * @see classifyBilled() */ function classer_facturee() { @@ -2046,22 +2347,55 @@ class Propal extends CommonObject * Set draft status * * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_draft($user) + function set_draft($user, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->statut = self::STATUS_DRAFT; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->statut = self::STATUS_DRAFT; $this->brouillon = 1; - return 1; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2364,32 +2698,65 @@ class Propal extends CommonObject * Change the delivery time * * @param int $availability_id Id of new delivery time + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if OK, <0 if KO */ - function availability($availability_id) + function availability($availability_id, $notrigger=0) { - dol_syslog('Propale::availability('.$availability_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_availability = '.$availability_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->availability_id = $availability_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->availability_id = $availability_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Propale::availability Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Propale::availability, etat propale incompatible'); - $this->error='Etat propale incompatible '.$this->statut; + $error_str='Propal status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2398,32 +2765,65 @@ class Propal extends CommonObject * Change source demand * * @param int $demand_reason_id Id of new source demand + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 si ok, <0 si ko */ - function demand_reason($demand_reason_id) + function demand_reason($demand_reason_id, $notrigger=0) { - dol_syslog('Propale::demand_reason('.$demand_reason_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->demand_reason_id = $demand_reason_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->demand_reason_id = $demand_reason_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Propale::demand_reason Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Propale::demand_reason, etat propale incompatible'); - $this->error='Etat propale incompatible '.$this->statut; + $error_str='Propal status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2507,21 +2907,21 @@ class Propal extends CommonObject */ function LibStatut($statut,$mode=1) { - global $langs; - $langs->load("propal"); + global $langs; + $langs->load("propal"); - if ($statut==self::STATUS_DRAFT) $statuttrans='statut0'; - if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1'; - if ($statut==self::STATUS_SIGNED) $statuttrans='statut3'; - if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5'; - if ($statut==self::STATUS_BILLED) $statuttrans='statut6'; + if ($statut==self::STATUS_DRAFT) $statuttrans='statut0'; + if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1'; + if ($statut==self::STATUS_SIGNED) $statuttrans='statut3'; + if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5'; + if ($statut==self::STATUS_BILLED) $statuttrans='statut6'; - if ($mode == 0) return $this->labelstatut[$statut]; - if ($mode == 1) return $this->labelstatut_short[$statut]; - if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut]; - if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans); - if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut]; - if ($mode == 5) return ''.$this->labelstatut_short[$statut].' '.img_picto($this->labelstatut_short[$statut],$statuttrans); + if ($mode == 0) return $this->labelstatut[$statut]; + if ($mode == 1) return $this->labelstatut_short[$statut]; + if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut]; + if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans); + if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut]; + if ($mode == 5) return ''.$this->labelstatut_short[$statut].' '.img_picto($this->labelstatut_short[$statut],$statuttrans); } @@ -2681,7 +3081,7 @@ class Propal extends CommonObject $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -2851,7 +3251,7 @@ class Propal extends CommonObject function getLinesArray() { // For other object, here we call fetch_lines. But fetch_lines does not exists on proposal - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; @@ -2911,7 +3311,7 @@ class Propal extends CommonObject $this->lines[$i]->date_start = $this->db->jdate($obj->date_start); $this->lines[$i]->date_end = $this->db->jdate($obj->date_end); $this->lines[$i]->fk_unit = $obj->fk_unit; - + // Multicurrency $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency; $this->lines[$i]->multicurrency_code = $obj->multicurrency_code; @@ -3096,7 +3496,7 @@ class PropaleLigne extends CommonObjectLine var $multicurrency_total_ht; var $multicurrency_total_tva; var $multicurrency_total_ttc; - + /** * Class line Contructor * @@ -3180,7 +3580,7 @@ class PropaleLigne extends CommonObjectLine $this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_tva = $objp->multicurrency_total_tva; $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->db->free($result); return 1; @@ -3206,7 +3606,7 @@ class PropaleLigne extends CommonObjectLine dol_syslog(get_class($this)."::insert rang=".$this->rang); $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; if (empty($this->localtax1_tx)) $this->localtax1_tx=0; @@ -3226,7 +3626,7 @@ class PropaleLigne extends CommonObjectLine if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3391,7 +3791,7 @@ class PropaleLigne extends CommonObjectLine $error=0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; if (empty($this->localtax1_tx)) $this->localtax1_tx=0; @@ -3413,7 +3813,7 @@ class PropaleLigne extends CommonObjectLine if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3459,13 +3859,13 @@ class PropaleLigne extends CommonObjectLine $sql.= " , date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null"); $sql.= " , date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); $sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6f14d407a5d..ac6386c0574 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -57,98 +57,100 @@ class Commande extends CommonOrder * Client ID * @var int */ - var $socid; + public $socid; - var $ref_client; - var $ref_int; - var $contactid; + public $ref_client; + public $ref_int; + public $contactid; /** * Status of the order. Check the following constants: * @var int * @see Commande::STATUS_CANCELED, Commande::STATUS_DRAFT, Commande::STATUS_ACCEPTED, Commande::STATUS_CLOSED */ - var $statut; + public $statut; /** * @deprecated * @see billed */ - var $facturee; - var $billed; // billed or not + public $facturee; + public $billed; // billed or not - var $brouillon; - var $cond_reglement_code; + public $brouillon; + public $cond_reglement_code; - var $fk_account; + public $fk_account; /** * It holds the label of the payment mode. Use it in case translation cannot be found. * @var string */ - var $mode_reglement; + public $mode_reglement; /** * Payment mode id * @var int */ - var $mode_reglement_id; + public $mode_reglement_id; /** * Payment mode code * @var string */ - var $mode_reglement_code; + public $mode_reglement_code; /** * Availability delivery time id * @var int */ - var $availability_id; + public $availability_id; /** * Availability delivery time code * @var string */ - var $availability_code; + public $availability_code; /** * Label of availability delivery time. Use it in case translation cannot be found. * @var string */ - var $availability; + public $availability; - var $demand_reason_id; - var $demand_reason_code; - var $address; - var $date; // Date commande + public $demand_reason_id; + public $demand_reason_code; + public $address; + public $date; // Date commande /** * @deprecated * @see date */ - var $date_commande; - var $date_livraison; // Date livraison souhaitee - var $fk_remise_except; - var $remise_percent; - var $remise_absolue; - var $info_bits; - var $rang; - var $special_code; - var $source; // Origin of order - var $extraparams=array(); + public $date_commande; + public $date_livraison; // Date livraison souhaitee + public $fk_remise_except; + public $remise_percent; + public $remise_absolue; + public $info_bits; + public $rang; + public $special_code; + public $source; // Origin of order + public $extraparams=array(); - var $linked_objects=array(); + public $linked_objects=array(); - var $user_author_id; + public $user_author_id; /** * @var OrderLine[] */ - var $lines = array(); + public $lines = array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; - + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; + + public $oldcopy; + /** * ERR Not enough stock */ @@ -450,7 +452,7 @@ class Commande extends CommonOrder if (! empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { $result = 0; - + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -469,10 +471,10 @@ class Commande extends CommonOrder if (!$error) { // Call trigger - $result=$this->call_trigger('ORDER_SETDRAFT',$user); + $result=$this->call_trigger('ORDER_UNVALIDATE',$user); if ($result < 0) $error++; } - + if (!$error) { $this->statut=self::STATUS_DRAFT; $this->db->commit(); @@ -701,7 +703,7 @@ class Commande extends CommonOrder // Clean parameters $this->brouillon = 1; // set command as draft - + // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate) if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); @@ -711,7 +713,7 @@ class Commande extends CommonOrder $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + dol_syslog(get_class($this)."::create user=".$user->id); // Check parameters @@ -1231,7 +1233,7 @@ class Commande extends CommonOrder if (empty($txlocaltax2)) $txlocaltax2=0; if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($this->fk_multicurrency)) $this->fk_multicurrency=0; - + $remise_percent=price2num($remise_percent); $qty=price2num($qty); $pu_ht=price2num($pu_ht); @@ -1281,7 +1283,7 @@ class Commande extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -1294,7 +1296,7 @@ class Commande extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -1596,7 +1598,7 @@ class Commande extends CommonOrder $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + $this->extraparams = (array) json_decode($obj->extraparams, true); $this->lines = array(); @@ -1787,7 +1789,7 @@ class Commande extends CommonOrder $line->product_desc = $objp->product_desc; $line->fk_product_type = $objp->fk_product_type; // Produit ou service $line->fk_unit = $objp->fk_unit; - + $line->weight = $objp->weight; $line->weight_units = $objp->weight_units; $line->volume = $objp->volume; @@ -1803,7 +1805,7 @@ class Commande extends CommonOrder $line->multicurrency_total_ht = $objp->multicurrency_total_ht; $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->lines[$i] = $line; $i++; @@ -1854,7 +1856,7 @@ class Commande extends CommonOrder /** * Load array this->expeditions of lines of shipments with nb of products sent for each order line * Note: For a dedicated shipment, the fetch_lines can be used to load the qty_asked and qty_shipped. This function is use to return qty_shipped cumulated for the order - * + * * @param int $filtre_statut Filter on shipment status * @return int <0 if KO, Nb of lines found if OK */ @@ -2044,30 +2046,62 @@ class Commande extends CommonOrder * * @param User $user User qui positionne la remise * @param float $remise Discount (percent) + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise($user, $remise) + function set_remise($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_percent = '.$remise; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_percent = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_percent = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2078,32 +2112,62 @@ class Commande extends CommonOrder * * @param User $user User qui positionne la remise * @param float $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_absolue = '.$remise; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; - dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG); - - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_absolue = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_absolue = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2112,29 +2176,59 @@ class Commande extends CommonOrder /** * Set the order date * - * @param User $user Object user making change - * @param int $date Date - * @return int <0 if KO, >0 if OK + * @param User $user Object user making change + * @param int $date Date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_date($user, $date) + function set_date($user, $date, $notrigger=0) { if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null'); $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_date",LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) + if (!$resql) { - $this->date = $date; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date = $date; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2146,29 +2240,59 @@ class Commande extends CommonOrder /** * Set the planned delivery date * - * @param User $user Objet utilisateur qui modifie + * @param User $user Objet utilisateur qui modifie * @param int $date_livraison Date de livraison - * @return int <0 si ko, >0 si ok + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 si ko, >0 si ok */ - function set_date_livraison($user, $date_livraison) + function set_date_livraison($user, $date_livraison, $notrigger=0) { if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) + if (!$resql) { - $this->date_livraison = $date_livraison; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date_livraison = $date_livraison; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2182,26 +2306,57 @@ class Commande extends CommonOrder * * @param User $user Object user making change * @param int $id If of availability delay + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_availability($user, $id) + function set_availability($user, $id, $notrigger=0) { if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; $sql.= " SET fk_availability = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_availability = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_availability = $id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_availability Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2209,28 +2364,60 @@ class Commande extends CommonOrder /** * Set source of demand * - * @param User $user Object user making change - * @param int $id Id of source - * @return int <0 if KO, >0 if OK + * @param User $user Object user making change + * @param int $id Id of source + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_demand_reason($user, $id) + function set_demand_reason($user, $id, $notrigger=0) { if ($user->rights->commande->creer) { + + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; $sql.= " SET fk_input_reason = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_input_reason = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_input_reason = $id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_demand_reason Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2309,69 +2496,137 @@ class Commande extends CommonOrder } /** - * Change le delai de livraison + * Update delivery delay * * @param int $availability_id Id du nouveau mode + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if OK, <0 if KO */ - function availability($availability_id) + function availability($availability_id, $notrigger=0) { dol_syslog('Commande::availability('.$availability_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_availability = '.$availability_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->availability_id = $availability_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->availability_id = $availability_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Commande::availability Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Commande::availability, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; + $error_str='Command status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } /** - * Change la source de la demande + * Update order demand_reason * * @param int $demand_reason_id Id of new demand + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if ok, <0 if ko */ - function demand_reason($demand_reason_id) + function demand_reason($demand_reason_id, $notrigger=0) { dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->demand_reason_id = $demand_reason_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->demand_reason_id = $demand_reason_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; + $error_str='order status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2381,27 +2636,57 @@ class Commande extends CommonOrder * * @param User $user User that make change * @param string $ref_client Customer ref + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_ref_client($user, $ref_client) + function set_ref_client($user, $ref_client, $notrigger=0) { if ($user->rights->commande->creer) { - dol_syslog(get_class($this).'::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET'; $sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); $sql.= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->ref_client = $ref_client; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->lasterror(); - return -2; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2413,10 +2698,11 @@ class Commande extends CommonOrder /** * Classify the order as invoiced * - * @param User $user Object user making the change - * @return int <0 if KO, >0 if OK + * @param User $user Object user making the change + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function classifyBilled(User $user) + function classifyBilled(User $user, $notrigger=0) { global $user; $error = 0; @@ -2429,16 +2715,24 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG); if ($this->db->query($sql)) { - // Call trigger - $result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user); - if ($result < 0) $error++; - // End call triggers if (! $error) { + $this->oldcopy= clone $this; $this->facturee=1; // deprecated $this->billed=1; + } + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { $this->db->commit(); return 1; } @@ -2485,25 +2779,32 @@ class Commande extends CommonOrder { global $conf, $user, $langs; $error = 0; - + $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 0'; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; - + dol_syslog(get_class($this)."::classifyUnBilled", LOG_DEBUG); if ($this->db->query($sql)) { + if (! $error) + { + $this->oldcopy= clone $this; + $this->facturee=1; // deprecated + $this->billed=1; + } + // Call trigger $result=$this->call_trigger('ORDER_CLASSIFY_UNBILLED',$user); if ($result < 0) $error++; // End call triggers - + if (! $error) { $this->facturee=0; // deprecated $this->billed=0; - + $this->db->commit(); return 1; } @@ -2525,8 +2826,8 @@ class Commande extends CommonOrder return -1; } } - - + + /** * Update a line in database * @@ -2589,7 +2890,7 @@ class Commande extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -2602,14 +2903,14 @@ class Commande extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) $price = $pu; - if ($price_base_type == 'TTC') + if ($price_base_type == 'TTC') { $subprice = $tabprice[5]; - } - else + } + else { $subprice = $pu; } @@ -2691,7 +2992,7 @@ class Commande extends CommonOrder $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // TODO deprecated $this->line->price=$price; $this->line->remise=$remise; @@ -3310,7 +3611,7 @@ class Commande extends CommonOrder $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -3442,7 +3743,7 @@ class Commande extends CommonOrder return max($this->date_commande, $this->date_livraison) < ($now - $conf->commande->client->warning_delay); } - + /** * Show the customer delayed info * @@ -3451,11 +3752,11 @@ class Commande extends CommonOrder public function showDelay() { global $conf, $langs; - + if (empty($this->date_livraison)) $text=$langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); else $text=$text=$langs->trans("DeliveryDate").' '.dol_print_date($this->date_livraison, 'day'); $text.=' '.($conf->commande->client->warning_delay>0?'+':'-').' '.round(abs($conf->commande->client->warning_delay)/3600/24,1).' '.$langs->trans("days").' < '.$langs->trans("Today"); - + return $text; } } @@ -3884,13 +4185,13 @@ class OrderLine extends CommonOrderLine $sql.= " , fk_parent_line=".(! empty($this->fk_parent_line)?$this->fk_parent_line:"null"); if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0ebe4f9b6ac..8af740acc6e 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -59,63 +59,63 @@ class Facture extends CommonInvoice */ protected $table_ref_field = 'facnumber'; - var $socid; + public $socid; - var $author; - var $fk_user_author; - var $fk_user_valid; - var $date; // Date invoice - var $date_creation; // Creation date - var $date_validation; // Validation date - var $datem; - var $ref_client; - var $ref_int; + public $author; + public $fk_user_author; + public $fk_user_valid; + public $date; // Date invoice + public $date_creation; // Creation date + public $date_validation; // Validation date + public $datem; + public $ref_client; + public $ref_int; //Check constants for types - var $type = self::TYPE_STANDARD; + public $type = self::TYPE_STANDARD; //var $amount; - var $remise_absolue; - var $remise_percent; - var $total_ht=0; - var $total_tva=0; - var $total_ttc=0; - var $revenuestamp; + public $remise_absolue; + public $remise_percent; + public $total_ht=0; + public $total_tva=0; + public $total_ttc=0; + public $revenuestamp; //! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon //! Fermeture alors que aucun paiement: replaced (si remplace), abandon - var $close_code; + public $close_code; //! Commentaire si mis a paye sans paiement complet - var $close_note; + public $close_note; //! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code) - var $paye; + public $paye; //! id of source invoice if replacement invoice or credit note - var $fk_facture_source; - var $linked_objects=array(); - var $date_lim_reglement; - var $cond_reglement_code; // Code in llx_c_paiement - var $mode_reglement_code; // Code in llx_c_paiement - var $fk_bank; // Field to store bank id to use when payment mode is withdraw + public $fk_facture_source; + public $linked_objects=array(); + public $date_lim_reglement; + public $cond_reglement_code; // Code in llx_c_paiement + public $mode_reglement_code; // Code in llx_c_paiement + public $fk_bank; // Field to store bank id to use when payment mode is withdraw /** * @deprecated */ - var $products=array(); + public $products=array(); /** * @var FactureLigne[] */ - var $lines=array(); - var $line; - var $extraparams=array(); - var $specimen; + public $lines=array(); + public $line; + public $extraparams=array(); + public $specimen; - var $fac_rec; + public $fac_rec; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * @var int Situation cycle reference number @@ -142,6 +142,8 @@ class Facture extends CommonInvoice */ public $tab_next_situation_invoice=array(); + public $oldcopy; + /** * Standard invoice */ @@ -1486,25 +1488,60 @@ class Facture extends CommonInvoice * Set customer ref * * @param string $ref_client Customer ref + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_ref_client($ref_client) + function set_ref_client($ref_client, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; if (empty($ref_client)) $sql .= ' SET ref_client = NULL'; else $sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\''; $sql .= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql)) + + dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) { $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + + $this->ref_client = $ref_client; + + $this->db->commit(); return 1; } else { - dol_print_error($this->db); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2070,7 +2107,7 @@ class Facture extends CommonInvoice $i++; } if ($final) { - $this->setFinal(); + $this->setFinal($user); } } } @@ -2760,9 +2797,10 @@ class Facture extends CommonInvoice * * @param User $user User that set discount * @param double $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise($user, $remise) + function set_remise($user, $remise, $notrigger=0) { // Clean parameters if (empty($remise)) $remise=0; @@ -2771,21 +2809,48 @@ class Facture extends CommonInvoice { $remise=price2num($remise); + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql.= ' SET remise_percent = '.$remise; $sql.= ' WHERE rowid = '.$this->id; $sql.= ' AND fk_statut = '.self::STATUS_DRAFT; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) { $this->remise_percent = $remise; $this->update_price(1); + + $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2796,14 +2861,19 @@ class Facture extends CommonInvoice * * @param User $user User that set discount * @param double $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { if (empty($remise)) $remise=0; if ($user->rights->facture->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; @@ -2811,18 +2881,43 @@ class Facture extends CommonInvoice $sql.= ' WHERE rowid = '.$this->id; $sql.= ' AND fk_statut = '.self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG); - - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; $this->remise_absolue = $remise; $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -3819,25 +3914,49 @@ class Facture extends CommonInvoice /** * Sets the invoice as a final situation * - * @return int 1 if ok, -1 if error + * @param User $user Object user + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function setFinal() + function setFinal(User $user, $notrigger=0) { + $error=0; - $this->db->begin(); + $this->db->begin(); $this->situation_final = 1; - $sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id; - $resql = $this->db->query($sql); - if ($resql) { - // FIXME: call triggers MODIFY because we modify invoice + $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id; + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { $this->db->commit(); return 1; - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this) . "::update Error setFinal " . $sql, LOG_ERR); + } + else + { + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } $this->db->rollback(); - return -1; + return -1*$error; } } diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index a2232358a99..77a951eef06 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -904,7 +904,7 @@ else // Statut print '
'.$langs->trans("Status").''; + print ''; print $object->getLibStatut(4); print '
'.$langs->trans('None').'
'.$langs->trans('NoRecordFound').'
trans("Port"); ?> value=""> @@ -484,9 +484,27 @@ if (! empty($force_install_message)) '."\n"; diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index a28ed69ab23..40956532b54 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -95,6 +95,8 @@ if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $projectid, 'projet&project'); +$hookmanager->initHooks(array('projectOverview')); + /* * View */ @@ -350,6 +352,15 @@ $listofreferent=array( 'test'=>$conf->projet->enabled && $user->rights->projet->lire && $conf->salaries->enabled && empty($conf->global->PROJECT_HIDE_TASKS)), ); +$parameters=array('listofreferent'=>$listofreferent); +$resHook = $hookmanager->executeHooks('completeListOfReferent',$parameters,$object,$action); + +if(!empty($hookmanager->resArray)) { + + $listofreferent = array_merge($listofreferent, $hookmanager->resArray); + +} + if ($action=="addelement") { $tablename = GETPOST("tablename"); @@ -438,6 +449,7 @@ foreach ($listofreferent as $key => $value) $element = new $classname($db); $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee); + if (count($elementarray)>0 && is_array($elementarray)) { $total_ht = 0; @@ -453,7 +465,7 @@ foreach ($listofreferent as $key => $value) $element->fetch($idofelement); if ($idofelementuser) $elementuser->fetch($idofelementuser); - if ($tablename != 'expensereport_det') $element->fetch_thirdparty(); + if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty(); if ($tablename == 'don') $total_ht_by_line=$element->amount; elseif ($tablename == 'projet_task') @@ -679,7 +691,7 @@ foreach ($listofreferent as $key => $value) if ($tablename != 'expensereport_det') { - $element->fetch_thirdparty(); + if(method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty(); } else { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 21bfed210fb..2367d4b87f5 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1025,7 +1025,7 @@ class Societe extends CommonObject $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $sql .= ', s.webservices_url, s.webservices_key'; $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; - $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj'; + $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj'; $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo'; $sql .= ', s.fk_shipping_method'; $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms'; @@ -1157,7 +1157,8 @@ class Societe extends CommonObject $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier; $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier; $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; - + $this->fk_account = $obj->fk_account; + $this->client = $obj->client; $this->fournisseur = $obj->fournisseur; diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index cf7163671a3..f47260ccec3 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -28,7 +28,9 @@ CKEDITOR.editorConfig = function( config ) config.toolbar_Full = [ - ['Source','-','Save','NewPage','Preview','-','Templates'], + ['Templates','NewPage'], + ['Save'], + ['Source','Maximize','Preview'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 761ce42e0f5..7453a6b1b2f 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -603,6 +603,12 @@ div.myavailability { .minwidth300 { min-width: 300px; } .minwidth400 { min-width: 400px; } .minwidth500 { min-width: 500px; } +.minwidth50imp { min-width: 50px !important; } +.minwidth100imp { min-width: 100px !important; } +.minwidth200imp { min-width: 200px !important; } +.minwidth300imp { min-width: 300px !important; } +.minwidth400imp { min-width: 400px !important; } +.minwidth500imp { min-width: 500px !important; } .maxwidth100 { max-width: 100px; } .maxwidth150 { max-width: 150px; } .maxwidth200 { max-width: 200px; } diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index cf7163671a3..f47260ccec3 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -28,7 +28,9 @@ CKEDITOR.editorConfig = function( config ) config.toolbar_Full = [ - ['Source','-','Save','NewPage','Preview','-','Templates'], + ['Templates','NewPage'], + ['Save'], + ['Source','Maximize','Preview'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], diff --git a/htdocs/theme/md/img/info.png b/htdocs/theme/md/img/info.png index bb6095bd00a..a5af4a11e3c 100644 Binary files a/htdocs/theme/md/img/info.png and b/htdocs/theme/md/img/info.png differ diff --git a/htdocs/theme/md/img/title_accountancy.png b/htdocs/theme/md/img/title_accountancy.png index f83b7635712..1159e6b8d43 100644 Binary files a/htdocs/theme/md/img/title_accountancy.png and b/htdocs/theme/md/img/title_accountancy.png differ diff --git a/htdocs/theme/md/img/title_products.png b/htdocs/theme/md/img/title_products.png index 142d71505c8..79c42a93647 100644 Binary files a/htdocs/theme/md/img/title_products.png and b/htdocs/theme/md/img/title_products.png differ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 92234aeddf3..17695a2adc4 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -601,6 +601,12 @@ div.myavailability { .minwidth300 { min-width: 300px; } .minwidth400 { min-width: 400px; } .minwidth500 { min-width: 500px; } +.minwidth50imp { min-width: 50px !important; } +.minwidth100imp { min-width: 100px !important; } +.minwidth200imp { min-width: 200px !important; } +.minwidth300imp { min-width: 300px !important; } +.minwidth400imp { min-width: 400px !important; } +.minwidth500imp { min-width: 500px !important; } .maxwidth100 { max-width: 100px; } .maxwidth150 { max-width: 150px; } .maxwidth200 { max-width: 200px; } @@ -746,7 +752,7 @@ td.showDragHandle { margin-left: 0; } div.login_block { - border-right: none ! important; + /* border-right: none ! important; */ top: inherit !important; } .side-nav { @@ -771,6 +777,7 @@ div.login_block { #id-left { z-index: 201; background: #FFF; + border-right: 1px solid rgba(0,0,0,0.3); global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { ?> top: 50px ! important; @@ -2664,7 +2671,7 @@ div.tabBar .noborder { } span.boxstatstext { - opacity: 0.9; + /* opacity: 0.9; Disabled. This make text on top of left menu in smartphone size */ line-height: 18px; } span.boxstatsindicator { diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index e87e830bb77..a3760a792ce 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -85,6 +85,12 @@ class Website extends CommonObject * @var integer */ public $fk_default_home; + /** + * @var string + */ + public $virtualhost; + + public $records; /** @@ -143,7 +149,8 @@ class Website extends CommonObject $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; - $sql.= 'fk_default_home,'; + $sql.= 'fk_default_home,'; + $sql.= 'virtualhost,'; $sql.= 'date_creation,'; $sql.= 'date_modification'; @@ -154,6 +161,7 @@ class Website extends CommonObject $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; $sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).','; + $sql .= ' '.(! isset($this->virtualhost)?'NULL':$this->virtualhost).','; $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); @@ -214,6 +222,7 @@ class Website extends CommonObject $sql .= " t.description,"; $sql .= " t.status,"; $sql .= " t.fk_default_home,"; + $sql .= " t.virtualhost,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -237,6 +246,7 @@ class Website extends CommonObject $this->description = $obj->description; $this->status = $obj->status; $this->fk_default_home = $obj->fk_default_home; + $this->virtualhost = $obj->virtualhost; $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_modification = $this->db->jdate($obj->date_modification); $this->tms = $this->db->jdate($obj->tms); @@ -281,7 +291,8 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; - $sql .= " t.fk_default_home,"; + $sql .= " t.fk_default_home,"; + $sql .= " t.virtualhost,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -321,6 +332,7 @@ class Website extends CommonObject $line->description = $obj->description; $line->status = $obj->status; $line->fk_default_home = $obj->fk_default_home; + $line->virtualhost = $obj->virtualhost; $line->date_creation = $this->db->jdate($obj->date_creation); $line->date_modification = $this->db->jdate($obj->date_modification); $line->tms = $this->db->jdate($obj->tms); @@ -380,6 +392,7 @@ class Website extends CommonObject $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; $sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").','; + $sql .= ' virtualhost = '.(($this->virtualhost != '')?$this->virtualhost:"null").','; $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); @@ -627,6 +640,7 @@ class Website extends CommonObject $this->description = 'A specimen website'; $this->status = ''; $this->fk_default_home = null; + $this->virtualhost = 'http://myvirtualhost'; $this->date_creation = dol_now(); $this->date_modification = dol_now(); $this->tms = dol_now(); @@ -665,6 +679,10 @@ class WebsiteLine * @var int */ public $fk_default_home; + /** + * @var string + */ + public $virtualhost; /** * @var mixed */ diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 19f72486c3f..188a3fa7ce6 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -454,6 +454,8 @@ print '
'; if (count($object->records) > 0) { + // ***** Part for web sites + print '
'; print $langs->trans("Website").': '; print '
'; @@ -478,15 +480,56 @@ if (count($object->records) > 0) } $out.=''; print $out; - print ''; + print ''; if ($website) { - print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + $dataroot=DOL_DATA_ROOT.'/websites/'.$website; + if (! empty($object->virtualhost)) $realurl=$object->virtualhost; + // TODO If virtual url defined, we use it + + /*print ' - '.$langs->trans("RealURL").' '; print ' '; - print ''.$langs->trans("ViewSiteInNewTab").''; + print ''.$langs->trans("ViewSiteInNewTab").'';*/ + + print '   '; + + print $langs->trans("ViewWebsiteInProduction").': '; + print ''; + //print ''; + $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); + print $form->textwithpicto('', $htmltext); + print ''.$langs->trans("ViewSiteInNewTab").''; + + // Example : Adding jquery code + if (! empty($conf->use_javascript_ajax)) + { + print ''; + } } + print '
'; // Button for websites @@ -513,7 +556,8 @@ if (count($object->records) > 0) print ''; - // Part for pages + // ***** Part for pages + if ($website) { print ''; @@ -555,7 +599,7 @@ if (count($object->records) > 0) else $out.=''; $out.=''; print $out; - print ''; + print ''; print ''; //print $form->selectarray('page', $array); @@ -563,8 +607,9 @@ if (count($object->records) > 0) { print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; - print ' '; - print ''.$langs->trans("ViewPageInNewTab").''; + print ' '; + print ''.$langs->trans("ViewPageInNewTab").''; + //print ''; } print ''; diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php index 7c14b0ccd64..364eaf7568d 100644 --- a/test/phpunit/ExportTest.php +++ b/test/phpunit/ExportTest.php @@ -120,9 +120,96 @@ class ExportTest extends PHPUnit_Framework_TestCase } + /** + * Other tests + * + * @return void + */ + public function testExportOther() + { + global $conf,$user,$langs,$db; + + $model='csv'; + + // Creation of class to export using model ExportXXX + $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; + $file = "export_".$model.".modules.php"; + $classname = "Export".$model; + require_once $dir.$file; + $objmodel = new $classname($this->db); + + // First test without option USE_STRICT_CSV_RULES + unset($conf->global->USE_STRICT_CSV_RULES); + + $valtotest='A simple string'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'A simple string'); + + $valtotest='A string with , and ; inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with , and ; inside"'); + + $valtotest='A string with " inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside"'); + + $valtotest='A string with " inside and '."\r\n".' carriage returns'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside and \n carriage returns"'); + + $valtotest='A string with html
content
inside
'."\n"; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with html
content
inside"'); + + // Same tests with strict mode + $conf->global->USE_STRICT_CSV_RULES=1; + + $valtotest='A simple string'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'A simple string'); + + $valtotest='A string with , and ; inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with , and ; inside"'); + + $valtotest='A string with " inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside"'); + + $valtotest='A string with " inside and '."\r\n".' carriage returns'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "\"A string with \"\" inside and \r\n carriage returns\""); + + $valtotest='A string with html
content
inside
'."\n"; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with html
content
inside"'); + + } + /** * Test export function for a personalized dataset * + * @depends testExportOther * @return void */ public function testExportPersonalizedExport() @@ -266,4 +353,5 @@ class ExportTest extends PHPUnit_Framework_TestCase return true; } + } diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index ce3275bb58e..470bcbf4900 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -54,7 +54,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savlangs; protected $savdb; protected $soapclient; - protected $socid; + + private static $socid; protected $ns = 'http://www.dolibarr.org/ns/'; @@ -72,10 +73,9 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; - // Set the WebService URL + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; $this->soapclient = new nusoap_client($WS_DOL_URL); if ($this->soapclient) @@ -84,7 +84,28 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $this->soapclient->decodeUTF8(false); } - // create third_parties, needed to test an invoice + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + + // create a third_party, needed to create an invoice + // + // The third party is created in setUpBeforeClass() and not in the + // constructor to avoid creating several objects (the constructor is + // called for each test). + // + // The third party must be created before beginning the DB transaction + // because there is a foreign key constraint between invoices and third + // parties (tables: lx_facture and llx_societe) and with MySQL, + // constraints are checked immediately, they are not deferred to + // transaction commit. So if the invoice is created in the same + // transaction than the third party, the FK constraint fails. + // See this post for more detail: http://stackoverflow.com/a/5014744/5187108 $societe=new Societe($db); $societe->ref=''; $societe->name='name'; @@ -97,24 +118,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $societe->particulier=0; $societe->create($user); - - $this->socid = $societe->id; - + + self::$socid = $societe->id; print __METHOD__." societe created id=".$societe->id."\n"; - print __METHOD__." db->type=".$db->type." user->id=".$user->id; - //print " - db ".$db->db; - print "\n"; - } - - // Static methods - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; + print __METHOD__."\n"; } + public static function tearDownAfterClass() { global $conf,$user,$langs,$db; @@ -135,9 +147,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + print __METHOD__."\n"; - } /** @@ -166,17 +177,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $WS_METHOD = 'createInvoice'; - // load societe first - /*$societe=new Societe($db); - $societe->fetch('', '', 'ref-phpunit'); - print __METHOD__." societe loaded id=".$societe->id."\n"; - */ - $body = array ( "id" => NULL, "ref" => NULL, "ref_ext" => "ref-phpunit-2", - "thirdparty_id" => $this->socid, + "thirdparty_id" => self::$socid, "fk_user_author" => NULL, "fk_user_valid" => NULL, "date" => "2015-04-19 20:16:53", @@ -333,7 +338,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "id" => NULL, "ref" => NULL, "ref_ext" => "ref-phpunit-2", - "thirdparty_id" => $this->socid, + "thirdparty_id" => self::$socid, "fk_user_author" => NULL, "fk_user_valid" => NULL, "date" => "2015-04-19 20:16:53",