Fix: sql request with pgsql

Fix: bug reported by scrutinizer
Doxygen
Start to work on multi user assigned to an event.
This commit is contained in:
Laurent Destailleur 2014-09-20 00:57:29 +02:00
parent d74c1a81ab
commit ad8b92541d
12 changed files with 303 additions and 206 deletions

View File

@ -18,7 +18,7 @@
*/ */
/** /**
* \file htdocs/accountancy/class/Accountingaccount.class.php * \file htdocs/accountancy/class/accountingaccount.class.php
* \ingroup Accounting Expert * \ingroup Accounting Expert
* \brief Fichier de la classe des comptes comptable * \brief Fichier de la classe des comptes comptable
*/ */
@ -29,8 +29,11 @@
class AccountingAccount class AccountingAccount
{ {
var $db; var $db;
var $error;
var $id; var $id;
var $rowid; var $rowid;
var $datec; // Creation date var $datec; // Creation date
var $fk_pcg_version; var $fk_pcg_version;
var $pcg_type; var $pcg_type;
@ -62,8 +65,10 @@ class AccountingAccount
*/ */
function fetch($rowid = null, $account_number = null) function fetch($rowid = null, $account_number = null)
{ {
if ($rowid || $account_number) { if ($rowid || $account_number)
$sql = "SELECT * FROM " . MAIN_DB_PREFIX . "accountingaccount WHERE "; {
$sql = "SELECT rowid, datec, tms, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, labe, fk_user_author, fk_user_modifn active";
$sql.= " FROM " . MAIN_DB_PREFIX . "accountingaccount WHERE";
if ($rowid) { if ($rowid) {
$sql .= " rowid = '" . $rowid . "'"; $sql .= " rowid = '" . $rowid . "'";
} elseif ($account_number) { } elseif ($account_number) {
@ -72,28 +77,40 @@ class AccountingAccount
dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result)
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
} else {
return null; if ($obj)
{
$this->id = $obj->rowid;
$this->rowid = $obj->rowid;
$this->datec = $obj->datec;
$this->tms = $obj->tms;
$this->fk_pcg_version = $obj->fk_pcg_version;
$this->pcg_type = $obj->pcg_type;
$this->pcg_subtype = $obj->pcg_subtype;
$this->account_number = $obj->account_number;
$this->account_parent = $obj->account_parent;
$this->label = $obj->label;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_modif = $obj->fk_user_modif;
$this->active = $obj->active;
return $this->id;
}
else
{
return 0;
}
}
else
{
dol_print_error($this->db);
} }
} }
$this->id = $obj->rowid; return -1;
$this->rowid = $obj->rowid;
$this->datec = $obj->datec;
$this->tms = $obj->tms;
$this->fk_pcg_version = $obj->fk_pcg_version;
$this->pcg_type = $obj->pcg_type;
$this->pcg_subtype = $obj->pcg_subtype;
$this->account_number = $obj->account_number;
$this->account_parent = $obj->account_parent;
$this->label = $obj->label;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_modif = $obj->fk_user_modif;
$this->active = $obj->active;
return $obj->rowid;
} }
/** /**

View File

@ -28,7 +28,7 @@
*/ */
require '../../main.inc.php'; require '../../main.inc.php';
// Class // Class
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
@ -88,12 +88,12 @@ $sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,";
$sql .= " fd.rowid as fdid, fd.description, fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type,"; $sql .= " fd.rowid as fdid, fd.description, fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type,";
$sql .= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur, s.fournisseur,"; $sql .= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur, s.fournisseur,";
$sql .= " s.code_compta_fournisseur, p.accountancy_code_buy , ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; $sql .= " s.code_compta_fournisseur, p.accountancy_code_buy , ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det fd"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product p ON p.rowid = fd.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_product";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON aa.rowid = fd.fk_code_ventilation";
$sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn f ON f.rowid = fd.fk_facture_fourn"; $sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
$sql .= " JOIN " . MAIN_DB_PREFIX . "societe s ON s.rowid = f.fk_soc"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
$sql .= " WHERE f.fk_statut > 0 "; $sql .= " WHERE f.fk_statut > 0 ";
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {
$sql .= " AND f.entity = " . $conf->entity; $sql .= " AND f.entity = " . $conf->entity;
@ -113,13 +113,13 @@ if ($result) {
// les variables // les variables
$cptfour = (! empty($conf->global->COMPTA_ACCOUNT_SUPPLIER)) ? $conf->global->COMPTA_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"); $cptfour = (! empty($conf->global->COMPTA_ACCOUNT_SUPPLIER)) ? $conf->global->COMPTA_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef");
$cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT)) ? $conf->global->COMPTA_VAT_ACCOUNT : $langs->trans("CodeNotDef"); $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT)) ? $conf->global->COMPTA_VAT_ACCOUNT : $langs->trans("CodeNotDef");
$tabfac = array (); $tabfac = array ();
$tabht = array (); $tabht = array ();
$tabtva = array (); $tabtva = array ();
$tabttc = array (); $tabttc = array ();
$tabcompany = array (); $tabcompany = array ();
$i = 0; $i = 0;
while ( $i < $num ) { while ( $i < $num ) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
@ -133,7 +133,7 @@ if ($result) {
$compta_prod = (! empty($conf->global->COMPTA_SERVICE_BUY_ACCOUNT)) ? $conf->global->COMPTA_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"); $compta_prod = (! empty($conf->global->COMPTA_SERVICE_BUY_ACCOUNT)) ? $conf->global->COMPTA_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef");
} }
$compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva); $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva);
$tabfac[$obj->rowid]["date"] = $obj->df; $tabfac[$obj->rowid]["date"] = $obj->df;
$tabfac[$obj->rowid]["ref"] = $obj->ref; $tabfac[$obj->rowid]["ref"] = $obj->ref;
$tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["type"] = $obj->type;
@ -145,9 +145,9 @@ if ($result) {
$tabcompany[$obj->rowid] = array ( $tabcompany[$obj->rowid] = array (
'id' => $obj->socid, 'id' => $obj->socid,
'name' => $obj->name, 'name' => $obj->name,
'code_fournisseur' => $obj->code_compta_fournisseur 'code_fournisseur' => $obj->code_compta_fournisseur
); );
$i ++; $i ++;
} }
} else { } else {
@ -160,11 +160,11 @@ if ($result) {
// Bookkeeping Write // Bookkeeping Write
if ($action == 'writebookkeeping') { if ($action == 'writebookkeeping') {
$now = dol_now(); $now = dol_now();
foreach ( $tabfac as $key => $val ) { foreach ( $tabfac as $key => $val ) {
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
// get compte id and label // get compte id and label
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
@ -180,10 +180,10 @@ if ($action == 'writebookkeeping') {
$bookkeeping->debit = ($mt <= 0) ? $mt : 0; $bookkeeping->debit = ($mt <= 0) ? $mt : 0;
$bookkeeping->credit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt > 0) ? $mt : 0;
$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
$bookkeeping->create(); $bookkeeping->create();
} }
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
@ -205,18 +205,18 @@ if ($action == 'writebookkeeping') {
$bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->debit = ($mt > 0) ? $mt : 0;
$bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
$bookkeeping->create(); $bookkeeping->create();
} }
} }
} }
// VAT // VAT
// var_dump($tabtva); // var_dump($tabtva);
foreach ( $tabtva[$key] as $k => $mt ) { foreach ( $tabtva[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
// get compte id and label // get compte id and label
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
@ -232,7 +232,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->debit = ($mt > 0) ? $mt : 0;
$bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
$bookkeeping->create(); $bookkeeping->create();
} }
} }
@ -243,21 +243,21 @@ if ($action == 'writebookkeeping') {
if ($action == 'export_csv') { if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_SEPARATORCSV; $sep = $conf->global->ACCOUNTING_SEPARATORCSV;
header('Content-Type: text/csv'); header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=journal_achats.csv'); header('Content-Disposition: attachment;filename=journal_achats.csv');
if ($conf->global->ACCOUNTING_MODELCSV == 1) // Modèle Export Cegid Expert if ($conf->global->ACCOUNTING_MODELCSV == 1) // Modèle Export Cegid Expert
{ {
foreach ( $tabfac as $key => $val ) { foreach ( $tabfac as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client']; $companystatic->client = $tabcompany[$key]['code_client'];
if ($mt) { if ($mt) {
print $date . $sep; print $date . $sep;
print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep; print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep;
@ -270,7 +270,7 @@ if ($action == 'export_csv') {
print "\n"; print "\n";
} }
} }
// VAT // VAT
// var_dump($tabtva); // var_dump($tabtva);
foreach ( $tabtva[$key] as $k => $mt ) { foreach ( $tabtva[$key] as $k => $mt ) {
@ -289,7 +289,7 @@ if ($action == 'export_csv') {
print $date . $sep; print $date . $sep;
print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep; print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep;
print length_accountg($conf->global->COMPTA_ACCOUNT_SUPPLIER) . $sep; print length_accountg($conf->global->COMPTA_ACCOUNT_SUPPLIER) . $sep;
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print length_accounta(html_entity_decode($k)) . $sep; print length_accounta(html_entity_decode($k)) . $sep;
print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt < 0 ? 'D' : 'C') . $sep;
@ -303,11 +303,11 @@ if ($action == 'export_csv') {
{ {
foreach ( $tabfac as $key => $val ) { foreach ( $tabfac as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), 'day'); $date = dol_print_date($db->jdate($val["date"]), 'day');
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client']; $companystatic->client = $tabcompany[$key]['code_client'];
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
@ -333,7 +333,7 @@ if ($action == 'export_csv') {
print "\n"; print "\n";
} }
} }
// Third party // Third party
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep; print '"' . $val["ref"] . '"' . $sep;
@ -347,11 +347,11 @@ if ($action == 'export_csv') {
} }
} }
} else { } else {
llxHeader('', '', ''); llxHeader('', '', '');
$form = new Form($db); $form = new Form($db);
$nom = $langs->trans("PurchasesJournal"); $nom = $langs->trans("PurchasesJournal");
$nomlink = ''; $nomlink = '';
$periodlink = ''; $periodlink = '';
@ -364,11 +364,11 @@ if ($action == 'export_csv') {
$description .= $langs->trans("DepositsAreIncluded"); $description .= $langs->trans("DepositsAreIncluded");
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />'; print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print ' print '
<script type="text/javascript"> <script type="text/javascript">
function launch_export() { function launch_export() {
@ -382,12 +382,12 @@ if ($action == 'export_csv') {
$("div.fiche div.tabBar form input[name=\"action\"]").val(""); $("div.fiche div.tabBar form input[name=\"action\"]").val("");
} }
</script>'; </script>';
/* /*
* Show result array * Show result array
*/ */
print '<br><br>'; print '<br><br>';
$i = 0; $i = 0;
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">"; print "<tr class=\"liste_titre\">";
@ -397,21 +397,21 @@ if ($action == 'export_csv') {
print "<td>" . $langs->trans("Account") . "</td>"; print "<td>" . $langs->trans("Account") . "</td>";
print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>"; print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
print "</tr>\n"; print "</tr>\n";
$var = true; $var = true;
$r = ''; $r = '';
$invoicestatic = new FactureFournisseur($db); $invoicestatic = new FactureFournisseur($db);
$companystatic = new Fournisseur($db); $companystatic = new Fournisseur($db);
foreach ( $tabfac as $key => $val ) { foreach ( $tabfac as $key => $val ) {
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"]; $invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"]; $invoicestatic->type = $val["type"];
$invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
$date = dol_print_date($db->jdate($val["date"]), 'day'); $date = dol_print_date($db->jdate($val["date"]), 'day');
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
@ -441,16 +441,16 @@ if ($action == 'export_csv') {
} }
} }
print "<tr " . $bc[$var] . ">"; print "<tr " . $bc[$var] . ">";
// Third party // Third party
// print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>"; // print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
print "<td>" . length_accounta($k); print "<td>" . length_accounta($k);
print "</td><td>" . $langs->trans("ThirdParty"); print "</td><td>" . $langs->trans("ThirdParty");
print ' (' . $companystatic->getNomUrl(0, 'supplier', 16) . ')'; print ' (' . $companystatic->getNomUrl(0, 'supplier', 16) . ')';
@ -459,12 +459,12 @@ if ($action == 'export_csv') {
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
} }
print "</tr>"; print "</tr>";
$var = ! $var; $var = ! $var;
} }
print "</table>"; print "</table>";
// End of page // End of page
llxFooter(); llxFooter();
} }

