';
print '' . $langs->trans("Total") . ' ';
@@ -302,7 +326,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
print '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . ' ';
}
print '' . $langs->trans("Total") . ' ';
-
+
$sql = "SELECT '" . $langs->trans("TotalExpenseReport") . "' AS label,";
for($i = 1; $i <= 12; $i ++) {
$sql .= " SUM(" . $db->ifsql('MONTH(er.date_create)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
@@ -314,12 +338,12 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
$sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
$sql .= " AND er.fk_statut > 0 ";
$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy
-
+
dol_syslog('htdocs/accountancy/expensereport/index.php');
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
-
+
while ( $row = $db->fetch_row($resql)) {
print '' . $row[0] . ' ';
for($i = 1; $i <= 12; $i ++) {
@@ -328,7 +352,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
print '' . price($row[13]) . ' ';
print ' ';
}
-
+
$db->free($resql);
} else {
print $db->lasterror(); // Show last sql error
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 505e2a9f534..640c4b03353 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -104,12 +104,15 @@ $idpays = $mysoc->country_id;
$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
$sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
-$sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,";
-$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, bu2.type as typeop";
+$sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop_company,";
+$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, bu2.type as typeop_user,";
+$sql .= " bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on bu2.url_id=u.rowid";
$sql .= " WHERE ba.fk_accountancy_journal=" . $id_journal;
@@ -147,6 +150,7 @@ $result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
+ //print $sql;
// Variables
$account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word
@@ -172,13 +176,31 @@ if ($result) {
{
$obj = $db->fetch_object($result);
- // Set accountancy code (for bank and thirdparty)
+ $lineisapurchase = -1;
+ $lineisasale = -1;
+ // Old method to detect if it's a sale or purchase
+ if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') $lineisapurchase=1;
+ if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') $lineisasale=1;
+ // Try a more reliable method to detect if record is a supplier payment or a customer payment
+ if ($lineisapurchase < 0)
+ {
+ if ($obj->typeop_payment_supplier == 'payment_supplier') $lineisapurchase = 1;
+ }
+ if ($lineisasale < 0)
+ {
+ if ($obj->typeop_payment == 'payment') $lineisasale = 1;
+ }
+ //var_dump($obj->type_payment); var_dump($obj->type_payment_supplier);
+ //var_dump($lineisapurchase); //var_dump($lineisasale);
+
+ // Set accountancy code for bank
$compta_bank = $obj->account_number;
+ // Set accountancy code for thirdparty
$compta_soc = 'NotDefined';
- if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)')
+ if ($lineisapurchase > 0)
$compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
- if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)')
+ if ($lineisasale > 0)
$compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
$tabcompany[$obj->rowid] = array (
@@ -187,6 +209,7 @@ if ($result) {
'code_compta' => $compta_soc,
);
+ // Set accountancy code for user
$compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
$tabuser[$obj->rowid] = array (
@@ -202,6 +225,7 @@ if ($result) {
$tabpay[$obj->rowid]["type_payment"] = $obj->fk_type; // CHQ, VIR, LIQ, CB, ...
$tabpay[$obj->rowid]["ref"] = $obj->label; // By default. Not unique. May be changed later
$tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
+ $tabpay[$obj->rowid]["bank_account_ref"] = $obj->baref;
$tabpay[$obj->rowid]["fk_bank_account"] = $obj->fk_account;
if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) {
$tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
@@ -214,7 +238,7 @@ if ($result) {
//var_dump($tabpay);
// By default
- $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or old record with no links in bank_url.
+ $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or any old record with no links in bank_url.
$tabtype[$obj->rowid] = 'unknown';
// get_url may return -1 which is not traversable
@@ -604,6 +628,8 @@ if (! $error && $action == 'writebookkeeping') {
}
}
+
+
// Export
if ($action == 'exportcsv') { // ISO and not UTF8 !
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
@@ -737,6 +763,22 @@ if (empty($action) || $action == 'view') {
journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
+
+ // Test that setup is complete
+ $sql='SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'bank_account WHERE fk_accountancy_journal IS NULL';
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj=$db->fetch_object($resql);
+ if ($obj->nb > 0)
+ {
+ print img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount");
+ print ' : '.$langs->trans("AccountancyAreaDescBank", 9, ''.$langs->transnoentitiesnoconv("MenuBankCash").' ');
+ }
+ }
+ else dol_print_error($db);
+
+
// Button to write into Ledger
if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1'
|| empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1'
@@ -797,8 +839,10 @@ if (empty($action) || $action == 'view') {
// Bank
foreach ( $tabbq[$key] as $k => $mt )
{
+ //var_dump($tabpay[$key]);
+ print '';
print '';
- print " ";
+ print " ";
print "" . $date . " ";
print "" . $ref . " ";
// Ledger account
@@ -819,11 +863,14 @@ if (empty($action) || $action == 'view') {
}
else print $accounttoshow;*/
print "";
- if ($val['soclib'] == '') {
- print "" . $langs->trans("Bank") . " - " . $reflabel . " ";
- } else {
- print "" . $langs->trans("Bank") . " - " . $val['soclib'] . " ";
+ print "";
+ //var_dump($tabpay[$key]);
+ print $langs->trans("Bank");
+ print ' '.$val['bank_account_ref'];
+ if (! empty($val['soclib'])) {
+ print " - " . $val['soclib'];
}
+ print " ";
print "" . $val["type_payment"] . " ";
print "" . ($mt >= 0 ? price($mt) : '') . " ";
print "" . ($mt < 0 ? price(- $mt) : '') . " ";
@@ -834,14 +881,15 @@ if (empty($action) || $action == 'view') {
if (is_array($tabtp[$key])) {
foreach ( $tabtp[$key] as $k => $mt ) {
if ($k != 'type') {
+ print '';
print ' ';
- print " ";
+ print " ";
print "" . $date . " ";
print "" . $ref . " ";
// Ledger account
print "";
$account_ledger = $k;
-
+ // Try to force general ledger account depending on type
if ($tabtype[$key] == 'payment') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
if ($tabtype[$key] == 'payment_supplier') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
if ($tabtype[$key] == 'payment_expensereport') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
@@ -878,7 +926,11 @@ if (empty($action) || $action == 'view') {
{
if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined')
{
- print ''.$langs->trans("ThirdpartyAccountNotDefined").' ';
+ /*var_dump($tabpay[$key]);
+ var_dump($tabtype[$key]);
+ var_dump($tabbq[$key]);*/
+ //print ''.$langs->trans("ThirdpartyAccountNotDefined").' ';
+ print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown").' ';
}
else print $accounttoshowsubledger;
}
@@ -893,8 +945,9 @@ if (empty($action) || $action == 'view') {
}
} else {
foreach ( $tabbq[$key] as $k => $mt ) {
+ print '';
print ' ';
- print " ";
+ print " ";
print "" . $date . " ";
print "" . $ref . " ";
// Ledger account
@@ -936,7 +989,7 @@ $db->close();
* Return source for doc_ref of a bank transaction
*
* @param string $val Array of val
- * @param string $typerecord Type of record
+ * @param string $typerecord Type of record ('payment', 'payment_supplier', 'payment_expensereport', 'payment_vat', ...)
* @return string|unknown
*/
function getSourceDocRef($val, $typerecord)
diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php
index f862feb5ba3..3dac6a23567 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -190,8 +190,8 @@ for($i = 1; $i <= 12; $i ++) {
}
print '' . $langs->trans("Total") . ' ';
-$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') ." AS codecomptable,";
-$sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.label') . " AS intitule,";
+$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,";
+$sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,";
for($i = 1; $i <= 12; $i ++) {
$sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
}
@@ -213,8 +213,20 @@ if ($resql) {
while ( $row = $db->fetch_row($resql)) {
- print '' . length_accountg($row[0]) . ' ';
- print '' . $row[1] . ' ';
+ print '';
+ if ($row[0] == 'tobind')
+ {
+ print $langs->trans("Unknown");
+ }
+ else print length_accountg($row[0]);
+ print ' ';
+ print '';
+ if ($row[0] == 'tobind')
+ {
+ print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.$y, $langs->transnoentitiesnoconv("ToBind"));
+ }
+ else print $row[1];
+ print ' ';
for($i = 2; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' ';
}
@@ -244,8 +256,8 @@ for($i = 1; $i <= 12; $i ++) {
}
print '' . $langs->trans("Total") . ' ';
-$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') ." AS codecomptable,";
-$sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.label') . " AS intitule,";
+$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,";
+$sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,";
for($i = 1; $i <= 12; $i ++) {
$sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
}
@@ -267,9 +279,21 @@ if ($resql) {
while ( $row = $db->fetch_row($resql)) {
- print '' . length_accountg($row[0]) . ' ';
- print '' . $row[1] . ' ';
- for($i = 2; $i <= 12; $i ++) {
+ print '';
+ if ($row[0] == 'tobind')
+ {
+ print $langs->trans("Unknown");
+ }
+ else print length_accountg($row[0]);
+ print ' ';
+ print '';
+ if ($row[0] == 'tobind')
+ {
+ print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.$y, $langs->transnoentitiesnoconv("ToBind"));
+ }
+ else print $row[1];
+ print ' ';
+ for($i = 2; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' ';
}
print '' . price($row[13]) . ' ';
diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php
index 016fc5e0499..a0f36c409de 100644
--- a/htdocs/adherents/type.php
+++ b/htdocs/adherents/type.php
@@ -390,13 +390,13 @@ if ($rowid > 0)
}
if ($status != '')
{
- $sql.= " AND d.statut IN (".$status.")"; // Peut valoir un nombre ou liste de nombre separes par virgules
+ $sql.= " AND d.statut IN (".$db->escape($status).")"; // Peut valoir un nombre ou liste de nombre separes par virgules
}
if ($action == 'search')
{
if (GETPOST('search'))
{
- $sql.= natural_search(array("d.firstname","d.lastname"), GETPOST('search'));
+ $sql.= natural_search(array("d.firstname","d.lastname"), GETPOST('search','alpha'));
}
}
if (! empty($search_lastname))
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 40068ec81e8..52e90b21956 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -1119,7 +1119,7 @@ if ($id)
}
if ($id == 4) print ' ';
- print '';
+ print ' ';
if ($action != 'edit')
{
print ' ';
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index ecf95c5096d..05d9049ff03 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -1540,17 +1540,30 @@ class Categorie extends CommonObject
dol_mkdir($dir);
}
- if (file_exists($dir))
- {
- $originImage = $dir . $file['name'];
+ if (file_exists($dir)) {
+ if (is_array($file['name']) && count($file['name']) > 0) {
+ for($i = 0; $i <= count($file['name']); $i ++) {
- // Cree fichier en taille origine
- dol_move_uploaded_file($file['tmp_name'], $originImage, 1, 0, 0);
+ $originImage = $dir . $file['name'][$i];
- if (file_exists($originImage))
- {
- // Create thumbs
- $this->addThumbs($originImage);
+ // Cree fichier en taille origine
+ dol_move_uploaded_file($file['tmp_name'][$i], $originImage, 1, 0, 0);
+
+ if (file_exists($originImage)) {
+ // Create thumbs
+ $this->addThumbs($originImage);
+ }
+ }
+ } else {
+ $originImage = $dir . $file['name'];
+
+ // Cree fichier en taille origine
+ dol_move_uploaded_file($file['tmp_name'], $originImage, 1, 0, 0);
+
+ if (file_exists($originImage)) {
+ // Create thumbs
+ $this->addThumbs($originImage);
+ }
}
}
}
diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php
index a0744fcfa04..ce6a9cf9896 100644
--- a/htdocs/comm/mailing/class/advtargetemailing.class.php
+++ b/htdocs/comm/mailing/class/advtargetemailing.class.php
@@ -640,16 +640,16 @@ class AdvanceTargetingMailing extends CommonObject
$sqlwhere[]=$this->transformToSQL('t.firstname',$arrayquery['contact_firstname']);
}
if (!empty($arrayquery['contact_country']) && count($arrayquery['contact_country'])) {
- $sqlwhere[]= " (t.fk_pays IN (".implode(',',$arrayquery['contact_country'])."))";
+ $sqlwhere[]= " (t.fk_pays IN (".$db->escape(implode(',',$arrayquery['contact_country']))."))";
}
if (!empty($arrayquery['contact_status']) && count($arrayquery['contact_status'])>0) {
- $sqlwhere[]= " (t.statut IN (".implode(',',$arrayquery['contact_status'])."))";
+ $sqlwhere[]= " (t.statut IN (".$db->escape(implode(',',$arrayquery['contact_status']))."))";
}
if (!empty($arrayquery['contact_civility']) && count($arrayquery['contact_civility'])>0) {
- $sqlwhere[]= " (t.civility IN ('".implode("','",$arrayquery['contact_civility'])."'))";
+ $sqlwhere[]= " (t.civility IN ('".$db->escape(implode("','",$arrayquery['contact_civility']))."'))";
}
if ($arrayquery['contact_no_email']!='') {
- $sqlwhere[]= " (t.no_email='".$arrayquery['contact_no_email']."')";
+ $sqlwhere[]= " (t.no_email='".$db->escape($arrayquery['contact_no_email'])."')";
}
if ($arrayquery['contact_update_st_dt']!='') {
$sqlwhere[]= " (t.tms >= '".$this->db->idate($arrayquery['contact_update_st_dt'])."' AND t.tms <= '".$this->db->idate($arrayquery['contact_update_end_dt'])."')";
@@ -658,7 +658,7 @@ class AdvanceTargetingMailing extends CommonObject
$sqlwhere[]= " (t.datec >= '".$this->db->idate($arrayquery['contact_create_st_dt'])."' AND t.datec <= '".$this->db->idate($arrayquery['contact_create_end_dt'])."')";
}
if (!empty($arrayquery['contact_categ']) && count($arrayquery['contact_categ'])>0) {
- $sqlwhere[]= " (contactcateg.fk_categorie IN (".implode(",",$arrayquery['contact_categ'])."))";
+ $sqlwhere[]= " (contactcateg.fk_categorie IN (".$db->escape(implode(",",$arrayquery['contact_categ']))."))";
}
//Standard Extrafield feature
diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php
index 5c74c8374a0..273862f68bf 100644
--- a/htdocs/comm/propal/stats/index.php
+++ b/htdocs/comm/propal/stats/index.php
@@ -92,7 +92,7 @@ dol_mkdir($dir);
$stats = new PropaleStats($db, $socid, ($userid>0?$userid:0), $mode);
-if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND p.fk_statut IN ('.$object_status.')';
+if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND p.fk_statut IN ('.$db->escape($object_status).')';
// Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
@@ -299,7 +299,7 @@ foreach ($data as $val)
while (! empty($year) && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
-
+
print ' ';
print '0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.' ';
print '0 ';
diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php
index ed9f8906804..6a8b57e3707 100644
--- a/htdocs/commande/stats/index.php
+++ b/htdocs/commande/stats/index.php
@@ -88,11 +88,11 @@ dol_mkdir($dir);
$stats = new CommandeStats($db, $socid, $mode, ($userid>0?$userid:0));
if ($mode == 'customer')
{
- if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND c.fk_statut IN ('.$object_status.')';
+ if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
}
if ($mode == 'supplier')
{
- if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND c.fk_statut IN ('.$object_status.')';
+ if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')';
}
diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php
index 52fb375000c..cbeba2828e7 100644
--- a/htdocs/compta/facture/class/facture-rec.class.php
+++ b/htdocs/compta/facture/class/facture-rec.class.php
@@ -34,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
/**
- * Classe de gestion des factures recurrentes/Modeles
+ * Class to manage invoice templates
*/
class FactureRec extends CommonInvoice
{
@@ -43,7 +43,7 @@ class FactureRec extends CommonInvoice
public $table_element_line='facturedet_rec';
public $fk_element='fk_facture';
public $picto='bill';
-
+
var $entity;
var $number;
var $date;
@@ -58,7 +58,10 @@ class FactureRec extends CommonInvoice
var $date_when;
var $nb_gen_done;
var $nb_gen_max;
-
+
+ var $frequency;
+ var $unit_frequency;
+
var $rang;
var $special_code;
@@ -91,20 +94,20 @@ class FactureRec extends CommonInvoice
// Clean parameters
$this->titre=trim($this->titre);
$this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
-
+
// No frequency defined then no next date to execution
- if (empty($this->frequency))
+ if (empty($this->frequency))
{
$this->frequency=0;
$this->date_when=NULL;
}
-
-
+
+
$this->frequency=abs($this->frequency);
$this->nb_gen_done=0;
$this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max;
$this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate;
-
+
$this->db->begin();
// Charge facture modele
@@ -197,7 +200,7 @@ class FactureRec extends CommonInvoice
$error++;
}
}
-
+
// Add object linked
if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
{
@@ -210,7 +213,7 @@ class FactureRec extends CommonInvoice
$error++;
}
}
- }
+ }
if ($error)
{
@@ -268,7 +271,7 @@ class FactureRec extends CommonInvoice
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
*/
-
+
$result = $this->db->query($sql);
if ($result)
{
@@ -361,8 +364,8 @@ class FactureRec extends CommonInvoice
{
return $this->fetch_lines();
}
-
-
+
+
/**
* Recupere les lignes de factures predefinies dans this->lines
*
@@ -386,7 +389,7 @@ class FactureRec extends CommonInvoice
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= ' WHERE l.fk_facture = '.$this->id;
$sql.= ' ORDER BY l.rang';
-
+
dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
@@ -431,7 +434,7 @@ class FactureRec extends CommonInvoice
$line->special_code = $objp->special_code;
$line->fk_unit = $objp->fk_unit;
$line->fk_contract_line = $objp->fk_contract_line;
-
+
// Ne plus utiliser
$line->price = $objp->price;
$line->remise = $objp->remise;
@@ -463,12 +466,12 @@ class FactureRec extends CommonInvoice
function delete($user, $notrigger=0, $idwarehouse=-1)
{
$rowid=$this->id;
-
+
dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
-
+
$error=0;
$this->db->begin();
-
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid;
dol_syslog($sql);
if ($this->db->query($sql))
@@ -481,7 +484,7 @@ class FactureRec extends CommonInvoice
$res = $this->deleteObjectLinked();
if ($res < 0) $error=-3;
}
- else
+ else
{
$this->error=$this->db->lasterror();
$error=-1;
@@ -492,7 +495,7 @@ class FactureRec extends CommonInvoice
$this->error=$this->db->lasterror();
$error=-2;
}
-
+
if (! $error)
{
$this->db->commit();
@@ -531,7 +534,7 @@ class FactureRec extends CommonInvoice
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null)
{
global $mysoc;
-
+
$facid=$this->id;
dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG);
@@ -557,11 +560,14 @@ class FactureRec extends CommonInvoice
if (empty($remise_percent)) $remise_percent=0;
$qty=price2num($qty);
if (! $info_bits) $info_bits=0;
- $pu_ht=price2num($pu_ht);
- $pu_ttc=price2num($pu_ttc);
- $txtva=price2num($txtva);
- $txlocaltax1 = price2num($txlocaltax1);
- $txlocaltax2 = price2num($txlocaltax2);
+ $pu_ht = price2num($pu_ht);
+ $pu_ttc = price2num($pu_ttc);
+ $txtva = price2num($txtva);
+ $txlocaltax1 = price2num($txlocaltax1);
+ $txlocaltax2 = price2num($txlocaltax2);
+ if (empty($txtva)) $txtva=0;
+ if (empty($txlocaltax1)) $txlocaltax1=0;
+ if (empty($txlocaltax2)) $txlocaltax2=0;
if ($price_base_type=='HT')
{
@@ -584,7 +590,7 @@ class FactureRec extends CommonInvoice
$total_ttc = $tabprice[2];
$total_localtax1=$tabprice[9];
$total_localtax2=$tabprice[10];
-
+
$product_type=$type;
if ($fk_product)
{
@@ -685,12 +691,12 @@ class FactureRec extends CommonInvoice
function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null)
{
global $mysoc;
-
+
$facid=$this->id;
-
+
dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
-
+
// Check parameters
if ($type < 0) return -1;
@@ -715,7 +721,7 @@ class FactureRec extends CommonInvoice
$txtva=price2num($txtva);
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
-
+
if ($price_base_type=='HT')
{
$pu=$pu_ht;
@@ -724,7 +730,7 @@ class FactureRec extends CommonInvoice
{
$pu=$pu_ttc;
}
-
+
// Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
@@ -736,7 +742,7 @@ class FactureRec extends CommonInvoice
$total_ttc = $tabprice[2];
$total_localtax1=$tabprice[9];
$total_localtax2=$tabprice[10];
-
+
$product_type=$type;
if ($fk_product)
{
@@ -744,7 +750,7 @@ class FactureRec extends CommonInvoice
$result=$product->fetch($fk_product);
$product_type=$product->type;
}
-
+
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
$sql.= "fk_facture = '".$facid."'";
$sql.= ", label=".(! empty($label)?"'".$this->db->escape($label)."'":"null");
@@ -784,12 +790,12 @@ class FactureRec extends CommonInvoice
return -1;
}
}
- }
-
-
+ }
+
+
/**
- * Return the next date of
- *
+ * Return the next date of
+ *
* @return timestamp false if KO, timestamp if OK
*/
function getNextDate()
@@ -797,27 +803,27 @@ class FactureRec extends CommonInvoice
if (empty($this->date_when)) return false;
return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
}
-
+
/**
* Create all recurrents invoices (for all entities if multicompany is used).
* A result may also be provided into this->output.
- *
- * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found.
- *
- * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
+ *
+ * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found.
+ *
+ * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
*/
function createRecurringInvoices()
{
global $conf, $langs, $db, $user;
-
+
$langs->load("bills");
-
+
$nb_create=0;
-
+
$now = dol_now();
$tmparray=dol_getdate($now);
$today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
-
+
dol_syslog("createRecurringInvoices");
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
$sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
@@ -825,30 +831,30 @@ class FactureRec extends CommonInvoice
$sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
$sql.= $db->order('entity', 'ASC');
//print $sql;exit;
-
+
$resql = $db->query($sql);
if ($resql)
{
$i=0;
$num = $db->num_rows($resql);
-
+
if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
-
+
$saventity = $conf->entity;
-
+
while ($i < $num) // Loop on each template invoice
{
$line = $db->fetch_object($resql);
$db->begin();
-
+
$facturerec = new FactureRec($db);
$facturerec->fetch($line->rowid);
-
+
// Set entity context
$conf->entity = $facturerec->entity;
-
+
dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
$error=0;
@@ -856,12 +862,12 @@ class FactureRec extends CommonInvoice
$facture = new Facture($db);
$facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
$facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
-
+
$facture->type = self::TYPE_STANDARD;
$facture->brouillon = 1;
$facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
$facture->socid = $facturerec->socid;
-
+
$invoiceidgenerated = $facture->create($user);
if ($invoiceidgenerated <= 0)
{
@@ -894,16 +900,16 @@ class FactureRec extends CommonInvoice
$i++;
}
-
+
$conf->entity = $saventity; // Restore entity context
}
else dol_print_error($db);
-
+
$this->output=trim($this->output);
-
+
return $error?$error:0;
}
-
+
/**
* Return clicable name (with picto eventually)
*
@@ -920,13 +926,13 @@ class FactureRec extends CommonInvoice
$result='';
$label=$langs->trans("ShowInvoice").': '.$this->ref;
-
+
$url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id;
-
+
if ($short) return $url;
-
+
$picto='bill';
-
+
$link = '';
$linkend=' ';
@@ -958,7 +964,7 @@ class FactureRec extends CommonInvoice
// Load array of products prodids
$num_prods = 0;
$prodids = array();
-
+
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE entity IN (".getEntity('product').")";
@@ -1071,7 +1077,7 @@ class FactureRec extends CommonInvoice
$this->lines[$xnbp]=$line;
$xnbp++;
}
-
+
$this->usenewprice = 1;
}
@@ -1091,7 +1097,7 @@ class FactureRec extends CommonInvoice
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
}
-
+
/**
* Update frequency and unit
*
@@ -1115,12 +1121,12 @@ class FactureRec extends CommonInvoice
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null');
- if (!empty($unit))
+ if (!empty($unit))
{
$sql.= ', unit_frequency = \''.$this->db->escape($unit).'\'';
}
$sql.= ' WHERE rowid = '.$this->id;
-
+
dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
if ($this->db->query($sql))
{
@@ -1134,7 +1140,7 @@ class FactureRec extends CommonInvoice
return -1;
}
}
-
+
/**
* Update the next date of execution
*
@@ -1167,7 +1173,7 @@ class FactureRec extends CommonInvoice
return -1;
}
}
-
+
/**
* Update the maximum period
*
@@ -1181,9 +1187,9 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
-
+
if (empty($nb)) $nb=0;
-
+
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET nb_gen_max = '.$nb;
$sql.= ' WHERE rowid = '.$this->id;
@@ -1200,7 +1206,7 @@ class FactureRec extends CommonInvoice
return -1;
}
}
-
+
/**
* Update the auto validate invoice
*
@@ -1214,7 +1220,7 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
-
+
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET auto_validate = '.$validate;
$sql.= ' WHERE rowid = '.$this->id;
@@ -1241,7 +1247,7 @@ class FactureRec extends CommonInvoice
*/
class FactureLigneRec extends CommonInvoiceLine
{
-
+
/**
* Delete line in database
*
@@ -1250,11 +1256,11 @@ class FactureLigneRec extends CommonInvoiceLine
function delete()
{
global $conf,$langs,$user;
-
+
$error=0;
-
+
$this->db->begin();
-
+
// Call trigger
/*$result=$this->call_trigger('LINEBILLREC_DELETE',$user);
if ($result < 0)
@@ -1263,8 +1269,8 @@ class FactureLigneRec extends CommonInvoiceLine
return -1;
}*/
// End call triggers
-
-
+
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if ($this->db->query($sql) )
@@ -1279,5 +1285,5 @@ class FactureLigneRec extends CommonInvoiceLine
return -1;
}
}
-
+
}
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index 55ff4dad6e3..bf54e4f58ab 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -84,11 +84,11 @@ dol_mkdir($dir);
$stats = new FactureStats($db, $socid, $mode, ($userid>0?$userid:0));
if ($mode == 'customer')
{
- if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND f.fk_statut IN ('.$object_status.')';
+ if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
}
if ($mode == 'supplier')
{
- if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$object_status.')';
+ if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->escape($object_status).')';
}
// Build graphic number of object
@@ -299,7 +299,7 @@ foreach ($data as $val)
while ($year && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
-
+
print ' ';
print '0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.' ';
print '0 ';
@@ -310,7 +310,7 @@ foreach ($data as $val)
print ' ';
print ' ';
}
-
+
print '';
print '0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$year.' ';
print ''.$val['nb'].' ';
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index e2e036c3700..6a7659cd925 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -770,24 +770,24 @@ class ExtraFields
if (empty($showsize))
{
- if ($type == 'date')
+ if ($type == 'date')
{
//$showsize=10;
$showsize = 'minwidth100imp';
}
- elseif ($type == 'datetime')
+ elseif ($type == 'datetime')
{
//$showsize=19;
$showsize = 'minwidth200imp';
}
- elseif (in_array($type,array('int','double')))
+ elseif (in_array($type,array('int','double','price')))
{
//$showsize=10;
- $showsize = 'minwidth100imp';
+ $showsize = 'maxwidth75';
}
elseif ($type == 'url')
{
- $showsize='minwidth400imp';
+ $showsize='minwidth400';
}
elseif ($type == 'boolean')
{
@@ -797,16 +797,16 @@ class ExtraFields
{
if (round($size) < 12)
{
- $showsize = 'minwidth100imp';
+ $showsize = 'minwidth100';
}
else if (round($size) <= 48)
{
- $showsize = 'minwidth200imp';
+ $showsize = 'minwidth200';
}
else
{
//$showsize=48;
- $showsize = 'minwidth400imp';
+ $showsize = 'minwidth400';
}
}
}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index b7a2b46dfc0..c8ea494ad3a 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -1918,7 +1918,7 @@ class Form
$sql.= ' WHERE p.entity IN ('.getEntity('product').')';
if (count($warehouseStatusArray))
{
- $sql.= ' AND (p.fk_product_type = 1 OR e.statut IN ('.implode(',',$warehouseStatusArray).'))';
+ $sql.= ' AND (p.fk_product_type = 1 OR e.statut IN ('.$db->escape(implode(',',$warehouseStatusArray)).'))';
}
if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php
index 71912714b90..c45c5a88e29 100644
--- a/htdocs/core/lib/date.lib.php
+++ b/htdocs/core/lib/date.lib.php
@@ -115,26 +115,28 @@ function getServerTimeZoneInt($refgmtdate='now')
*/
function dol_time_plus_duree($time, $duration_value, $duration_unit)
{
+ global $conf;
+
if ($duration_value == 0) return $time;
if ($duration_unit == 'h') return $time + (3600*$duration_value);
if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value);
-
+
$deltastring='P';
-
+
if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; }
if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; }
if ($duration_unit == 'd') { $deltastring.="D"; }
if ($duration_unit == 'm') { $deltastring.="M"; }
if ($duration_unit == 'y') { $deltastring.="Y"; }
-
+
$date = new DateTime();
- $date->setTimezone(new DateTimeZone('UTC'));
+ if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($time);
$interval = new DateInterval($deltastring);
-
+
if($sub) $date->sub($interval);
else $date->add( $interval );
-
+
return $date->getTimestamp();
}
diff --git a/htdocs/core/modules/syslog/mod_syslog_syslog.php b/htdocs/core/modules/syslog/mod_syslog_syslog.php
index e0283ac9a9f..1f2f499fbac 100644
--- a/htdocs/core/modules/syslog/mod_syslog_syslog.php
+++ b/htdocs/core/modules/syslog/mod_syslog_syslog.php
@@ -49,7 +49,7 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
public function isActive()
{
global $conf;
-
+
// This function does not exists on some ISP (Ex: Free in France)
if (!function_exists('openlog')) return 0;
@@ -81,15 +81,15 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
*/
public function checkConfiguration()
{
- global $langs;
+ global $conf, $langs;
$errors = array();
- $facility = SYSLOG_FACILITY;
+ $facility = constant($conf->global->SYSLOG_FACILITY);
if ($facility)
{
// Only LOG_USER supported on Windows
- if (! empty($_SERVER["WINDIR"])) $facility='LOG_USER';
+ if (! empty($_SERVER["WINDIR"])) $facility=constant('LOG_USER');
dol_syslog("admin/syslog: facility ".$facility);
}
diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php
index d6defba0fa9..c7b3ea7342f 100644
--- a/htdocs/core/tpl/contacts.tpl.php
+++ b/htdocs/core/tpl/contacts.tpl.php
@@ -35,13 +35,13 @@ elseif ($module == 'project') { $permission=$user->rights->projet->creer; }
elseif ($module == 'action') { $permission=$user->rights->agenda->myactions->create; }
elseif ($module == 'shipping') { $permission=$user->rights->expedition->creer; }
elseif ($module == 'project_task') { $permission=$user->rights->projet->creer; }
-elseif (! isset($permission) && isset($user->rights->$module->creer))
-{
- $permission=$user->rights->$module->creer;
+elseif (! isset($permission) && isset($user->rights->$module->creer))
+{
+ $permission=$user->rights->$module->creer;
}
elseif (! isset($permission) && isset($user->rights->$module->write))
{
- $permission=$user->rights->$module->write;
+ $permission=$user->rights->$module->write;
}
$formcompany= new FormCompany($db);
@@ -55,8 +55,8 @@ $userstatic=new User($db);