From 03eadcebf1c636cb8a9d4c5945d33d5929c8f082 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Mon, 19 Jun 2017 12:25:00 +0200 Subject: [PATCH 01/16] FIX: User id correction on holiday request --- htdocs/holiday/card.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 8cae9592033..d9e651953c5 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -3,7 +3,7 @@ * Copyright (C) 2012-2015 Laurent Destailleur * Copyright (C) 2012-2016 Regis Houssin * Copyright (C) 2013 Juanjo Menent - * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2014-2017 Ferran Marcet * * 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 @@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; $myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); -$userid = GETPOST('userid')?GETPOST('userid'):$user->id; +$userID = GETPOST('userID')?GETPOST('userID'):$user->id; // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -57,6 +57,7 @@ if ($action == 'create') $cp = new Holiday($db); // If no right to create a request + $userid = GETPOST('userid'); if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) { $error++; @@ -82,7 +83,6 @@ if ($action == 'create') $valideur = GETPOST('valideur'); $description = trim(GETPOST('description')); - $userID = GETPOST('userID'); // If no type if ($type <= 0) @@ -112,7 +112,7 @@ if ($action == 'create') } // Check if there is already holiday for this period - $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); + $verifCP = $cp->verifDateHolidayCP($userid, $date_debut, $date_fin, $halfday); if (! $verifCP) { header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=alreadyCP'); @@ -762,7 +762,7 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create // Formulaire de demande print '
'."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; dol_fiche_head(); From c4546b6da6b7ca71b5f640184b22b3d0394b8139 Mon Sep 17 00:00:00 2001 From: fmarcet Date: Mon, 19 Jun 2017 16:23:44 +0200 Subject: [PATCH 02/16] FIX: User id correction on holiday request --- htdocs/holiday/card.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index d9e651953c5..5789cf27180 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -39,7 +39,6 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; $myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); -$userID = GETPOST('userID')?GETPOST('userID'):$user->id; // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -57,8 +56,8 @@ if ($action == 'create') $cp = new Holiday($db); // If no right to create a request - $userid = GETPOST('userid'); - if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) + $fuserid = GETPOST('fuserid'); + if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) { $error++; setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); @@ -112,7 +111,7 @@ if ($action == 'create') } // Check if there is already holiday for this period - $verifCP = $cp->verifDateHolidayCP($userid, $date_debut, $date_fin, $halfday); + $verifCP = $cp->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday); if (! $verifCP) { header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=alreadyCP'); @@ -140,7 +139,7 @@ if ($action == 'create') if (! $error) { - $cp->fk_user = $userid; + $cp->fk_user = $fuserid; $cp->description = $description; $cp->date_debut = $date_debut; $cp->date_fin = $date_fin; @@ -682,7 +681,7 @@ llxHeader(array(),$langs->trans('CPTitreMenu')); if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') { // Si l'utilisateur n'a pas le droit de faire une demande - if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) + if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) { $errors[]=$langs->trans('CantCreateCP'); } @@ -762,7 +761,6 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create // Formulaire de demande print ''."\n"; print ''."\n"; - print ''."\n"; dol_fiche_head(); @@ -793,10 +791,10 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; if (empty($user->rights->holiday->write_all)) { - print $form->select_dolusers($userid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - print ''; + print $form->select_dolusers($fuserid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + print ''; } - else print $form->select_dolusers(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); + else print $form->select_dolusers(GETPOST('fuserid')?GETPOST('fuserid'):$user->id,'fuserid',0,'',0); print ''; print ''; From f694939fc74e81d823be4c56b51d66f64d793abb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Jun 2017 19:39:37 +0200 Subject: [PATCH 03/16] Fix migration with pgsql --- htdocs/install/mysql/migration/3.5.0-3.6.0.sql | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql index bd04766eebf..3d83d2a7af9 100644 --- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql +++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql @@ -63,7 +63,7 @@ ALTER TABLE llx_bookmark ADD COLUMN entity integer DEFAULT 1 NOT NULL; ALTER TABLE llx_bookmark MODIFY COLUMN url varchar(255) NOT NULL; -ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01-01 00:00:00'; +-- VMYSQL4.1 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01-01 00:00:00'; -- Clean corrupted values for tms -- VMYSQL4.1 SET sql_mode = 'ALLOW_INVALID_DATES'; @@ -74,7 +74,7 @@ ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01- -- VMYSQL4.3 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN date_fin DATETIME NULL DEFAULT NULL; -- VPGSQL8.2 ALTER TABLE llx_opensurvey_sondage ALTER COLUMN date_fin DROP NOT NULL; -ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP; +-- VMYSQL4.1 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP; ALTER TABLE llx_opensurvey_sondage ADD COLUMN entity integer DEFAULT 1 NOT NULL; @@ -204,9 +204,14 @@ CREATE TABLE llx_payment_salary ( fk_user_modif integer )ENGINE=innodb; + +DELETE FROM llx_product_batch where fk_product_stock NOT IN (SELECT rowid from llx_product_stock); + ALTER TABLE llx_product_batch ADD INDEX idx_fk_product_stock (fk_product_stock); ALTER TABLE llx_product_batch ADD CONSTRAINT fk_product_batch_fk_product_stock FOREIGN KEY (fk_product_stock) REFERENCES llx_product_stock (rowid); +DELETE FROM llx_expeditiondet_batch where fk_expeditiondet NOT IN (SELECT rowid from llx_expeditiondet); + ALTER TABLE llx_expeditiondet_batch ADD INDEX idx_fk_expeditiondet (fk_expeditiondet); ALTER TABLE llx_expeditiondet_batch ADD CONSTRAINT fk_expeditiondet_batch_fk_expeditiondet FOREIGN KEY (fk_expeditiondet) REFERENCES llx_expeditiondet(rowid); From 99c78675222640e1890c678ba0fbc13fc64ee4ad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Jun 2017 12:06:01 +0200 Subject: [PATCH 04/16] Fix travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb6b774d9ab..60343805fcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ php: - '5.3' - '5.4' - '5.5' -- '5.6' +- '5.6.29' - '7.0' - nightly From 65b9b70ff8ad62147bf5186ac07a9e3ac3a67ee2 Mon Sep 17 00:00:00 2001 From: arnaud Date: Tue, 27 Jun 2017 15:23:51 +0200 Subject: [PATCH 05/16] FIX invoice page list --- htdocs/compta/facture/list.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 14a5c484e8c..e37f5b316fc 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -551,7 +551,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $nbtotalofrecords = $db->num_rows($result); } -$sql.= $db->plimit($limit,$offset); +$sql.= $db->plimit($limit + 1,$offset); //print $sql; $resql = $db->query($sql); @@ -591,7 +591,6 @@ if ($resql) $i = 0; print ''."\n"; - print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num,$nbtotalofrecords,'title_accountancy.png'); if ($massaction == 'presend') From 4283b1ee30b294b975c34236897a0944a6901371 Mon Sep 17 00:00:00 2001 From: fmarcet Date: Wed, 28 Jun 2017 18:31:37 +0200 Subject: [PATCH 06/16] FIX: User id correction on holiday request --- htdocs/holiday/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 5789cf27180..44ec0496f7b 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -792,7 +792,7 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create if (empty($user->rights->holiday->write_all)) { print $form->select_dolusers($fuserid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - print ''; + print ''; } else print $form->select_dolusers(GETPOST('fuserid')?GETPOST('fuserid'):$user->id,'fuserid',0,'',0); print ''; From a695fa9c6e448c3be77c55321f3584b6a95fc1d0 Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 29 Jun 2017 14:36:10 +0200 Subject: [PATCH 07/16] FIX holidays with postgresql like on rowid integer --- htdocs/holiday/list.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 90db40fd2e7..53430f0b6e1 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -70,7 +70,6 @@ $type = GETPOST('type','int'); // List of fields to search into when doing a "search in all" $fieldstosearchall = array( - 'cp.rowid'=>'Ref', 'cp.description'=>'Description', 'uu.lastname'=>'EmployeeLastname', 'uu.firstname'=>'EmployeeFirstname' @@ -124,7 +123,7 @@ $order = $db->order($sortfield,$sortorder).$db->plimit($limit + 1, $offset); // WHERE if(!empty($search_ref)) { - $filter.= " AND cp.rowid LIKE '%".$db->escape($search_ref)."%'\n"; + $filter.= " AND cp.rowid = ".$db->escape($search_ref); } // DATE START From 6e8c83b2a960cc5f2c9e33a1e9ce7ba19c3eeb96 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 29 Jun 2017 15:47:33 +0200 Subject: [PATCH 08/16] fix class error (given by eclipse Oxygen version) --- .../accountancy/class/bookkeeping.class.php | 434 +++++++++--------- .../compta/paiement/class/cpaiement.class.php | 42 +- 2 files changed, 238 insertions(+), 238 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 8f31b40bc54..c5f2e9d8696 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -53,19 +53,19 @@ 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'; + + public $entity = 1; - - + + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - - + + /** * * @var int ID @@ -89,10 +89,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -101,7 +101,7 @@ class BookKeeping extends CommonObject public function __construct(DoliDB $db) { $this->db = $db; } - + /** * Create object into database * @@ -111,11 +111,11 @@ class BookKeeping extends CommonObject */ public function create(User $user, $notrigger = false) { global $conf, $langs; - + dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); @@ -164,7 +164,7 @@ class BookKeeping extends CommonObject } if (empty($this->debit)) $this->debit = 0; if (empty($this->credit)) $this->credit = 0; - + // Check parameters if (empty($this->numero_compte) || $this->numero_compte == '-1') { @@ -175,40 +175,40 @@ class BookKeeping extends CommonObject } else { - $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type); + $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type); } - + return -1; } - - + + $this->db->begin(); - + $this->piece_num = 0; - + // First check if line not yet already in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; $sql .= " AND fk_doc = " . $this->fk_doc; - $sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines + $sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); - if ($row->nb == 0) + 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 . "'"; // For example doc_type = 'bank' + $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; // For example doc_type = 'bank' $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ... $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; // ref of source object $sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -220,7 +220,7 @@ class BookKeeping extends CommonObject $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -232,12 +232,12 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $this->piece_num = 1; } - + $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"; @@ -255,7 +255,7 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - $sql .= ', entity'; + $sql .= ', entity'; $sql .= ") VALUES ("; $sql .= "'" . $this->db->idate($this->doc_date) . "'"; $sql .= ",'" . $this->doc_type . "'"; @@ -275,12 +275,12 @@ class BookKeeping extends CommonObject $sql .= "," . $this->piece_num; $sql .= ", " . (! isset($this->entity) ? '1' : $this->entity); $sql .= ")"; - + 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; @@ -308,20 +308,20 @@ class BookKeeping extends CommonObject $this->errors[] = 'Error ' . $this->db->lasterror(); 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(); @@ -331,7 +331,7 @@ class BookKeeping extends CommonObject return $result; } } - + /** * Create object into database * @@ -341,11 +341,11 @@ class BookKeeping extends CommonObject */ 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); } @@ -393,10 +393,10 @@ class BookKeeping extends CommonObject } if (empty($this->debit)) $this->debit = 0; if (empty($this->credit)) $this->credit = 0; - + // 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,'; @@ -435,55 +435,55 @@ class BookKeeping extends CommonObject $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->piece_num).','; $sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity); $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) { global $conf; - + dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.doc_date,"; @@ -510,15 +510,15 @@ class BookKeeping extends CommonObject } else { $sql .= ' AND 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; @@ -537,7 +537,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -546,11 +546,11 @@ 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 * @@ -560,14 +560,14 @@ 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 fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; - + dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.doc_date,"; @@ -620,18 +620,18 @@ class BookKeeping extends CommonObject } 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; @@ -648,21 +648,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 * @@ -672,14 +672,14 @@ 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') { global $conf; - + dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.doc_date,"; @@ -723,7 +723,7 @@ class BookKeeping extends CommonObject if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -731,16 +731,16 @@ 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; @@ -757,20 +757,20 @@ 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 * @@ -785,9 +785,9 @@ class BookKeeping extends CommonObject */ public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; - + dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= " t.numero_compte,"; $sql .= " SUM(t.debit) as debit,"; @@ -817,55 +817,55 @@ class BookKeeping extends CommonObject if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); + $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); } @@ -911,10 +911,10 @@ 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') . ','; @@ -934,69 +934,69 @@ class BookKeeping extends CommonObject $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 ++; @@ -1004,19 +1004,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 * @@ -1025,25 +1025,25 @@ 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(); dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR); $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -1053,14 +1053,14 @@ class BookKeeping extends CommonObject */ function deleteByYearAndJournal($delyear='', $journal='') { global $conf; - - if (empty($delyear) && empty($journal)) + + if (empty($delyear) && empty($journal)) { return -1; } - + $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element; @@ -1069,7 +1069,7 @@ class BookKeeping extends CommonObject if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1079,11 +1079,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return -1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by piece number * @@ -1092,17 +1092,17 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { global $conf; - + $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; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1112,57 +1112,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); - + $object = new BookKeeping($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 @@ -1171,9 +1171,9 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { global $user; - + $now=dol_now(); - + $this->id = 0; $this->doc_date = $now; $this->doc_type = ''; @@ -1192,7 +1192,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1201,17 +1201,17 @@ class BookKeeping extends CommonObject */ public function fetchPerMvt($piecenum) { global $conf; - + $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; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + 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); @@ -1222,22 +1222,22 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * * @return string Next numero to use */ - public function getNextNumMvt() + public function getNextNumMvt() { global $conf; - + $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); @@ -1252,7 +1252,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1261,7 +1261,7 @@ class BookKeeping extends CommonObject */ function fetch_all_per_mvt($piecenum) { global $conf; - + $sql = "SELECT rowid, doc_date, doc_type,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $sql .= " numero_compte, label_compte, debit, credit,"; @@ -1269,17 +1269,17 @@ class BookKeeping extends CommonObject $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + 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; @@ -1294,7 +1294,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 { @@ -1302,10 +1302,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1314,27 +1314,27 @@ class BookKeeping extends CommonObject */ function export_bookkeping($model = 'ebp') { global $conf; - + $sql = "SELECT rowid, doc_date, doc_type,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $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; $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; - + 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; @@ -1349,11 +1349,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(); @@ -1361,9 +1361,9 @@ class BookKeeping extends CommonObject return - 1; } } - - - + + + /** * Return list of accounts with label by chart of accounts * @@ -1378,11 +1378,11 @@ class BookKeeping extends CommonObject */ 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"; @@ -1391,82 +1391,82 @@ class BookKeeping extends CommonObject $sql .= " AND asy.rowid = " . $pcgver; $sql .= " AND ab.entity IN (" . getEntity("accountancy", 1) . ")"; $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; - + $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 a root accounting account + * Description of a root accounting account * * @param string $account Accounting account * @return string Root account */ function get_compte_racine($account = null) - { + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; - + $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 .= " WHERE aa.account_number = '" . $account . "'"; $sql .= " AND parent.active = 1"; $sql .= " AND root.active = 1"; $sql .= " AND aa.entity IN (" . getEntity("accountancy", 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); + $obj = $this->db->fetch_object($resql); } - + return $obj->label; - + } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); @@ -1474,8 +1474,8 @@ class BookKeeping extends CommonObject return -1; } } - - + + /** * Description of accounting account * @@ -1483,9 +1483,9 @@ class BookKeeping extends CommonObject * @return string Account desc */ 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 "; @@ -1495,20 +1495,20 @@ class BookKeeping extends CommonObject $sql .= " AND aa.active = 1"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; $sql .= " WHERE aa.entity IN (" . getEntity("accountancy", 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); + $obj = $this->db->fetch_object($resql); } - - if(empty($obj->category)){ + + if(empty($obj->category)){ return $obj->label; }else{ return $obj->label.' ('.$obj->category.')'; - + } } else { $this->error = "Error " . $this->db->lasterror(); @@ -1516,7 +1516,7 @@ class BookKeeping extends CommonObject return -1; } } - + } diff --git a/htdocs/compta/paiement/class/cpaiement.class.php b/htdocs/compta/paiement/class/cpaiement.class.php index 5428f4abdbf..c91b7276633 100644 --- a/htdocs/compta/paiement/class/cpaiement.class.php +++ b/htdocs/compta/paiement/class/cpaiement.class.php @@ -46,7 +46,7 @@ class Cpaiement /** */ - + public $code; public $libelle; public $type; @@ -56,7 +56,7 @@ class Cpaiement /** */ - + /** * Constructor @@ -83,7 +83,7 @@ class Cpaiement $error = 0; // Clean parameters - + if (isset($this->code)) { $this->code = trim($this->code); } @@ -103,14 +103,14 @@ class Cpaiement $this->module = trim($this->module); } - + // Check parameters // Put here code to add control on parameters values // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql.= 'id,'; $sql.= 'code,'; $sql.= 'libelle,'; @@ -119,9 +119,9 @@ class Cpaiement $sql.= 'accountancy_code,'; $sql.= 'module'; - + $sql .= ') VALUES ('; - + $sql .= ' '.(! isset($this->id)?'NULL':$this->id).','; $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; $sql .= ' '.(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").','; @@ -130,7 +130,7 @@ class Cpaiement $sql .= ' '.(! isset($this->accountancy_code)?'NULL':"'".$this->db->escape($this->accountancy_code)."'").','; $sql .= ' '.(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'"); - + $sql .= ')'; $this->db->begin(); @@ -202,7 +202,7 @@ class Cpaiement $obj = $this->db->fetch_object($resql); $this->id = $obj->id; - + $this->code = $obj->code; $this->libelle = $obj->libelle; $this->type = $obj->type; @@ -210,7 +210,7 @@ class Cpaiement $this->accountancy_code = $obj->accountancy_code; $this->module = $obj->module; - + } $this->db->free($resql); @@ -252,7 +252,7 @@ class Cpaiement $sql .= " t.accountancy_code,"; $sql .= " t.module"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; // Manage filter @@ -265,7 +265,7 @@ class Cpaiement if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); } - + if (!empty($sortfield)) { $sql .= $this->db->order($sortfield,$sortorder); } @@ -279,10 +279,10 @@ class Cpaiement $num = $this->db->num_rows($resql); while ($obj = $this->db->fetch_object($resql)) { - $line = new CpaiementLine(); + $line = new Cpaiement(); $line->id = $obj->id; - + $line->code = $obj->code; $line->libelle = $obj->libelle; $line->type = $obj->type; @@ -290,7 +290,7 @@ class Cpaiement $line->accountancy_code = $obj->accountancy_code; $line->module = $obj->module; - + $this->lines[$line->id] = $line; } @@ -320,7 +320,7 @@ class Cpaiement dol_syslog(__METHOD__, LOG_DEBUG); // Clean parameters - + if (isset($this->code)) { $this->code = trim($this->code); } @@ -340,7 +340,7 @@ class Cpaiement $this->module = trim($this->module); } - + // Check parameters // Put here code to add a control on parameters values @@ -438,8 +438,8 @@ class Cpaiement return 1; } } - - + + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -449,7 +449,7 @@ class Cpaiement public function initAsSpecimen() { $this->id = 0; - + $this->code = ''; $this->libelle = ''; $this->type = ''; @@ -457,7 +457,7 @@ class Cpaiement $this->accountancy_code = ''; $this->module = ''; - + } } From f79b72f724b67a4a2e7938b9cb56c8ee8d9c179b Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 29 Jun 2017 16:57:30 +0200 Subject: [PATCH 09/16] FIX edit sociale was emptying label --- htdocs/compta/sociales/card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 92cb36059e4..1aecfdbdd08 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -196,7 +196,6 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr { $result=$object->fetch($id); - $object->lib=GETPOST('label'); $object->date_ech=$dateech; $object->periode=$dateperiod; $object->amount=price2num($amount); From ca6ce2ba8b0aa8fcb4568ce74646b13cc3d30393 Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 30 Jun 2017 10:38:54 +0200 Subject: [PATCH 10/16] FIX status were wrong on product referent list --- htdocs/compta/facture/list.php | 8 ++++---- htdocs/product/stats/facture.php | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 1d0a5ad7e9f..4ce8e0ed724 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1431,10 +1431,10 @@ if ($resql) // Status if (! empty($arrayfields['f.fk_statut']['checked'])) { - print ''; - print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type); - print ""; - if (! $i) $totalarray['nbfield']++; + print ''; + print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type); + print ""; + if (! $i) $totalarray['nbfield']++; } // Action column diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index e9eb3d41859..e8fd04ac818 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -141,7 +141,7 @@ if ($id > 0 || ! empty($ref)) elseif ($user->rights->facture->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,"; - $sql.= " f.facnumber, f.datef, f.paye, f.fk_statut as statut, f.rowid as facid,"; + $sql.= " f.facnumber, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,"; $sql.= " d.rowid, d.total_ht as total_ht, d.qty"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; @@ -232,23 +232,24 @@ if ($id > 0 || ! empty($ref)) $var=True; while ($i < min($num,$conf->liste_limit)) { - $objp = $db->fetch_object($result); + $objp = $db->fetch_object($result); + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->facnumber; + $societestatic->fetch($objp->socid); + $paiement = $invoicestatic->getSommePaiement(); $var=!$var; print ''; print ''; - $invoicestatic->id=$objp->facid; - $invoicestatic->ref=$objp->facnumber; print $invoicestatic->getNomUrl(1); print "\n"; - $societestatic->fetch($objp->socid); print ''.$societestatic->getNomUrl(1).''; print "".$objp->code_client."\n"; print ''; print dol_print_date($db->jdate($objp->datef),'day').""; print ''.$objp->qty."\n"; print ''.price($objp->total_ht)."\n"; - print ''.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).''; + print ''.$invoicestatic->LibStatut($objp->paye,$objp->statut,5,$paiement,$objp->type).''; print "\n"; $i++; From e1ae97e66123b1565eb2769d98f199526ac7e2b3 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 4 Jul 2017 10:34:59 +0200 Subject: [PATCH 11/16] Fix return method --- htdocs/contrat/class/contrat.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index a1696c749f8..f1c0f1343b7 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -228,7 +228,7 @@ class Contrat extends CommonObject */ function active_line($user, $line_id, $date, $date_end='', $comment='') { - $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); + return $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); } @@ -243,7 +243,7 @@ class Contrat extends CommonObject */ function close_line($user, $line_id, $date_end, $comment='') { - $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); + return $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); } From 31b94c1d3f13553bfbcc36977d701652b1148d90 Mon Sep 17 00:00:00 2001 From: phf Date: Wed, 5 Jul 2017 16:52:37 +0200 Subject: [PATCH 12/16] Fix 7109 - class name already exist for customer payment --- .../supplier_payment/mod_supplier_payment_brodator.php | 2 +- .../modules/supplier_payment/mod_supplier_payment_bronan.php | 2 +- .../modules/supplier_payment/modules_supplier_payment.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php b/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php index fb06c028aed..97c7b077b22 100644 --- a/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php +++ b/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php @@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_payment/modules_supplier /** * Class to manage customer payment numbering rules Ant */ -class mod_supplier_payment_brodator extends ModeleNumRefPayments +class mod_supplier_payment_brodator extends ModeleNumRefSupplierPayments { var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $error = ''; diff --git a/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php b/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php index e7146e2e1fd..c94ef4296c0 100644 --- a/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php +++ b/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php @@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_payment/modules_supplier /** * Class to manage customer payment numbering rules Cicada */ -class mod_supplier_payment_bronan extends ModeleNumRefPayments +class mod_supplier_payment_bronan extends ModeleNumRefSupplierPayments { var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $prefix='SPAY'; diff --git a/htdocs/core/modules/supplier_payment/modules_supplier_payment.php b/htdocs/core/modules/supplier_payment/modules_supplier_payment.php index c9023a9fc65..526b70145ba 100644 --- a/htdocs/core/modules/supplier_payment/modules_supplier_payment.php +++ b/htdocs/core/modules/supplier_payment/modules_supplier_payment.php @@ -17,11 +17,11 @@ */ /** - * \class ModeleNumRefPayments + * \class ModeleNumRefSupplierPayments * \brief Payment numbering references mother class */ -abstract class ModeleNumRefPayments +abstract class ModeleNumRefSupplierPayments { var $error=''; From a072b23a5e5df764de2a2e08d874d59b25bf3ce6 Mon Sep 17 00:00:00 2001 From: jfefe Date: Thu, 6 Jul 2017 00:47:26 +0200 Subject: [PATCH 13/16] FIX #7075 : bad path for document --- htdocs/fourn/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index bc3c0822207..b46b9fde5cd 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -878,7 +878,7 @@ if (empty($reshook)) } // Actions to build doc - $upload_dir = $conf->commande->dir_output; + $upload_dir = $conf->fournisseur->dir_output.'/commande'; $permissioncreate = $user->rights->fournisseur->commande->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; From a6f1e08c194e7b8f3b3ebf191eaa0f10c57ad7bb Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 7 Jul 2017 11:46:19 +0200 Subject: [PATCH 14/16] FIX : we have to check if contact doesn't already exist on add_contact() function --- htdocs/core/class/commonobject.class.php | 92 ++++++++++++++---------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 2d52a7ee2d1..8e9cdbfc4d5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -599,48 +599,64 @@ abstract class CommonObject } $datecreate = dol_now(); - - $this->db->begin(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= "'".$this->db->idate($datecreate)."'"; - $sql.= ", 4, ". $id_type_contact; - $sql.= ")"; - - $resql=$this->db->query($sql); - if ($resql) - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); - if ($result < 0) + + // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error + $TListeContacts=$this->liste_contact(-1, $source); + $already_added=false; + if(!empty($TListeContacts)) { + foreach($TListeContacts as $array_contact) { + if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { + $already_added=true; + break; + } + } + } + + if(!$already_added) { + + $this->db->begin(); + + // Insertion dans la base + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; + $sql.= "'".$this->db->idate($datecreate)."'"; + $sql.= ", 4, ". $id_type_contact; + $sql.= ")"; + + $resql=$this->db->query($sql); + if ($resql) + { + if (! $notrigger) { + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + } + + $this->db->commit(); + return 1; + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->errno(); + $this->db->rollback(); + echo 'err rollback'; + return -2; + } + else + { + $this->error=$this->db->error(); $this->db->rollback(); return -1; } - } - - $this->db->commit(); - return 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $this->error=$this->db->errno(); - $this->db->rollback(); - return -2; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } + } + } else return 0; } /** From bd0dba6439d57508ff8f4a14cd7ead54e735b88e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 20:14:47 +0200 Subject: [PATCH 15/16] Update card.php Better fix for future --- htdocs/fourn/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index b46b9fde5cd..bbc91bc3871 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -878,7 +878,7 @@ if (empty($reshook)) } // Actions to build doc - $upload_dir = $conf->fournisseur->dir_output.'/commande'; + $upload_dir = $conf->fournisseur->commande->dir_output; $permissioncreate = $user->rights->fournisseur->commande->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; From ba3b6b6aa5d372d41869eb0559d3e8bbfb64d561 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 8 Jul 2017 17:57:35 +0200 Subject: [PATCH 16/16] Better support of vat with code in expense report --- htdocs/commande/class/commande.class.php | 8 +- htdocs/core/lib/functions.lib.php | 2 +- htdocs/expensereport/card.php | 442 +++++++++--------- .../class/expensereport.class.php | 107 +++-- 4 files changed, 308 insertions(+), 251 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 40e258a8e82..c326efa7e49 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1360,10 +1360,10 @@ class Commande extends CommonOrder $this->line->vat_src_code=$vat_src_code; $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$txlocaltax1; - $this->line->localtax2_tx=$txlocaltax2; - $this->line->localtax1_type = $localtaxes_type[0]; - $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->localtax1_tx=$localtaxes_type[1]; + $this->line->localtax2_tx=$localtaxes_type[3]; + $this->line->localtax1_type=$localtaxes_type[0]; + $this->line->localtax2_type=$localtaxes_type[2]; $this->line->fk_product=$fk_product; $this->line->product_type=$product_type; $this->line->fk_remise_except=$fk_remise_except; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5c3d78aa0ee..a12e4c18ba4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3892,7 +3892,7 @@ function getTaxesFromId($vatrowid) * @param Societe $buyer Company object * @param Societe $seller Company object * @param int $firstparamisid 1 if first param is id into table (use this if you can) - * @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type1, rate localtax2, accountancycodecust, accountancycodesupp) + * @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type2, rate localtax2, accountancycodecust, accountancycodesupp) */ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0) { diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 596636c74b0..951659a2b59 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -122,7 +122,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if ($cancel) + if ($cancel) { $action=''; $fk_projet=''; @@ -155,7 +155,7 @@ if (empty($reshook)) { // Because createFromClone modifies the object, we must clone it so that we can restore it later $orig = clone $object; - + $result=$object->createFromClone($socid); if ($result > 0) { @@ -171,7 +171,7 @@ if (empty($reshook)) } } } - + if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer) { $object = new ExpenseReport($db); @@ -187,20 +187,20 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == 'add' && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); - + $object->date_debut = $date_start; $object->date_fin = $date_end; - + $object->fk_user_author = GETPOST('fk_user_author','int'); if (! ($object->fk_user_author > 0)) $object->fk_user_author = $user->id; - + $fuser=new User($db); $fuser->fetch($object->fk_user_author); - + $object->fk_statut = 1; $object->fk_c_paiement = GETPOST('fk_c_paiement','int'); $object->fk_user_validator = GETPOST('fk_user_validator','int'); @@ -212,20 +212,20 @@ if (empty($reshook)) $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error++; } - + if ($object->periode_existe($fuser,$object->date_debut,$object->date_fin)) { $error++; setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors'); $action='create'; } - + if (! $error) { $db->begin(); - + $id = $object->create($user); - + if ($id > 0) { $db->commit(); @@ -240,25 +240,25 @@ if (empty($reshook)) } } } - + if ($action == 'update' && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + $object->date_debut = $date_start; $object->date_fin = $date_end; - + if($object->fk_statut < 3) { $object->fk_user_validator = GETPOST('fk_user_validator','int'); } - + $object->fk_c_paiement = GETPOST('fk_c_paiement','int'); $object->note_public = GETPOST('note_public'); $object->note_private = GETPOST('note_private'); $object->fk_user_modif = $user->id; - + $result = $object->update($user); if ($result > 0) { @@ -270,14 +270,14 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error++; - + if (! $error) { // Actions on extra fields (by external module or standard code) @@ -293,17 +293,17 @@ if (empty($reshook)) } else if ($reshook < 0) $error++; } - + if ($error) $action = 'edit_extras'; } - + if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setValidate($user); - + if ($result > 0) { // Define output language @@ -319,51 +319,51 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0 && $object->fk_user_validator > 0) { $langs->load("mails"); - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - + if ($emailTo && $emailFrom) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->trans("ExpenseReportWaitingForApproval"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link); - + // Rebuild pdf /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); - + if($resultPDF): // ATTACHMENT array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf"); array_push($mimetype,"application/pdf"); */ - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -408,13 +408,13 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->set_save_from_refuse($user); - + if ($result > 0) { // Define output language @@ -430,35 +430,35 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) // TODO Translate this so we can remove condition { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - + if ($emailTo) { // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - + // SUBJECT $subject = "' ERP - Note de frais à re-approuver"; - + // CONTENT $dateRefusEx = explode(" ",$object->date_refuse); - + $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n"; $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n"; @@ -466,11 +466,11 @@ if (empty($reshook)) $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // Génération du pdf avant attachement $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + if($resultPDF) { // ATTACHMENT @@ -478,10 +478,10 @@ if (empty($reshook)) array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf"); array_push($mimetype,"application/pdf"); - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if (! $mailfile->error) { // SEND @@ -512,15 +512,15 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + // Approve if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->setApproved($user); - + if ($result > 0) { // Define output language @@ -536,44 +536,44 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) // TODO Translate this so we can remove condition { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // CC $emailCC = $conf->global->NDF_CC_EMAILS; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_valid); $emailFrom = $expediteur->email; - + // SUBJECT $subject = "' ERP - Note de frais validée"; - + // CONTENT $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Votre note de frais \"{$object->ref}\" vient d'être approuvé!\n"; $message.= "- Approbateur : {$expediteur->firstname} {$expediteur->lastname}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // Génération du pdf avant attachement $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + if($resultPDF): // ATTACHMENT $filename=array(); $filedir=array(); $mimetype=array(); @@ -586,12 +586,12 @@ if (empty($reshook)) ".pdf" ); array_push($mimetype,"application/pdf"); - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename,$emailCC); - + if(!$mailfile->error): - + // SEND $result=$mailfile->sendfile(); if ($result): @@ -601,7 +601,7 @@ if (empty($reshook)) else: setEventMessages($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo), null, 'errors'); endif; - + else: setEventMessages($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo), null, 'errors'); endif; @@ -617,14 +617,14 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->setDeny($user,GETPOST('detail_refuse')); - + if ($result > 0) { // Define output language @@ -640,30 +640,30 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) // TODO Translate this so we can remove condition { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_refuse); $emailFrom = $expediteur->email; - + // SUBJECT $subject = "' ERP - Note de frais refusée"; - + // CONTENT $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Votre note de frais \"{$object->ref}\" vient d'être refusée.\n"; @@ -671,10 +671,10 @@ if (empty($reshook)) $message.= "- Motif de refus : {$_POST['detail_refuse']}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); - + if(!$mailfile->error) { // SEND @@ -698,17 +698,17 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + //var_dump($user->id == $object->fk_user_validator);exit; if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_cancel') && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) { $result = $object->set_cancel($user,GETPOST('detail_cancel')); - + if ($result > 0) { // Define output language @@ -724,30 +724,30 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) // TODO Translate this so we can remove condition { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_cancel); $emailFrom = $expediteur->email; - + // SUBJECT $subject = "' ERP - Note de frais annulée"; - + // CONTENT $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Votre note de frais \"{$object->ref}\" vient d'être annulée.\n"; @@ -755,10 +755,10 @@ if (empty($reshook)) $message.= "- Motif d'annulation : {$_POST['detail_cancel']}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); - + if(!$mailfile->error) { // SEND @@ -791,7 +791,7 @@ if (empty($reshook)) setEventMessages($langs->transnoentitiesnoconv("OnlyOwnerCanCancel"), '', 'errors'); // Should not happened } } - + if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); @@ -799,7 +799,7 @@ if (empty($reshook)) if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { $result = $object->setStatut(0); - + if ($result > 0) { // Define output language @@ -815,11 +815,11 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); @@ -835,14 +835,14 @@ if (empty($reshook)) setEventMessages("NOT_AUTHOR", '', 'errors'); } } - + if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->set_paid($id, $user); - + if ($result > 0) { // Define output language @@ -858,50 +858,50 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) // TODO Translate this so we can remove condition { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($user->id); $emailFrom = $expediteur->email; - + // SUBJECT $subject = "'ERP - Note de frais payée"; - + // CONTENT $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // Generate pdf before attachment $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); - + if(!$mailfile->error): - + // SEND $result=$mailfile->sendfile(); if ($result): - + // Retour if($result): Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); @@ -909,11 +909,11 @@ if (empty($reshook)) else: dol_print_error($db); endif; - + else: dol_print_error($db,$acct->error); endif; - + else: $mesg="Impossible d'envoyer l'email."; setEventMessages($mesg, null, 'errors'); @@ -926,49 +926,50 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "addline" && $user->rights->expensereport->creer) { $error = 0; - + $db->begin(); - + $object_ligne = new ExpenseReportLine($db); - - $vatrate = GETPOST('vatrate'); + + $vatrate = GETPOST('vatrate','alpha'); // May be 8.5* (8.5NPROM) + $object_ligne->comments = GETPOST('comments'); $qty = GETPOST('qty','int'); if (empty($qty)) $qty=1; $object_ligne->qty = $qty; - + $up=price2num(GETPOST('value_unit'),'MU'); $object_ligne->value_unit = $up; - + $object_ligne->date = $date; - + $object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees'); - + // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. if (empty($vatrate)) $vatrate = "0.000"; $object_ligne->vatrate = price2num($vatrate); - + $object_ligne->fk_projet = $fk_projet; - - + + if (! GETPOST('fk_c_type_fees') > 0) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action=''; } - + if ($vatrate < 0 || $vatrate == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors'); $action=''; } - + /* Projects are never required. To force them, check module forceproject if ($conf->projet->enabled) { @@ -978,7 +979,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors'); } }*/ - + // Si aucune date n'est rentrée if (empty($object_ligne->date) || $object_ligne->date=="--") { @@ -991,21 +992,42 @@ if (empty($reshook)) $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors'); } - + // S'il y'a eu au moins une erreur if (! $error) { $object_ligne->fk_expensereport = $_POST['fk_expensereport']; - + $type = 0; // TODO What if service ? - $seller = ''; // seller is unknown - $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); - + + // We don't know seller and buyer for expense reports + $seller = $mysoc; + $buyer = new Societe($db); + + $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller); + + // Clean vat code + $vat_src_code=''; + + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { + $vat_src_code = $reg[1]; + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + } + $vatrate = preg_replace('/\*/','',$vatrate); + + $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + + $object_ligne->vat_src_code = $vat_src_code; $object_ligne->vatrate = price2num($vatrate); $object_ligne->total_ttc = $tmp[2]; $object_ligne->total_ht = $tmp[0]; $object_ligne->total_tva = $tmp[1]; - + $object_ligne->localtax1_tx = $localtaxes_type[1]; + $object_ligne->localtax2_tx = $localtaxes_type[3]; + $object_ligne->localtax1_type = $localtaxes_type[0]; + $object_ligne->localtax2_type = $localtaxes_type[2]; + $result = $object_ligne->insert(); if ($result > 0) { @@ -1019,20 +1041,20 @@ if (empty($reshook)) $db->rollback(); } } - + $action=''; } - + if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + $object_ligne = new ExpenseReportLine($db); $object_ligne->fetch(GETPOST("rowid")); $total_ht = $object_ligne->total_ht; $total_tva = $object_ligne->total_tva; - + $result=$object->deleteline(GETPOST("rowid"), $user); if ($result >= 0) { @@ -1051,11 +1073,11 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + $object->update_totaux_del($object_ligne->total_ht,$object_ligne->total_tva); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); exit; @@ -1065,12 +1087,12 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "updateligne" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + $rowid = $_POST['rowid']; $type_fees_id = GETPOST('fk_c_type_fees'); $projet_id = $fk_projet; @@ -1082,7 +1104,7 @@ if (empty($reshook)) // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. if (empty($vatrate)) $vatrate = "0.000"; $vatrate = price2num($vatrate); - + if (! GETPOST('fk_c_type_fees') > 0) { $error++; @@ -1095,7 +1117,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); $action=''; } - + if (! $error) { // TODO Use update method of ExpenseReportLine @@ -1117,13 +1139,13 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + $result = $object->recalculer($id); - + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } @@ -1133,8 +1155,8 @@ if (empty($reshook)) } } } - - + + /* * Generate or regenerate the PDF document */ @@ -1142,12 +1164,12 @@ if (empty($reshook)) { $depl = new ExpenseReport($db, 0, $_GET['id']); $depl->fetch($id); - + if ($_REQUEST['model']) { $depl->setDocModel($user, $_REQUEST['model']); } - + $outputlangs = $langs; if (! empty($_REQUEST['lang_id'])) { @@ -1161,7 +1183,7 @@ if (empty($reshook)) $action=''; } } - + // Remove file in doc form else if ($action == 'remove_file') { @@ -1169,9 +1191,9 @@ if (empty($reshook)) if ($object->fetch($id)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - + $object->fetch_thirdparty(); - + $langs->load("other"); $upload_dir = $conf->expensereport->dir_output; $file = $upload_dir . '/' . GETPOST('file'); @@ -1210,7 +1232,7 @@ if ($action == 'create') print ''; print ''; - + // Date start print ''; print ''; @@ -1218,7 +1240,7 @@ if ($action == 'create') $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1); print ''; print ''; - + // Date end print ''; print ''; @@ -1226,7 +1248,7 @@ if ($action == 'create') $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1); print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + // Payment mode if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) { @@ -1294,7 +1316,7 @@ if ($action == 'create') if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } - + print ''; print '
'.$langs->trans("DateStart").'
'.$langs->trans("DateEnd").'
'.$langs->trans("User").''; @@ -1238,7 +1260,7 @@ if ($action == 'create') print $s; print '
'.$langs->trans("VALIDATOR").''; @@ -1255,7 +1277,7 @@ if ($action == 'create') } print '
'; @@ -1314,7 +1336,7 @@ else $result = $object->fetch($id, $ref); $res = $object->fetch_optionals($object->id, $extralabels); - + if ($result > 0) { if (! in_array($object->fk_user_author, $user->getAllChildIds(1))) @@ -1365,7 +1387,7 @@ else $userfee->fetch($object->fk_user_author); print $userfee->getNomUrl(-1); print ''; - + // Ref print ''.$langs->trans("Ref").''; print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); @@ -1460,7 +1482,7 @@ else // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneExpenseReport'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } - + if ($action == 'save') { $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_validate","","",1); @@ -1510,13 +1532,13 @@ else // Print form confirm print $formconfirm; - - + + // Expense report card - + $linkback = ''.$langs->trans("BackToList").''; - - + + $morehtmlref='
'; /* // Ref customer @@ -1557,15 +1579,15 @@ else } }*/ $morehtmlref.='
'; - - + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '
'; print '
'; print '
'; - + print ''; // Author @@ -1580,7 +1602,7 @@ else print $userauthor->getNomUrl(-1); } print ''; - + print ''; print ''; print '"; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; @@ -1638,7 +1660,7 @@ else $userfee=new User($db); $userfee->fetch($object->fk_user_validator); print $userfee->getNomUrl(-1); - if (empty($userfee->email) || ! isValidEmail($userfee->email)) + if (empty($userfee->email) || ! isValidEmail($userfee->email)) { $langs->load("errors"); print img_warning($langs->trans("ErrorBadEMail", $userfee->email)); @@ -1658,7 +1680,7 @@ else print $userfee->getNomUrl(-1); } print ''; - + print ''; print ''; print ''; @@ -1680,7 +1702,7 @@ else print $userapp->getNomUrl(-1); } print ''; - + print ''; print ''; print ''; @@ -1696,7 +1718,7 @@ else $userfee->fetch($object->fk_user_refuse); print $userfee->getNomUrl(-1); print ''; - + print ''; print ''; print '
'.$langs->trans("Period").''; @@ -1607,12 +1629,12 @@ else if($object->fk_statut==6) $rowspan+=2; print "
'.$langs->trans("AmountVAT").''.price($object->total_tva).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc).'
'.$langs->trans("MOTIF_CANCEL").''.$object->detail_cancel.'
'.$langs->trans("DateApprove").''.dol_print_date($object->date_approve,'dayhour').'
'.$langs->trans("DATE_REFUS").''.dol_print_date($object->date_refuse,'dayhour'); @@ -1725,14 +1747,14 @@ else // Other attributes $cols = 3; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + print '
'; print '
'; print '
'; print '
'; //print '
'; - + // List of payments $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; $sql.= "c.code as type_code,c.libelle as payment_type"; @@ -1744,7 +1766,7 @@ else $sql.= " AND e.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; $sql.= " ORDER BY dp"; - + $resql = $db->query($sql); if ($resql) { @@ -1758,7 +1780,7 @@ else print ''.$langs->trans("Amount").''; print ' '; print ''; - + $var=True; while ($i < $num) { @@ -1774,14 +1796,14 @@ else $totalpaid += $objp->amount; $i++; } - + if ($object->paid == 0) { print "".$langs->trans("AlreadyPaid")." :".price($totalpaid)."\n"; print "".$langs->trans("AmountExpected")." :".price($object->total_ttc)."\n"; - + $remaintopay = $object->total_ttc - $totalpaid; - + print "".$langs->trans("RemainderToPay")." :"; print ''.price($remaintopay)."\n"; } @@ -1791,14 +1813,14 @@ else else { dol_print_error($db); - } - + } + print '
'; print '
'; print '
'; - + print '

'; - + print '
'; // Fetch Lines of current expense report @@ -1815,17 +1837,17 @@ else $actiontouse='updateligne'; if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline') $actiontouse='addline'; - + print ''; print ''; print ''; print ''; print ''; - - + + print '
'; print ''; - + $resql = $db->query($sql); if ($resql) { @@ -1885,7 +1907,7 @@ else print ''; print ''; print ''; - + if ($action != 'editline') { print ''; @@ -1906,7 +1928,7 @@ else print ''; } - + print ''; } @@ -1914,7 +1936,7 @@ else { //modif ligne!!!!! print ''; - + print ''; // Select date @@ -1929,7 +1951,7 @@ else $formproject->select_projects(-1, $objp->fk_projet,'fk_projet', 0, 0, 1, 1); print ''; } - + // Select type print ''; // Unit price @@ -1960,7 +1984,7 @@ else print ''; print ''; } - + print ''; print ''; - + print ''; print ''; - + // Select date print ''; } - + // Select type print ''; // Unit price @@ -2048,13 +2072,13 @@ else } print ''; - + print ''; } // Fin si c'est payé/validé print '
'.vatrate($objp->vatrate,true).''.price($objp->value_unit).''.$objp->qty.''.price($objp->total_ht).'
'; select_type_fees_id($objp->type_fees_code,'fk_c_type_fees'); @@ -1942,7 +1964,9 @@ else // VAT print ''; - print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $mysoc, ''); + $seller=$mysoc; + $buyer=new Societe($db); + print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $seller, $buyer, 0, 0, '', false, 1); print ''.$langs->trans('AmountHT').''.$langs->trans('AmountTTC').''; print ''; print ''; @@ -1996,11 +2020,11 @@ else print '
'; $form->select_date($date?$date:-1,'date'); @@ -2013,7 +2037,7 @@ else $formproject->select_projects(-1, $fk_projet, 'fk_projet', 0, 0, 1, 1); print ''; select_type_fees_id($fk_c_type_fees,'fk_c_type_fees',1); @@ -2028,7 +2052,7 @@ else print ''; $defaultvat=-1; if (! empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none'; - print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false); + print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false, 1); print '
'; print '
'; - + print ''; } else @@ -2167,15 +2191,15 @@ if ($action != 'create' && $action != 'edit') } } - + // If status is Appoved // -------------------- - + if ($user->rights->expensereport->approve && $object->fk_statut == 5) { print ''; } - + // If bank module is used if ($user->rights->expensereport->to_paid && ! empty($conf->banque->enabled) && $object->fk_statut == 5) { @@ -2189,8 +2213,8 @@ if ($action != 'create' && $action != 'edit') print ''; } } - - // If bank module is not used + + // If bank module is not used if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5) { //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0) @@ -2199,26 +2223,26 @@ if ($action != 'create' && $action != 'edit') print '"; } } - + if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->fk_statut == 5) { // Cancel print ''; } - + // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled. if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->fk_statut == 6) { // Cancel print ''; } - + // Clone if ($user->rights->expensereport->creer) { print ''; } - - /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ + + /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->fk_statut <= 4) { // Delete @@ -2269,7 +2293,7 @@ if ($action != 'create' && $action != 'edit' && ($id || $ref)) $object->fetch_thirdparty(); $result = $object->add_object_linked('fichinter', GETPOST('LinkedFichinter')); } - + // Show links to link elements $linktoelements=array(); if (! empty($conf->global->EXPENSES_LINK_TO_INTERVENTION)) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index e3970ab6b93..2bf9144dce2 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -37,9 +37,9 @@ class ExpenseReport extends CommonObject var $picto = 'trip'; var $lignes=array(); - + public $date_debut; - + public $date_fin; var $fk_user_validator; @@ -65,7 +65,7 @@ class ExpenseReport extends CommonObject // Update var $date_modif; var $fk_user_modif; - + // Refus var $date_refuse; var $detail_refuse; @@ -128,7 +128,7 @@ class ExpenseReport extends CommonObject $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. if (empty($fuserid)) $fuserid = $user->id; - + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; @@ -235,35 +235,35 @@ class ExpenseReport extends CommonObject function createFromClone($socid=0) { global $user,$hookmanager; - + $error=0; - + $this->context['createfromclone'] = 'createfromclone'; - + $this->db->begin(); - + // get extrafields so they will be clone foreach($this->lines as $line) //$line->fetch_optionals($line->rowid); - + // Load source object $objFrom = clone $this; - + $this->id=0; $this->ref = ''; $this->statut=0; - + // Clear fields $this->fk_user_author = $user->id; // Note fk_user_author is not the 'author' but the guy the expense report is for. $this->fk_user_valid = ''; $this->date_create = ''; $this->date_creation = ''; $this->date_validation = ''; - + // Create clone $result=$this->create($user); if ($result < 0) $error++; - + if (! $error) { // Hook of thirdparty module @@ -274,15 +274,15 @@ class ExpenseReport extends CommonObject $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) $error++; } - + // Call trigger $result=$this->call_trigger('EXPENSEREPORT_CLONE',$user); if ($result < 0) $error++; // End call triggers } - + unset($this->context['createfromclone']); - + // End if (! $error) { @@ -295,8 +295,8 @@ class ExpenseReport extends CommonObject return -1; } } - - + + /** * update * @@ -399,7 +399,7 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $obj->fk_user_refuse; $this->fk_user_cancel = $obj->fk_user_cancel; $this->fk_user_approve = $obj->fk_user_approve; - + $user_author = new User($this->db); if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author); @@ -588,7 +588,7 @@ class ExpenseReport extends CommonObject $auser->fetch($obj->fk_user_approve); $this->user_approve = $auser; } - + } $this->db->free($resql); } @@ -1000,7 +1000,7 @@ class ExpenseReport extends CommonObject $sql.= ", ref_number_int = ".$ref_number_int; } $sql.= ' WHERE rowid = '.$this->id; - + $resql=$this->db->query($sql); if ($resql) { @@ -1215,7 +1215,7 @@ class ExpenseReport extends CommonObject $sql = 'SELECT MAX(de.ref_number_int) as max'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de'; - + $result = $this->db->query($sql); if($this->db->num_rows($result) > 0): @@ -1359,7 +1359,7 @@ class ExpenseReport extends CommonObject * @param int $rowid Line to edit * @param int $type_fees_id Type payment * @param int $projet_id Project id - * @param double $vatrate Vat rate + * @param double $vatrate Vat rate. Can be '8.5* (8.5NPROM...)' * @param string $comments Description * @param real $qty Qty * @param double $value_unit Value init @@ -1369,14 +1369,34 @@ class ExpenseReport extends CommonObject */ function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id) { - global $user; + global $user, $mysoc; if ($this->fk_statut==0 || $this->fk_statut==99) { $this->db->begin(); + $type = 0; // TODO What if type is service ? + + // We don't know seller and buyer for expense reports + $seller = $mysoc; + $buyer = new Societe($this->db); + + $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller); + + // Clean vat code + $vat_src_code=''; + + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { + $vat_src_code = $reg[1]; + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + } + $vatrate = preg_replace('/\*/','',$vatrate); + + $tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + // calcul de tous les totaux de la ligne - $total_ttc = price2num($qty*$value_unit, 'MT'); + //$total_ttc = price2num($qty*$value_unit, 'MT'); $tx_tva = $vatrate / 100; $tx_tva = $tx_tva + 1; @@ -1386,6 +1406,9 @@ class ExpenseReport extends CommonObject // fin calculs $ligne = new ExpenseReportLine($this->db); + + $ligne->rowid = $rowid; + $ligne->comments = $comments; $ligne->qty = $qty; $ligne->value_unit = $value_unit; @@ -1395,11 +1418,21 @@ class ExpenseReport extends CommonObject $ligne->fk_c_type_fees = $type_fees_id; $ligne->fk_projet = $projet_id; - $ligne->total_ht = $total_ht; - $ligne->total_tva = $total_tva; - $ligne->total_ttc = $total_ttc; - $ligne->vatrate = price2num($vatrate); - $ligne->rowid = $rowid; + //$ligne->total_ht = $total_ht; + //$ligne->total_tva = $total_tva; + //$ligne->total_ttc = $total_ttc; + //$ligne->vatrate = price2num($vatrate); + + $ligne->vat_src_code = $vat_src_code; + $ligne->vatrate = price2num($vatrate); + $ligne->total_ttc = $tmp[2]; + $ligne->total_ht = $tmp[0]; + $ligne->total_tva = $tmp[1]; + $ligne->localtax1_tx = $localtaxes_type[1]; + $ligne->localtax2_tx = $localtaxes_type[3]; + $ligne->localtax1_type = $localtaxes_type[0]; + $ligne->localtax2_type = $localtaxes_type[2]; + // Select des infos sur le type fees $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees"; @@ -1540,7 +1573,7 @@ class ExpenseReport extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; $sql.= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; //print $sql; - + dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql); $result = $this->db->query($sql); if($result) @@ -1679,7 +1712,7 @@ class ExpenseReport extends CommonObject $now=dol_now(); $userchildids = $user->getAllChildIds(1); - + $sql = "SELECT ex.rowid, ex.date_valid"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; if ($option == 'toapprove') $sql.= " WHERE ex.fk_statut = 2"; @@ -1711,7 +1744,7 @@ class ExpenseReport extends CommonObject while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - + if ($option == 'toapprove') { if ($this->db->jdate($obj->date_valid) < ($now - $conf->expensereport->approve->warning_delay)) { @@ -1735,7 +1768,7 @@ class ExpenseReport extends CommonObject return -1; } } - + /** * Return if an expense report is late or not * @@ -1745,11 +1778,11 @@ class ExpenseReport extends CommonObject public function hasDelay($option) { global $conf; - + //Only valid members if ($option == 'toapprove' && $this->status != 2) return false; if ($option == 'topay' && $this->status != 5) return false; - + $now = dol_now(); if ($option == 'toapprove') { @@ -1757,7 +1790,7 @@ class ExpenseReport extends CommonObject } else return ($this->datevalid?$this->datevalid:$this->date_valid) < ($now - $conf->expensereport->payment->warning_delay); - } + } }