View File

@ -90,11 +90,11 @@ $sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tot
$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,"; $sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
$sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte, "; $sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte, ";
$sql .= " ct.accountancy_code_sell as account_tva"; $sql .= " ct.accountancy_code_sell as account_tva";
$sql .= " FROM " . MAIN_DB_PREFIX . "facturedet fd"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product p ON p.rowid = fd.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_product";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON aa.rowid = fd.fk_code_ventilation";
$sql .= " JOIN " . MAIN_DB_PREFIX . "facture f ON f.rowid = fd.fk_facture"; $sql .= " JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
$sql .= " JOIN " . MAIN_DB_PREFIX . "societe s ON s.rowid = f.fk_soc"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
$sql .= " WHERE fd.fk_code_ventilation > 0 "; $sql .= " WHERE fd.fk_code_ventilation > 0 ";
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {

View File

@ -57,12 +57,14 @@ class ActionComm extends CommonObject
var $punctual = 1; // Milestone var $punctual = 1; // Milestone
var $percentage; // Percentage var $percentage; // Percentage
var $location; // Location var $location; // Location
var $transparency; // Transparency (ical standard). Used to say if people assigned to event are busy or not by event. 0=available, 1=busy, 2=busy (refused events) var $transparency; // Transparency (ical standard). Used to say if people assigned to event are busy or not by event. 0=available, 1=busy, 2=busy (refused events)
var $priority; // Small int (0 By default) var $priority; // Small int (0 By default)
var $note; // Description var $note; // Description
var $usertodo; // Object user that must do action var $userassigned; // Array of user ids
var $userdone; // Object user that did action var $usertodo; // Object user of owner
var $userdone; // Object user that did action (deprecated)
var $societe; // Company linked to action (optional) var $societe; // Company linked to action (optional)
var $contact; // Contact linked to action (optional) var $contact; // Contact linked to action (optional)
@ -89,10 +91,10 @@ class ActionComm extends CommonObject
{ {
$this->db = $db; $this->db = $db;
$this->author = new stdClass(); //$this->author = new stdClass();
$this->usermod = new stdClass(); //$this->usermod = new stdClass();
$this->usertodo = new stdClass(); //$this->usertodo = new stdClass();
$this->userdone = new stdClass(); //$this->userdone = new stdClass();
$this->societe = new stdClass(); $this->societe = new stdClass();
$this->contact = new stdClass(); $this->contact = new stdClass();
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
@ -87,20 +87,37 @@ $hookmanager->initHooks(array('actioncard'));
* Actions * Actions
*/ */
if (GETPOST('addassignedtouser')) // Remove user to assigned list
if (! empty($_POST['removedassigned']))
{
$idtoremove=$_POST['removedassigned'];
if (! empty($_SESSION['assignedtouser'])) $tmpassigneduserids=dol_json_decode($_SESSION['assignedtouser'],1);
else $tmpassigneduserids=array();
unset($tmpassigneduserids[$idtoremove]);
//var_dump($_POST['removedassigned']);exit;
$_SESSION['assignedtouser']=dol_json_encode($tmpassigneduserids);
$donotclearsession=1;
if ($action == 'add') $action = 'create';
if ($action == 'update') $action = 'edit';
}
// Add user to assigned list
if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser'))
{ {
// Add a new user // Add a new user
if (GETPOST('affectedto') > 0) if (GETPOST('affectedto') > 0)
{ {
$assignedtouser=array(); $assignedtouser=array();
if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); if (! empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
$assignedtouser[GETPOST('affectedto')]=array('transparency'=>GETPOST('transparency'),'mandatory'=>1); $assignedtouser[GETPOST('affectedto')]=array('transparency'=>GETPOST('transparency'),'mandatory'=>1);
$_SESSION['assignedtouser']=dol_json_encode($assignedtouser); $_SESSION['assignedtouser']=dol_json_encode($assignedtouser);
} }
$donotclearsession=1; $donotclearsession=1;
$action='create'; if ($action == 'add') $action = 'create';
if ($action == 'update') $action = 'edit';
} }
// Add action
// Add event
if ($action == 'add') if ($action == 'add')
{ {
$error=0; $error=0;
@ -131,22 +148,22 @@ if ($action == 'add')
// Check parameters // Check parameters
if (! $datef && $percentage == 100) if (! $datef && $percentage == 100)
{ {
$error++; $error++; $donotclearsession=1;
$action = 'create'; $action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")), 'errors');
} }
if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! GETPOST('label')) if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! GETPOST('label'))
{ {
$error++; $error++; $donotclearsession=1;
$action = 'create'; $action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Title")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Title")), 'errors');
} }
// Initialisation objet cactioncomm // Initialisation objet cactioncomm
if (! GETPOST('actioncode')) if (! GETPOST('actioncode') > 0)
{ {
$error++; $error++; $donotclearsession=1;
$action = 'create'; $action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
} }
@ -161,7 +178,6 @@ if ($action == 'add')
$object->priority = GETPOST("priority")?GETPOST("priority"):0; $object->priority = GETPOST("priority")?GETPOST("priority"):0;
$object->fulldayevent = (! empty($fulldayevent)?1:0); $object->fulldayevent = (! empty($fulldayevent)?1:0);
$object->location = GETPOST("location"); $object->location = GETPOST("location");
$object->transparency = (GETPOST("transparency")=='on'?1:0);
$object->label = trim(GETPOST('label')); $object->label = trim(GETPOST('label'));
$object->fk_element = GETPOST("fk_element"); $object->fk_element = GETPOST("fk_element");
$object->elementtype = GETPOST("elementtype"); $object->elementtype = GETPOST("elementtype");
@ -186,18 +202,35 @@ if ($action == 'add')
$object->percentage = $percentage; $object->percentage = $percentage;
$object->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60; $object->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60;
$usertodo=new User($db); $listofuserid=dol_json_decode($_SESSION['assignedtouser']);
if ($_POST["affectedto"] > 0) $i=0;
foreach($listofuserid as $key => $value)
{ {
$usertodo->fetch($_POST["affectedto"]); if ($i == 0) // First entry
{
$usertodo=new User($db);
if ($key > 0)
{
$usertodo->fetch($key);
}
$object->usertodo = $usertodo;
$object->transparency = (GETPOST("transparency")=='on'?1:0);
}
$object->userassigned[$key]=array('id'=>$key, 'transparency'=>(GETPOST("transparency")=='on'?1:0));
$i++;
} }
$object->usertodo = $usertodo;
$userdone=new User($db); if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
if ($_POST["doneby"] > 0)
{ {
$userdone->fetch($_POST["doneby"]); $userdone=new User($db);
if ($_POST["doneby"] > 0)
{
$userdone->fetch($_POST["doneby"]);
}
$object->userdone = $userdone;
} }
$object->userdone = $userdone;
$object->note = trim($_POST["note"]); $object->note = trim($_POST["note"]);
if (isset($_POST["contactid"])) $object->contact = $contact; if (isset($_POST["contactid"])) $object->contact = $contact;
@ -214,16 +247,22 @@ if ($action == 'add')
if (! empty($conf->phenix->enabled) && GETPOST('add_phenix') == 'on') $object->use_phenix=1; if (! empty($conf->phenix->enabled) && GETPOST('add_phenix') == 'on') $object->use_phenix=1;
// Check parameters // Check parameters
if (empty($object->usertodo))
{
$error++; $donotclearsession=1;
$action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ActionAffectedTo")), 'errors');
}
if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent)))) if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent))))
{ {
$error++; $error++; $donotclearsession=1;
$action = 'create'; $action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")), 'errors');
} }
if (! GETPOST('apyear') && ! GETPOST('adyear')) if (! GETPOST('apyear') && ! GETPOST('adyear'))
{ {
$error++; $error++; $donotclearsession=1;
$action = 'create'; $action = 'create';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
} }
@ -265,42 +304,14 @@ if ($action == 'add')
$langs->load("errors"); $langs->load("errors");
$error=$langs->trans($object->error); $error=$langs->trans($object->error);
setEventMessage($error,'errors'); setEventMessage($error,'errors');
$action = 'create'; $action = 'create'; $donotclearsession=1;
} }
} }
else else
{ {
$db->rollback(); $db->rollback();
$langs->load("errors"); setEventMessages($object->error, $object->errors, 'errors');
$action = 'create'; $donotclearsession=1;
if (! empty($object->error)) setEventMessage($langs->trans($object->error), 'errors');
if (count($object->errors)) setEventMessage($object->errors, 'errors');
$action = 'create';
}
}
}
/*
* Action suppression de l'action
*/
if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{
$object->fetch($id);
if ($user->rights->agenda->myactions->delete
|| $user->rights->agenda->allactions->delete)
{
$result=$object->delete();
if ($result >= 0)
{
header("Location: index.php");
exit;
}
else
{
setEventMessage($object->error,'errors');
} }
} }
} }
@ -348,25 +359,59 @@ if ($action == 'update')
if (! $datef && $percentage == 100) if (! $datef && $percentage == 100)
{ {
$error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd")); $error++; $donotclearsession=1;
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")),$object->errors,'errors');
$action = 'edit'; $action = 'edit';
} }
// Users // Users
$usertodo=new User($db); $listofuserid=dol_json_decode($_SESSION['assignedtouser']);
if ($_POST["affectedto"]) $i=0;
foreach($listofuserid as $key => $value)
{ {
$usertodo->fetch($_POST["affectedto"]); if ($i == 0) // First entry
} {
$object->usertodo = $usertodo; $usertodo=new User($db);
$object->transparency=(GETPOST("transparency")=='on'?1:0); if ($key > 0)
{
$usertodo->fetch($key);
}
$object->usertodo = $usertodo;
$object->transparency=(GETPOST("transparency")=='on'?1:0);
}
$userdone=new User($db); $object->userassigned[$key]=array('id'=>$key, 'transparency'=>(GETPOST("transparency")=='on'?1:0));
if ($_POST["doneby"])
{ $i++;
$userdone->fetch($_POST["doneby"]); }
if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
{
$userdone=new User($db);
if ($_POST["doneby"])
{
$userdone->fetch($_POST["doneby"]);
}
$object->userdone = $userdone;
}
// Check parameters
if (! GETPOST('actioncode') > 0)
{
$error++; $donotclearsession=1;
$action = 'edit';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
}
else
{
$result=$cactioncomm->fetch(GETPOST('actioncode'));
}
if (empty($object->usertodo))
{
$error++; $donotclearsession=1;
$action = 'edit';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ActionAffectedTo")), 'errors');
} }
$object->userdone = $userdone;
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@ -383,17 +428,13 @@ if ($action == 'update')
} }
else else
{ {
setEventMessages($object->error,$object->errors,'errors');
$db->rollback(); $db->rollback();
} }
} }
} }
if ($result < 0) if (! $error)
{
setEventMessage($object->error,'errors');
setEventMessage($object->errors,'errors');
}
else
{ {
if (! empty($backtopage)) if (! empty($backtopage))
{ {
@ -403,6 +444,30 @@ if ($action == 'update')
} }
} }
/*
* delete event
*/
if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{
$object->fetch($id);
if ($user->rights->agenda->myactions->delete
|| $user->rights->agenda->allactions->delete)
{
$result=$object->delete();
if ($result >= 0)
{
header("Location: index.php");
exit;
}
else
{
setEventMessages($object->error,$object->errors,'errors');
}
}
}
/* /*
* Action move update, used when user move an event in calendar by drag'n drop * Action move update, used when user move an event in calendar by drag'n drop
*/ */
@ -576,15 +641,14 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" size="50" value="'.(GETPOST('location')?GETPOST('location'):$object->location).'"></td></tr>'; print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" size="50" value="'.(GETPOST('location')?GETPOST('location'):$object->location).'"></td></tr>';
// Assigned to // Assigned to
$var=false;
print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>'; print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
if (empty($donotclearsession)) if (empty($donotclearsession))
{ {
$assignedtouser=GETPOST("affectedtouser")?GETPOST("affectedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id); $assignedtouser=GETPOST("affectedtouser")?GETPOST("affectedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id);
$_SESSION['assignedtouser']=dol_json_encode(array($assignedtouser=>array('transparency'=>1,'mandatory'=>1))); $_SESSION['assignedtouser']=dol_json_encode(array($assignedtouser=>array('transparency'=>1,'mandatory'=>1)));
} }
//print $form->select_dolusers_forevent('affectedto',1); print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'affectedto',1);
print $form->select_dolusers(GETPOST("affectedto")?GETPOST("affectedto"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id),'affectedto',1); //print $form->select_dolusers(GETPOST("affectedto")?GETPOST("affectedto"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id),'affectedto',1);
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
@ -599,7 +663,7 @@ if ($action == 'create')
print '</td></tr>'; print '</td></tr>';
// Realised by // Realised by
if ($conf->global->AGENDA_ENABLE_DONEBY) if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
{ {
print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td>'; print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td>';
print $form->select_dolusers(GETPOST("doneby")?GETPOST("doneby"):(! empty($object->userdone->id) && $percent==100?$object->userdone->id:0),'doneby',1); print $form->select_dolusers(GETPOST("doneby")?GETPOST("doneby"):(! empty($object->userdone->id) && $percent==100?$object->userdone->id:0),'doneby',1);
@ -704,11 +768,6 @@ if ($action == 'create')
// View or edit // View or edit
if ($id > 0) if ($id > 0)
{ {
if ($error)
{
dol_htmloutput_errors($error);
}
$result=$object->fetch($id); $result=$object->fetch($id);
$object->fetch_optionals($id,$extralabels); $object->fetch_optionals($id,$extralabels);
@ -833,7 +892,14 @@ if ($id > 0)
// Assigned to // Assigned to
print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">'; print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
print $form->select_dolusers($object->usertodo->id>0?$object->usertodo->id:-1,'affectedto',1); $listofuserid=array();
if (empty($donotclearsession))
{
if (is_object($object->usertodo)) $listofuserid[$object->usertodo->id]=array('id'=>$object->usertodo->id,'transparency'=>$object->transparency);
$_SESSION['assignedtouser']=dol_json_encode($listofuserid);
}
print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'affectedto',1);
//print $form->select_dolusers($object->usertodo->id>0?$object->usertodo->id:-1,'affectedto',1);
print '</td></tr>'; print '</td></tr>';
print '</table><br><br><table class="border" width="100%">'; print '</table><br><br><table class="border" width="100%">';
@ -844,7 +910,7 @@ if ($id > 0)
print '</td></tr>'; print '</td></tr>';
// Realised by // Realised by
if ($conf->global->AGENDA_ENABLE_DONEBY) if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
{ {
print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td colspan="3">'; print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td colspan="3">';
print $form->select_dolusers($object->userdone->id> 0?$object->userdone->id:-1,'doneby',1); print $form->select_dolusers($object->userdone->id> 0?$object->userdone->id:-1,'doneby',1);

View File

@ -484,7 +484,7 @@ class Facture extends CommonInvoice
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_CREATE',$user); $result=$this->call_trigger('BILL_CREATE',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
if (! $error) if (! $error)
@ -593,8 +593,8 @@ class Facture extends CommonInvoice
// Load source object // Load source object
$objFrom = dol_clone($this); $objFrom = dol_clone($this);
// Change socid if needed // Change socid if needed
if (! empty($socid) && $socid != $this->socid) if (! empty($socid) && $socid != $this->socid)
@ -637,7 +637,7 @@ class Facture extends CommonInvoice
unset($this->products[$i]); // Tant que products encore utilise unset($this->products[$i]); // Tant que products encore utilise
} }
} }
// Create clone // Create clone
$result=$this->create($user); $result=$this->create($user);
if ($result < 0) $error++; if ($result < 0) $error++;
@ -645,7 +645,7 @@ class Facture extends CommonInvoice
// copy internal contacts // copy internal contacts
if ($this->copy_linked_contact($objFrom, 'internal') < 0) if ($this->copy_linked_contact($objFrom, 'internal') < 0)
$error++; $error++;
// copy external contacts if same company // copy external contacts if same company
elseif ($objFrom->socid == $this->socid) elseif ($objFrom->socid == $this->socid)
{ {
@ -667,7 +667,7 @@ class Facture extends CommonInvoice
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_CLONE',$user); $result=$this->call_trigger('BILL_CLONE',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
@ -1108,7 +1108,7 @@ class Facture extends CommonInvoice
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_MODIFY',$user); $result=$this->call_trigger('BILL_MODIFY',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
} }
@ -1266,7 +1266,7 @@ class Facture extends CommonInvoice
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_DELETE',$user); $result=$this->call_trigger('BILL_DELETE',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
@ -1438,7 +1438,7 @@ class Facture extends CommonInvoice
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_PAYED',$user); $result=$this->call_trigger('BILL_PAYED',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
else else
@ -1490,7 +1490,7 @@ class Facture extends CommonInvoice
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_UNPAYED',$user); $result=$this->call_trigger('BILL_UNPAYED',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
else else
@ -1554,7 +1554,7 @@ class Facture extends CommonInvoice
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_CANCEL',$user); $result=$this->call_trigger('BILL_CANCEL',$user);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -1768,11 +1768,11 @@ class Facture extends CommonInvoice
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_VALIDATE',$user); $result=$this->call_trigger('BILL_VALIDATE',$user);
if ($result < 0) $error++; if ($result < 0) $error++;
//TODO: Restoring ref, facnumber, statut, brouillon to previous value if trigger fail //TODO: Restoring ref, facnumber, statut, brouillon to previous value if trigger fail
// End call triggers // End call triggers
} }
// Set new ref and define current statut // Set new ref and define current statut
if (! $error) if (! $error)
{ {
@ -1856,7 +1856,7 @@ class Facture extends CommonInvoice
$this->statut = 0; $this->statut = 0;
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_UNVALIDATE',$user); $result=$this->call_trigger('BILL_UNVALIDATE',$user);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
$this->statut=$old_statut; $this->statut=$old_statut;
@ -3164,7 +3164,7 @@ class Facture extends CommonInvoice
$sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,'; $sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,';
$sql.= ' p.description as product_desc'; $sql.= ' p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON l.fk_product=p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
$sql.= ' WHERE l.fk_facture = '.$this->id; $sql.= ' WHERE l.fk_facture = '.$this->id;
$sql.= ' ORDER BY l.rang ASC, l.rowid'; $sql.= ' ORDER BY l.rang ASC, l.rowid';
@ -3550,7 +3550,7 @@ class FactureLigne extends CommonInvoiceLine
// Call trigger // Call trigger
$result=$this->call_trigger('LINEBILL_INSERT',$user); $result=$this->call_trigger('LINEBILL_INSERT',$user);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -3661,7 +3661,7 @@ class FactureLigne extends CommonInvoiceLine
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('LINEBILL_UPDATE',$user); $result=$this->call_trigger('LINEBILL_UPDATE',$user);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
@ -3691,7 +3691,7 @@ class FactureLigne extends CommonInvoiceLine
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
// Call trigger // Call trigger
$result=$this->call_trigger('LINEBILL_DELETE',$user); $result=$this->call_trigger('LINEBILL_DELETE',$user);
if ($result < 0) if ($result < 0)
@ -3700,7 +3700,7 @@ class FactureLigne extends CommonInvoiceLine
return -1; return -1;
} }
// End call triggers // End call triggers
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid; $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);

View File

@ -104,11 +104,11 @@ $sql.= " fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_t
$sql.= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur,"; $sql.= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur,";
$sql.= " p.rowid as pid, p.ref as ref, p.accountancy_code_buy,"; $sql.= " p.rowid as pid, p.ref as ref, p.accountancy_code_buy,";
$sql.= " ct.accountancy_code_buy as account_tva, ct.recuperableonly"; $sql.= " ct.accountancy_code_buy as account_tva, ct.recuperableonly";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn_det fd"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva as ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON p.rowid = fd.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture_fourn f ON f.rowid = fd.fk_facture_fourn"; $sql.= " JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid = f.fk_soc" ; $sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc" ;
$sql.= " WHERE f.fk_statut > 0 AND f.entity = ".$conf->entity; $sql.= " WHERE f.fk_statut > 0 AND f.entity = ".$conf->entity;
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)";
else $sql.= " AND f.type IN (0,1,2,3)"; else $sql.= " AND f.type IN (0,1,2,3)";

View File

@ -105,10 +105,10 @@ $sql.= " fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc, fd
$sql.= " s.rowid as socid, s.nom as name, s.code_compta, s.client,"; $sql.= " s.rowid as socid, s.nom as name, s.code_compta, s.client,";
$sql.= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell,"; $sql.= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell,";
$sql.= " ct.accountancy_code_sell as account_tva, ct.recuperableonly"; $sql.= " ct.accountancy_code_sell as account_tva, ct.recuperableonly";
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet fd"; $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON p.rowid = fd.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture f ON f.rowid = fd.fk_facture"; $sql.= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid = f.fk_soc"; $sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity = ".$conf->entity;
$sql.= " AND f.fk_statut > 0"; $sql.= " AND f.fk_statut > 0";

View File

@ -1289,7 +1289,7 @@ class Form
* @return string HTML select string * @return string HTML select string
* @see select_dolgroups * @see select_dolgroups
*/ */
function select_dolusers_forevent($htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='') function select_dolusers_forevent($action='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='')
{ {
global $conf,$user,$langs; global $conf,$user,$langs;
@ -1297,18 +1297,24 @@ class Form
// Method with no ajax // Method with no ajax
//$out.='<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; //$out.='<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); $out.='<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
$out.='<input type="submit" class="button" name="addassignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">'; $out.='<script type="text/javascript" language="javascript">jQuery(document).ready(function () { jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });})</script>';
$out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
$out.='<input type="submit" class="button" name="'.$action.'assignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
$assignedtouser=array(); $assignedtouser=array();
if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
if (count($assignedtouser)) $out.='<br>'; if (count($assignedtouser)) $out.='<br>';
$i=0;
foreach($assignedtouser as $key => $value) foreach($assignedtouser as $key => $value)
{ {
$userstatic->fetch($key); $userstatic->fetch($key);
$out.=$userstatic->getNomUrl(1); $out.=$userstatic->getNomUrl(1);
if ($i == 0) $out.=' ('.$langs->trans("Owner").')';
$out.=' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional")); //$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy")); //$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
$out.='<br>'; $out.='<br>';
$i++;
} }
//$out.='</form>'; //$out.='</form>';

View File

@ -186,12 +186,12 @@ class Entrepot extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement";
$sql.= " WHERE fk_entrepot = " . $this->id; $sql.= " WHERE fk_entrepot = " . $this->id;
dol_syslog("Entrepot::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql1=$this->db->query($sql); $resql1=$this->db->query($sql);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock";
$sql.= " WHERE fk_entrepot = " . $this->id; $sql.= " WHERE fk_entrepot = " . $this->id;
dol_syslog("Entrepot::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql2=$this->db->query($sql); $resql2=$this->db->query($sql);
if ($resql1 && $resql2) if ($resql1 && $resql2)
@ -202,8 +202,8 @@ class Entrepot extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql1=$this->db->query($sql); $resql1=$this->db->query($sql);
// Update denormalized fields because we change content of produt_stock // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
$sql = "UPDATE ".MAIN_DB_PREFIX."product p SET p.stock= (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock ps WHERE ps.fk_product = p.rowid)"; $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)";
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql2=$this->db->query($sql); $resql2=$this->db->query($sql);
@ -217,7 +217,7 @@ class Entrepot extends CommonObject
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
return -1; return -2;
} }
} }
else else
@ -540,7 +540,7 @@ class Entrepot extends CommonObject
$this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now,'dayhourlog'); $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now,'dayhourlog');
$this->statut=1; $this->statut=1;
$this->specimen=1; $this->specimen=1;
$this->lieu='Location test'; $this->lieu='Location test';
$this->address='21 jump street'; $this->address='21 jump street';
$this->zip='99999'; $this->zip='99999';

View File

@ -261,7 +261,7 @@ else
// Country // Country
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
if (! empty($object->country_code)) if (! empty($object->country_code))
{ {
$img=picto_from_langcode($object->country_code); $img=picto_from_langcode($object->country_code);
print ($img?$img.' ':''); print ($img?$img.' ':'');
@ -339,14 +339,14 @@ else
print "<a class=\"butAction\" href=\"fiche.php?action=edit&id=".$object->id."\">".$langs->trans("Modify")."</a>"; print "<a class=\"butAction\" href=\"fiche.php?action=edit&id=".$object->id."\">".$langs->trans("Modify")."</a>";
else else
print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Modify")."</a>"; print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Modify")."</a>";
if ($user->rights->stock->supprimer) if ($user->rights->stock->supprimer)
print "<a class=\"butActionDelete\" href=\"fiche.php?action=delete&id=".$object->id."\">".$langs->trans("Delete")."</a>"; print "<a class=\"butActionDelete\" href=\"fiche.php?action=delete&id=".$object->id."\">".$langs->trans("Delete")."</a>";
else else
print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>"; print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>";
} }
} }
print "</div>"; print "</div>";
@ -375,7 +375,7 @@ else
$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc,"; $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc,";
$sql.= " ps.pmp, ps.reel as value"; $sql.= " ps.pmp, ps.reel as value";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE ps.fk_product = p.rowid"; $sql.= " WHERE ps.fk_product = p.rowid";
$sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse) $sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
$sql.= " AND ps.fk_entrepot = ".$object->id; $sql.= " AND ps.fk_entrepot = ".$object->id;

View File

@ -123,14 +123,21 @@ class AllTests
require_once dirname(__FILE__).'/DiscountTest.php'; require_once dirname(__FILE__).'/DiscountTest.php';
$suite->addTestSuite('DiscountTest'); $suite->addTestSuite('DiscountTest');
require_once dirname(__FILE__).'/ContratTest.php';
$suite->addTestSuite('ContratTest');
require_once dirname(__FILE__).'/FichinterTest.php';
$suite->addTestSuite('FichinterTest');
require_once dirname(__FILE__).'/PropalTest.php';
$suite->addTestSuite('PropalTest');
require_once dirname(__FILE__).'/CommandeTest.php'; require_once dirname(__FILE__).'/CommandeTest.php';
$suite->addTestSuite('CommandeTest'); $suite->addTestSuite('CommandeTest');
require_once dirname(__FILE__).'/CommandeFournisseurTest.php'; require_once dirname(__FILE__).'/CommandeFournisseurTest.php';
$suite->addTestSuite('CommandeFournisseurTest'); $suite->addTestSuite('CommandeFournisseurTest');
require_once dirname(__FILE__).'/ContratTest.php';
$suite->addTestSuite('ContratTest');
require_once dirname(__FILE__).'/FactureTest.php'; require_once dirname(__FILE__).'/FactureTest.php';
$suite->addTestSuite('FactureTest'); $suite->addTestSuite('FactureTest');
require_once dirname(__FILE__).'/FactureRecTest.php'; require_once dirname(__FILE__).'/FactureRecTest.php';
@ -139,8 +146,7 @@ class AllTests
$suite->addTestSuite('FactureTestRounding'); $suite->addTestSuite('FactureTestRounding');
require_once dirname(__FILE__).'/FactureFournisseurTest.php'; require_once dirname(__FILE__).'/FactureFournisseurTest.php';
$suite->addTestSuite('FactureFournisseurTest'); $suite->addTestSuite('FactureFournisseurTest');
require_once dirname(__FILE__).'/PropalTest.php';
$suite->addTestSuite('PropalTest');
require_once dirname(__FILE__).'/UserTest.php'; require_once dirname(__FILE__).'/UserTest.php';
$suite->addTestSuite('UserTest'); $suite->addTestSuite('UserTest');
require_once dirname(__FILE__).'/UserGroupTest.php'; require_once dirname(__FILE__).'/UserGroupTest.php';