Browse Source

Merge pull request #6546 from aspangaro/6.0-new_bank_direct_input

New : Add Various payment submodule linked to the accountancy to replace free input in bank
Laurent Destailleur 8 years ago
parent
commit
278bbf184c

+ 23 - 24
htdocs/accountancy/admin/index.php

@@ -142,18 +142,17 @@ if ($action == 'setmanagezero') {
 }
 
 if ($action == 'setdisabledirectinput') {
-    $setdisabledirectinput = GETPOST('value', 'int');
-    $res = dolibarr_set_const($db, "BANK_DISABLE_DIRECT_INPUT", $setdisabledirectinput, 'yesno', 0, '', $conf->entity);
-    if (! $res > 0)
-        $error ++;
-        if (! $error) {
-            setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
-        } else {
-            setEventMessages($langs->trans("Error"), null, 'mesgs');
-        }
+	$setdisabledirectinput = GETPOST('value', 'int');
+	$res = dolibarr_set_const($db, "BANK_DISABLE_DIRECT_INPUT", $setdisabledirectinput, 'yesno', 0, '', $conf->entity);
+	if (! $res > 0)
+		$error ++;
+		if (! $error) {
+			setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
+		} else {
+			setEventMessages($langs->trans("Error"), null, 'mesgs');
+		}
 }
 
-
 /*
  * View
  */
@@ -243,20 +242,20 @@ if (! empty($user->admin))
     }
     print '</tr>';
 
-    $var = ! $var;
-    print "<tr " . $bc[$var] . ">";
-    print '<td>' . $langs->trans("BANK_DISABLE_DIRECT_INPUT") . '</td>';
-    if (! empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
-        print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=0">';
-        print img_picto($langs->trans("Activated"), 'switch_on');
-        print '</a></td>';
-    } else {
-        print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=1">';
-        print img_picto($langs->trans("Disabled"), 'switch_off');
-        print '</a></td>';
-    }
-    print '</tr>';
-    
+	$var = ! $var;
+	print "<tr " . $bc[$var] . ">";
+	print '<td>' . $langs->trans("BANK_DISABLE_DIRECT_INPUT") . '</td>';
+	if (! empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
+		print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=0">';
+		print img_picto($langs->trans("Activated"), 'switch_on');
+		print '</a></td>';
+	} else {
+		print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=1">';
+		print img_picto($langs->trans("Disabled"), 'switch_off');
+		print '</a></td>';
+	}
+	print '</tr>';
+
     $var = ! $var;
     print "<tr " . $bc[$var] . ">";
     print '<td>' . $langs->trans("ACCOUNTING_MANAGE_ZERO") . '</td>';

+ 7 - 6
htdocs/accountancy/class/accountingaccount.class.php

@@ -369,22 +369,23 @@ class AccountingAccount extends CommonObject
 	 */
 	function getNomUrl($withpicto = 0) {
 		global $langs;
-		
+
 		$result = '';
-		
+
 		$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?id=' . $this->id . '">';
 		$linkend = '</a>';
-		
+
 		$picto = 'billr';
-		
+
 		$label = $langs->trans("Show") . ': ' . $this->account_number . ' - ' . $this->label;
-		
+
 		if ($withpicto)
 			$result .= ($link . img_object($label, $picto) . $linkend);
 		if ($withpicto && $withpicto != 2)
 			$result .= ' ';
 		if ($withpicto != 2)
-			$result .= $link . $this->account_number . $linkend;
+			require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
+			$result .= $link . length_accountg($this->account_number) . ' - ' . $this->label . $linkend;
 		return $result;
 	}
 	

+ 21 - 66
htdocs/compta/bank/bankentries.php

@@ -4,8 +4,9 @@
  * Copyright (C) 2005-2010  Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2012       Vinícius Nogueira    <viniciusvgn@gmail.com>
  * Copyright (C) 2014       Florian Henry    	 <florian.henry@open-cooncept.pro>
- * Copyright (C) 2015       Jean-François Ferry	<jfefe@aternatik.fr>
+ * Copyright (C) 2015       Jean-François Ferry	 <jfefe@aternatik.fr>
  * Copyright (C) 2016       Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2017       Alexandre Spangaro   <aspangaro@zendsi.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -396,40 +397,37 @@ if ($id > 0 || ! empty($ref))
     foreach ($bankcateg->fetchAll() as $bankcategory) {
         $options[$bankcategory->id] = $bankcategory->label;
     }
-    
+
     // Bank card
-    
     $head=bank_prepare_head($object);
     dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account');
-    
+
     $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/index.php">'.$langs->trans("BackToList").'</a>';
-    
+
     dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
-    
+
     dol_fiche_end();
  
-
-
     /*
      * Buttons actions
      */
-    if ($action != 'addline' && $action != 'reconcile')
+    if ($action != 'reconcile')
     {
         print '<div class="tabsAction">';
-    
-        if ($action != 'addline')
-        {
-            if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT))
-            {
-                if ($user->rights->banque->modifier) {
-                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param.'">'.$langs->trans("AddBankRecord").'</a>';
-                } else {
-                    print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("AddBankRecord").'</a>';
-                }
-            } else {
-                print '<a class="butActionRefused" title="'.$langs->trans("FeatureDisabled").'" href="#">'.$langs->trans("AddBankRecord").'</a>';
-            }
-        }
+
+		if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT))
+		{
+			if ($user->rights->banque->modifier) {
+				print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.$account.'">'.$langs->trans("AddBankRecord").'</a>';
+			} else {
+				print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("AddBankRecord").'</a>';
+			}
+		}
+		else
+		{
+			print '<a class="butActionRefused" title="'.$langs->trans("FeatureDisabled").'" href="#">'.$langs->trans("AddBankRecord").'</a>';
+		}
+
         if ($object->canBeConciliated() > 0) {
             // If not cash account and can be reconciliate
             if ($user->rights->banque->consolidate) {
@@ -640,49 +638,6 @@ if ($resql)
 //	    print '</td></tr></table>';
 	}
 
-	// Form to add a transaction with no invoice
-	if ($user->rights->banque->modifier && $action == 'addline')
-	{
-	    print load_fiche_titre($langs->trans("AddBankRecordLong"),'','');
-	
-	    print '<table class="noborder" width="100%">';
-	    print '<tr class="liste_titre">';
-	    print '<td>'.$langs->trans("Date").'</td>';
-	    print '<td>&nbsp;</td>';
-	    print '<td>'.$langs->trans("Type").'</td>';
-	    print '<td>'.$langs->trans("Numero").'</td>';
-	    print '<td colspan="2">'.$langs->trans("Description").'</td>';
-	    print '<td align=right>'.$langs->trans("Debit").'</td>';
-	    print '<td align=right>'.$langs->trans("Credit").'</td>';
-	    print '<td colspan="2" align="center">&nbsp;</td>';
-	    print '</tr>';
-	
-	    print '<tr '.$bcnd[false].'>';
-	    print '<td class="nowrap" colspan="2">';
-	    $form->select_date(empty($dateop)?-1:$dateop,'op',0,0,0,'transaction');
-	    print '</td>';
-	    print '<td class="nowrap">';
-	    $form->select_types_paiements((GETPOST('operation')?GETPOST('operation'):($object->courant == Account::TYPE_CASH ? 'LIQ' : '')),'operation','1,2',2,1);
-	    print '</td><td>';
-	    print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq").'"></td>';
-	    print '<td colspan="2">';
-	    print '<input name="label" class="flat" type="text" size="24"  value="'.GETPOST("label").'">';
-	    if ($options) {
-	        print '<br>'.$langs->trans("Rubrique").': ';
-	        print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
-	    }
-	    print '</td>';
-	    print '<td align="right"><input name="adddebit" class="flat" type="text" size="4" value="'.GETPOST("adddebit").'"></td>';
-	    print '<td align="right"><input name="addcredit" class="flat" type="text" size="4" value="'.GETPOST("addcredit").'"></td>';
-	    print '<td colspan="2" align="center">';
-	    print '<input type="submit" name="save" class="button" value="'.$langs->trans("Add").'"><br>';
-	    print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
-	    print '</td></tr>';
-	    print '</table>';
-	    print '<br>';
-	}	
-	
-	
 	/// ajax to adjust value date with plus and less picto
 	print '
     <script type="text/javascript">

+ 527 - 0
htdocs/compta/bank/class/paymentvarious.class.php

@@ -0,0 +1,527 @@
+<?php
+/* Copyright (C) 2017 		Alexandre Spangaro   <aspangaro@zendsi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/compta/bank/class/paymentvarious.class.php
+ *      \ingroup    salaries
+ *      \brief		Class for salaries module payment
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
+
+
+/**
+ *  Class to manage various payments
+ */
+class PaymentVarious extends CommonObject
+{
+	//public $element='payment_various';			//!< Id that identify managed objects
+	//public $table_element='payment_various';	//!< Name of table without prefix where object is stored
+
+	var $tms;
+	var $datep;
+	var $datev;
+	var $sens;
+	var $amount;
+	var $type_payment;
+	var $num_payment;
+	var $label;
+	var $accountancy_code;
+	var $fk_bank;
+	var $fk_user_author;
+	var $fk_user_modif;
+
+
+	/**
+	 *	Constructor
+	 *
+	 *  @param		DoliDB		$db      Database handler
+	 */
+	function __construct($db)
+	{
+		$this->db = $db;
+		$this->element = 'payment_various';
+		$this->table_element = 'payment_various';
+		return 1;
+	}
+
+	/**
+	 * Update database
+	 *
+	 * @param   User	$user        	User that modify
+	 * @param	int		$notrigger	    0=no, 1=yes (no update trigger)
+	 * @return  int         			<0 if KO, >0 if OK
+	 */
+	function update($user=null, $notrigger=0)
+	{
+		global $conf, $langs;
+
+		$error=0;
+
+		// Clean parameters
+		$this->fk_user=trim($this->fk_user);
+		$this->amount=trim($this->amount);
+		$this->label=trim($this->label);
+		$this->note=trim($this->note);
+		$this->fk_bank=trim($this->fk_bank);
+		$this->fk_user_author=trim($this->fk_user_author);
+		$this->fk_user_modif=trim($this->fk_user_modif);
+
+		$this->db->begin();
+
+		// Update request
+		$sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
+
+		$sql.= " tms=".$this->db->idate($this->tms).",";
+		$sql.= " fk_user='".$this->fk_user."',";
+		$sql.= " datep=".$this->db->idate($this->datep).",";
+		$sql.= " datev=".$this->db->idate($this->datev).",";
+		$sql.= " sens=".$this->sens.",";
+		$sql.= " amount='".$this->amount."',";
+		$sql.= " fk_typepayment=".$this->fk_typepayment."',";
+		$sql.= " num_payment='".$this->num_payment."',";
+		$sql.= " label='".$this->db->escape($this->label)."',";
+		$sql.= " note='".$this->db->escape($this->note)."',";
+		$sql.= " accountancy_code='".$this->db->escape($this->accountancy_code)."',";
+		$sql.= " fk_bank=".($this->fk_bank > 0 ? "'".$this->fk_bank."'":"null").",";
+		$sql.= " fk_user_author='".$this->fk_user_author."',";
+		$sql.= " fk_user_modif='".$this->fk_user_modif."'";
+
+		$sql.= " WHERE rowid=".$this->id;
+
+		dol_syslog(get_class($this)."::update", LOG_DEBUG);
+		$resql = $this->db->query($sql);
+		if (! $resql)
+		{
+			$this->error="Error ".$this->db->lasterror();
+			return -1;
+		}
+
+		if (! $notrigger)
+		{
+            // Call trigger
+            $result=$this->call_trigger('PAYMENT_SALARY_MODIFY',$user);
+            if ($result < 0) $error++;
+            // End call triggers
+		}
+
+		if (! $error)
+		{
+			$this->db->commit();
+			return 1;
+		}
+		else
+		{
+			$this->db->rollback();
+			return -1;
+		}
+	}
+
+
+	/**
+	 *  Load object in memory from database
+	 *
+	 *  @param	int		$id         id object
+	 *  @param  User	$user       User that load
+	 *  @return int         		<0 if KO, >0 if OK
+	 */
+	function fetch($id, $user=null)
+	{
+		global $langs;
+		$sql = "SELECT";
+		$sql.= " v.rowid,";
+
+		$sql.= " v.tms,";
+		$sql.= " v.datep,";
+		$sql.= " v.datev,";
+		$sql.= " v.sens,";
+		$sql.= " v.amount,";
+		$sql.= " v.fk_typepayment,";
+		$sql.= " v.num_payment,";
+		$sql.= " v.label,";
+		$sql.= " v.note,";
+		$sql.= " v.accountancy_code,";
+		$sql.= " v.fk_bank,";
+		$sql.= " v.fk_user_author,";
+		$sql.= " v.fk_user_modif,";
+		$sql.= " b.fk_account,";
+		$sql.= " b.fk_type,";
+		$sql.= " b.rappro";
+
+		$sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
+		$sql.= " WHERE v.rowid = ".$id;
+
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			if ($this->db->num_rows($resql))
+			{
+				$obj = $this->db->fetch_object($resql);
+
+				$this->id				= $obj->rowid;
+				$this->ref				= $obj->rowid;
+				$this->tms				= $this->db->jdate($obj->tms);
+				$this->fk_user			= $obj->fk_user;
+				$this->datep			= $this->db->jdate($obj->datep);
+				$this->datev			= $this->db->jdate($obj->datev);
+				$this->sens				= $obj->sens;
+				$this->amount			= $obj->amount;
+				$this->type_payement	= $obj->fk_typepayment;
+				$this->num_payment		= $obj->num_payment;
+				$this->label			= $obj->label;
+				$this->note				= $obj->note;
+				$this->accountancy_code	= $obj->accountancy_code;
+				$this->fk_bank			= $obj->fk_bank;
+				$this->fk_user_author	= $obj->fk_user_author;
+				$this->fk_user_modif	= $obj->fk_user_modif;
+				$this->fk_account		= $obj->fk_account;
+				$this->fk_type			= $obj->fk_type;
+				$this->rappro			= $obj->rappro;
+			}
+			$this->db->free($resql);
+
+			return 1;
+		}
+		else
+		{
+			$this->error="Error ".$this->db->lasterror();
+			return -1;
+		}
+	}
+
+
+	/**
+	 *  Delete object in database
+	 *
+	 *	@param	User	$user       User that delete
+	 *	@return	int					<0 if KO, >0 if OK
+	 */
+	function delete($user)
+	{
+		global $conf, $langs;
+
+		$error=0;
+
+		// Call trigger
+		$result=$this->call_trigger('PAYMENT_VARIOUS_DELETE',$user);
+		if ($result < 0) return -1;
+		// End call triggers
+
+
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_various";
+		$sql.= " WHERE rowid=".$this->id;
+
+		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
+		$resql = $this->db->query($sql);
+		if (! $resql)
+		{
+			$this->error="Error ".$this->db->lasterror();
+			return -1;
+		}
+
+		return 1;
+	}
+
+
+	/**
+	 *  Initialise an instance with random values.
+	 *  Used to build previews or test instances.
+	 *	id must be 0 if object instance is a specimen.
+	 *
+	 *  @return	void
+	 */
+	function initAsSpecimen()
+	{
+		$this->id=0;
+
+		$this->tms='';
+		$this->fk_user='';
+		$this->datep='';
+		$this->datev='';
+		$this->sens='';
+		$this->amount='';
+		$this->label='';
+		$this->note='';
+		$this->fk_bank='';
+		$this->fk_user_author='';
+		$this->fk_user_modif='';
+	}
+
+    /**
+     *  Create in database
+     *
+     *  @param      User	$user       User that create
+     *  @return     int      			<0 if KO, >0 if OK
+     */
+	function create($user)
+	{
+		global $conf,$langs;
+
+		$error=0;
+		$now=dol_now();
+
+		// Clean parameters
+		$this->amount=price2num(trim($this->amount));
+		$this->label=trim($this->label);
+		$this->note=trim($this->note);
+		$this->fk_bank=trim($this->fk_bank);
+		$this->fk_user_author=trim($this->fk_user_author);
+		$this->fk_user_modif=trim($this->fk_user_modif);
+
+		// Check parameters
+		if (! $this->label)
+		{
+			$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
+			return -3;
+		}
+		if ($this->amount < 0 || $this->amount == '')
+		{
+			$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
+			return -5;
+		}
+		if (! empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
+		{
+			$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account"));
+			return -6;
+		}
+		if (! empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
+		{
+			$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
+			return -7;
+		}
+
+		$this->db->begin();
+
+		// Insert into llx_payment_various
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_various (";
+		$sql.= " datep";
+		$sql.= ", datev";
+		$sql.= ", sens";
+		$sql.= ", amount";
+		$sql.= ", fk_typepayment";
+		$sql.= ", num_payment";
+		if ($this->note) $sql.= ", note";
+		$sql.= ", label";
+		$sql.= ", accountancy_code";
+		$sql.= ", fk_user_author";
+		$sql.= ", datec";
+		$sql.= ", fk_bank";
+		$sql.= ", entity";
+		$sql.= ")";
+		$sql.= " VALUES (";
+		$sql.= "'".$this->db->idate($this->datep)."'";
+		$sql.= ", '".$this->db->idate($this->datev)."'";
+		$sql.= ", '".$this->sens."'";
+		$sql.= ", ".$this->amount;
+		$sql.= ", '".$this->type_payment."'";
+		$sql.= ", '".$this->num_payment."'";
+		if ($this->note) $sql.= ", '".$this->db->escape($this->note)."'";
+		$sql.= ", '".$this->db->escape($this->label)."'";
+		$sql.= ", '".$this->accountancy_code."'";
+		$sql.= ", '".$user->id."'";
+		$sql.= ", '".$this->db->idate($now)."'";
+		$sql.= ", NULL";
+		$sql.= ", ".$conf->entity;
+		$sql.= ")";
+
+		dol_syslog(get_class($this)."::create", LOG_DEBUG);
+		$result = $this->db->query($sql);
+		if ($result)
+		{
+
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_various");
+
+			if ($this->id > 0)
+			{
+				if (! empty($conf->banque->enabled) && ! empty($this->amount))
+				{
+					// Insert into llx_bank
+					require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+					$acc = new Account($this->db);
+					$result=$acc->fetch($this->accountid);
+					if ($result <= 0) dol_print_error($this->db);
+
+					// Insert payment into llx_bank
+					// Add link 'payment_various' in bank_url between payment and bank transaction
+					if ($this->sens == '0') $sign='-';
+
+					$bank_line_id = $acc->addline(
+						$this->datep,
+						$this->type_payment,
+						$this->label,
+						$sign.abs($this->amount),
+						$this->num_payment,
+						'',
+						$user
+					);
+
+					// Update fk_bank into llx_paiement.
+					// So we know the payment which has generate the banking ecriture
+					if ($bank_line_id > 0)
+					{
+						$this->update_fk_bank($bank_line_id);
+					}
+					else
+					{
+						$this->error=$acc->error;
+						$error++;
+					}
+
+					if (! $error)
+					{
+						// Add link 'payment_various' in bank_url between payment and bank transaction
+						$url=DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id=';
+
+						$result=$acc->add_url_line($bank_line_id, $this->id, $url, "(VariousPayment)", "payment_various");
+						if ($result <= 0)
+						{
+							$this->error=$acc->error;
+							$error++;
+						}
+					}
+
+					if ($result <= 0)
+					{
+						$this->error=$acc->error;
+						$error++;
+					}
+				}
+
+	            // Call trigger
+	            $result=$this->call_trigger('PAYMENT_VARIOUS_CREATE',$user);
+	            if ($result < 0) $error++;
+	            // End call triggers
+
+			}
+			else $error++;
+
+			if (! $error)
+			{
+				$this->db->commit();
+				return $this->id;
+			}
+			else
+			{
+				$this->db->rollback();
+				return -2;
+			}
+		}
+		else
+		{
+			$this->error=$this->db->error();
+			$this->db->rollback();
+			return -1;
+		}
+	}
+
+	/**
+	 *  Update link between payment various and line generate into llx_bank
+	 *
+	 *  @param	int		$id_bank    Id bank account
+	 *	@return	int					<0 if KO, >0 if OK
+	 */
+	function update_fk_bank($id_bank)
+	{
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.$id_bank;
+		$sql.= ' WHERE rowid = '.$this->id;
+		$result = $this->db->query($sql);
+		if ($result)
+		{
+			return 1;
+		}
+		else
+		{
+			dol_print_error($this->db);
+			return -1;
+		}
+	}
+
+
+	/**
+	 *	Send name clicable (with possibly the picto)
+	 *
+	 *	@param	int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
+	 *	@param	string	$option			link option
+	 *	@return	string					Chaine with URL
+	 */
+	function getNomUrl($withpicto=0,$option='')
+	{
+		global $langs;
+
+		$result='';
+        $label=$langs->trans("ShowVariousPayment").': '.$this->ref;
+
+        $link = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
+		$linkend='</a>';
+
+		$picto='payment';
+
+        if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
+		if ($withpicto && $withpicto != 2) $result.=' ';
+		if ($withpicto != 2) $result.=$link.$this->ref.$linkend;
+		return $result;
+	}
+
+	/**
+	 * Information on record
+	 *
+	 * @param	int		$id      Id of record
+	 * @return	void
+	 */
+	function info($id)
+	{
+		$sql = 'SELECT v.rowid, v.datec, v.fk_user_author';
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
+		$sql.= ' WHERE v.rowid = '.$id;
+
+		dol_syslog(get_class($this).'::info', LOG_DEBUG);
+		$result = $this->db->query($sql);
+
+		if ($result)
+		{
+			if ($this->db->num_rows($result))
+			{
+				$obj = $this->db->fetch_object($result);
+				$this->id = $obj->rowid;
+				if ($obj->fk_user_author)
+				{
+					$cuser = new User($this->db);
+					$cuser->fetch($obj->fk_user_author);
+					$this->user_creation = $cuser;
+				}
+				$this->date_creation = $this->db->jdate($obj->datec);
+				if ($obj->fk_user_modif)
+				{
+					$muser = new User($this->db);
+					$muser->fetch($obj->fk_user_modif);
+					$this->user_modif = $muser;
+				}
+				$this->date_modif = $this->db->jdate($obj->tms);
+			}
+			$this->db->free($result);
+		}
+		else
+		{
+			dol_print_error($this->db);
+		}
+	}
+
+}

+ 7 - 1
htdocs/compta/bank/ligne.php

@@ -4,7 +4,7 @@
  * Copyright (C) 2004-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2004      Christophe Combelles <ccomb@free.fr>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
- * Copyright (C) 2015-2016 Alexandre Spangaro	<aspangaro@zendsi.com>
+ * Copyright (C) 2015-2017 Alexandre Spangaro	<aspangaro@zendsi.com>
  * Copyright (C) 2015      Jean-François Ferry	<jfefe@aternatik.fr>
  * Copyright (C) 2016      Marcos García        <marcosgdf@gmail.com>
  *
@@ -374,6 +374,12 @@ if ($result)
                     print img_object($langs->trans('ShowUser'),'user').' ';
                     print $langs->trans("User");
                     print '</a>';
+                }
+				else if ($links[$key]['type']=='payment_various') {
+                    print '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$links[$key]['url_id'].'">';
+                    print img_object($langs->trans('ShowVariousPayment'),'payment').' ';
+                    print $langs->trans("VariousPayment");
+                    print '</a>';
                 }
                 else {
                     print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';

+ 409 - 0
htdocs/compta/bank/various_payment/card.php

@@ -0,0 +1,409 @@
+<?php
+/* Copyright (C) 2017		Alexandre Spangaro	<aspangaro@zendsi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *	    \file       htdocs/compta/bank/various_expenses/card.php
+ *      \ingroup    bank
+ *		\brief      Page of various expenses
+ */
+
+require '../../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
+if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
+
+$langs->load("compta");
+$langs->load("banks");
+$langs->load("bills");
+$langs->load("users");
+$langs->load("accountancy");
+
+$id=GETPOST("id",'int');
+$action=GETPOST('action','alpha');
+$cancel=GETPOST('cancel','alpha');
+$accountid=GETPOST("accountid") > 0 ? GETPOST("accountid","int") : 0;
+$label=GETPOST("label","alpha");
+$sens=GETPOST("sens","int");
+$amount=GETPOST("amount");
+$paymenttype=GETPOST("paymenttype");
+$accountancy_code=GETPOST("accountancy_code","int");
+
+// Security check
+$socid = GETPOST("socid","int");
+if ($user->societe_id) $socid=$user->societe_id;
+$result = restrictedArea($user, 'banque', '', '', '');
+
+$object = new PaymentVarious($db);
+
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+$hookmanager->initHooks(array('variouscard','globalcard'));
+
+
+
+/**
+ * Actions
+ */
+
+if (! empty($cancel))
+{
+	header("Location: index.php");
+	exit;
+}
+
+if ($action == 'add' && empty($cancel))
+{
+	$error=0;
+
+	$datep=dol_mktime(12,0,0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
+	$datev=dol_mktime(12,0,0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
+	if (empty($datev)) $datev=$datep;
+	
+	$object->accountid=GETPOST("accountid") > 0 ? GETPOST("accountid","int") : 0;
+	$object->datev=$datev;
+	$object->datep=$datep;
+	$object->amount=price2num(GETPOST("amount"));
+	$object->label=GETPOST("label");
+	$object->note=GETPOST("note");
+	$object->type_payment=GETPOST("paymenttype") > 0 ? GETPOST("paymenttype", "int") : 0;
+	$object->num_payment=GETPOST("num_payment");
+	$object->fk_user_author=$user->id;
+	$object->accountancy_code=GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code","int") : "";
+
+	if (empty($datep) || empty($datev))
+	{
+		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
+		$error++;
+	}
+	if (empty($object->type_payment) || $object->type_payment < 0)
+	{
+		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
+		$error++;
+	}
+	if (empty($object->amount))
+	{
+		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
+		$error++;
+	}
+	if (! empty($conf->banque->enabled) && ! $object->accountid > 0)
+	{
+		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
+		$error++;
+	}
+
+	if (! $error)
+	{
+		$db->begin();
+
+		$ret=$object->create($user);
+		if ($ret > 0)
+		{
+			$db->commit();
+			header("Location: index.php");
+			exit;
+		}
+		else
+		{
+			$db->rollback();
+			setEventMessages($object->error, $object->errors, 'errors');
+			$action="create";
+		}
+	}
+
+	$action='create';
+}
+
+if ($action == 'delete')
+{
+	$result=$object->fetch($id);
+
+	if ($object->rappro == 0)
+	{
+		$db->begin();
+
+		$ret=$object->delete($user);
+		if ($ret > 0)
+		{
+			if ($object->fk_bank)
+			{
+				$accountline=new AccountLine($db);
+				$result=$accountline->fetch($object->fk_bank);
+				if ($result > 0) $result=$accountline->delete($user);	// $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
+			}
+
+			if ($result >= 0)
+			{
+				$db->commit();
+				header("Location: ".DOL_URL_ROOT.'/compta/salaries/index.php');
+				exit;
+			}
+			else
+			{
+				$object->error=$accountline->error;
+				$db->rollback();
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
+		}
+		else
+		{
+			$db->rollback();
+			setEventMessages($object->error, $object->errors, 'errors');
+		}
+	}
+	else
+	{
+		setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
+	}
+}
+
+
+/*
+ *	View
+ */
+
+llxHeader("",$langs->trans("VariousPayment"));
+
+$form = new Form($db);
+if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
+
+if ($id)
+{
+	$object = new PaymentVarious($db);
+	$result = $object->fetch($id);
+	if ($result <= 0)
+	{
+		dol_print_error($db);
+		exit;
+	}
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Create mode                                                                */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'create')
+{
+	print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="post">';
+	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	print '<input type="hidden" name="action" value="add">';
+
+	print load_fiche_titre($langs->trans("NewVariousPayment"),'', 'title_accountancy.png');
+
+	dol_fiche_head('', '');
+	
+	print '<table class="border" width="100%">';
+
+	// Date payment
+	print '<tr><td>';
+	print fieldLabel('DatePayment','datep',1).'</td><td>';
+	print $form->select_date((empty($datep)?-1:$datep),"datep",'','','','add',1,1);
+	print '</td></tr>';
+
+	// Date value for bank
+	print '<tr><td>';
+	print fieldLabel('DateValue','datev',0).'</td><td>';
+	print $form->select_date((empty($datev)?-1:$datev),"datev",'','','','add',1,1);
+	print '</td></tr>';
+
+	// Label
+	print '<tr><td>';
+	print fieldLabel('Label','label',1).'</td><td>';
+	print '<input name="label" id="label" class="minwidth300" value="'.($label?$label:$langs->trans("VariousPayment")).'">';
+	print '</td></tr>';
+
+	// Sens
+	print '<tr><td>';
+	print fieldLabel('Sens','sens',1).'</td><td>';
+    $sensarray=array( '0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
+    print $form->selectarray('sens',$sensarray,$sens);
+	print '</td></tr>';
+
+	// Amount
+	print '<tr><td>';
+	print fieldLabel('Amount','amount',1).'</td><td>';
+	print '<input name="amount" id="amount" class="minwidth100" value="'.$amount.'">';
+	print '</td></tr>';
+
+	// Bank
+	if (! empty($conf->banque->enabled))
+	{
+		print '<tr><td>';
+		print fieldLabel('BankAccount','selectaccountid',1).'</td><td>';
+		$form->select_comptes($accountid,"accountid",0,'',1);  // Affiche liste des comptes courant
+		print '</td></tr>';
+	}
+
+	// Type payment
+	print '<tr><td>';
+	print fieldLabel('PaymentMode','selectpaymenttype',1).'</td><td>';
+	$form->select_types_paiements($paymenttype, "paymenttype");
+	print '</td></tr>';
+
+	// Number
+	if (! empty($conf->banque->enabled))
+	{
+		// Number
+		print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
+		print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
+		print '</label></td>';
+		print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
+	}
+
+	// Accountancy account
+	if (! empty($conf->accounting->enabled))
+	{
+		print '<tr><td>'.$langs->trans("AccountAccounting").'</td>';
+        print '<td>';
+		print $formaccountancy->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1, '');
+        print '</td></tr>';
+	}			
+	else // For external software 
+	{
+		print '<tr><td>'.$langs->trans("AccountAccounting").'</td>';
+		print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code" value="'.$accountancy_code.'">';
+		print '</td></tr>';
+	}
+
+	// Other attributes
+	$parameters=array('colspan' => ' colspan="1"');
+	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+
+	print '</table>';
+
+	dol_fiche_end();
+
+	print '<div class="center">';
+	print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
+	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+	print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
+	print '</div>';
+
+	print '</form>';
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* View mode                                                                  */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($id)
+{
+
+	$head=various_payment_prepare_head($object);
+
+	dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), 0, 'payment');
+
+	print '<table class="border" width="100%">';
+
+    $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/index.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
+	
+    print "<tr>";
+	print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
+	print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
+	print '</td></tr>';
+
+	// Label
+	print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
+
+	print "<tr>";
+	print '<td>'.$langs->trans("DatePayment").'</td><td>';
+	print dol_print_date($object->datep,'day');
+	print '</td></tr>';
+
+	print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
+	print dol_print_date($object->datev,'day');
+	print '</td></tr>';
+
+	// Debit / Credit
+	if ($object->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
+	print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
+
+	print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
+
+	// Accountancy code
+	print '<tr><td class="nowrap">';
+	print $langs->trans("AccountAccounting");
+	print '</td><td>';
+	if (! empty($conf->accounting->enabled))
+	{
+		$accountancyaccount = new AccountingAccount($db);
+		$accountancyaccount->fetch('',$object->accountancy_code);
+
+		print $accountancyaccount->getNomUrl(1);
+		// print length_accountg($object->accountancy_code);
+	} else {
+		print $object->accountancy_code;
+	}
+	print '</td></tr>';
+
+	if (! empty($conf->banque->enabled))
+	{
+		if ($object->fk_account > 0)
+		{
+			$bankline=new AccountLine($db);
+			$bankline->fetch($object->fk_bank);
+
+			print '<tr>';
+			print '<td>'.$langs->trans('BankTransactionLine').'</td>';
+			print '<td colspan="3">';
+			print $bankline->getNomUrl(1,0,'showall');
+			print '</td>';
+			print '</tr>';
+		}
+	}
+
+	// Other attributes
+	$parameters=array('colspan' => ' colspan="1"');
+	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+
+	print '</table>';
+
+	dol_fiche_end();
+
+	
+	/*
+	 * Action buttons
+	 */
+	print '<div class="tabsAction">'."\n";
+	if ($object->rappro == 0)
+	{
+		if (! empty($user->rights->banque->delete))
+		{
+			print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
+		}
+		else
+		{
+			print '<a class="butActionRefused" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a>';
+		}
+	}
+	else
+	{
+		print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a>';
+	}
+	print "</div>";
+}
+
+
+
+llxFooter();
+
+$db->close();

+ 127 - 0
htdocs/compta/bank/various_payment/document.php

@@ -0,0 +1,127 @@
+<?php
+/* Copyright (C) 2017		Alexandre Spangaro	<aspangaro@zendsi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * or see http://www.gnu.org/
+ */
+
+/**
+ *       \file       htdocs/compta/bank/various_payment/document.php
+ *       \ingroup    banque
+ *       \brief      Page of linked files onto various_payment
+ */
+
+require '../../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
+
+$langs->load("other");
+$langs->load("bank");
+$langs->load("companies");
+
+$id = GETPOST('id','int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action','alpha');
+$confirm = GETPOST('confirm','alpha');
+
+// Security check
+if ($user->societe_id) $socid=$user->societe_id;
+$result = restrictedArea($user, 'salaries', $id, '');
+
+
+// Get parameters
+$sortfield = GETPOST('sortfield','alpha');
+$sortorder = GETPOST('sortorder','alpha');
+$page = GETPOST('page','int');
+if ($page == -1) { $page = 0; }
+$offset = $conf->liste_limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (! $sortorder) $sortorder="ASC";
+if (! $sortfield) $sortfield="name";
+
+
+$object = new PaymentVarious($db);
+$object->fetch($id, $ref);
+
+$upload_dir = $conf->banque->dir_output.'/'.dol_sanitizeFileName($object->id);
+$modulepart='banque';
+
+
+/*
+ * Actions
+ */
+
+include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+llxHeader("",$langs->trans("VariousPayment"));
+
+
+if ($object->id)
+{
+	$head=various_payment_prepare_head($object);
+
+	dol_fiche_head($head, 'documents',  $langs->trans("VariousPayment"), 0, 'payment');
+
+
+	// Construit liste des fichiers
+	$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+	$totalsize=0;
+	foreach($filearray as $key => $file)
+	{
+		$totalsize+=$file['size'];
+	}
+
+
+    print '<table class="border" width="100%">';
+
+    $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/index.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
+
+	// Ref
+	print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
+	print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
+	print '</td></tr>';
+
+	// Societe
+	//print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
+
+    print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
+    print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
+    print '</table>';
+
+    print '</div>';
+
+    $modulepart = 'banque';
+    $permission = $user->rights->banque->modifier;
+    $param = '&id=' . $object->id;
+    include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
+
+}
+else
+{
+	print $langs->trans("ErrorUnknown");
+}
+
+llxFooter();
+
+$db->close();

+ 259 - 0
htdocs/compta/bank/various_payment/index.php

@@ -0,0 +1,259 @@
+<?php
+/* Copyright (C) 2017		Alexandre Spangaro	<aspangaro@zendsi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *	    \file       htdocs/compta/bank/various_payment/index.php
+ *      \ingroup    bank
+ *		\brief     	List of various payments
+ */
+
+require '../../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+$langs->load("compta");
+$langs->load("banks");
+$langs->load("bills");
+
+// Security check
+$socid = GETPOST("socid","int");
+if ($user->societe_id) $socid=$user->societe_id;
+$result = restrictedArea($user, 'banque', '', '', '');
+
+$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
+$search_ref = GETPOST('search_ref','int');
+$search_user = GETPOST('search_user','alpha');
+$search_label = GETPOST('search_label','alpha');
+$search_amount = GETPOST('search_amount','alpha');
+$search_account = GETPOST('search_account','int');
+
+$sortfield = GETPOST("sortfield",'alpha');
+$sortorder = GETPOST("sortorder",'alpha');
+$page = GETPOST("page",'int');
+if ($page == -1) { $page = 0; }
+$offset = $conf->liste_limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (! $sortfield) $sortfield="v.datep";
+if (! $sortorder) $sortorder="DESC";
+$optioncss = GETPOST('optioncss','alpha');
+
+$filtre=$_GET["filtre"];
+
+if (empty($_REQUEST['typeid']))
+{
+	$newfiltre=str_replace('filtre=','',$filtre);
+	$filterarray=explode('-',$newfiltre);
+	foreach($filterarray as $val)
+	{
+		$part=explode(':',$val);
+		if ($part[0] == 'v.fk_typepayment') $typeid=$part[1];
+	}
+}
+else
+{
+	$typeid=$_REQUEST['typeid'];
+}
+
+if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
+{
+	$search_ref="";
+	$search_label="";
+	$search_amount="";
+	$search_account='';
+    $typeid="";
+}
+
+/*
+ * View
+ */
+
+llxHeader();
+
+$form = new Form($db);
+$variousstatic = new PaymentVarious($db);
+$accountstatic = new Account($db);
+
+$sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank,";
+$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.accountancy_journal, ba.label as blabel,";
+$sql.= " pst.code as payment_code";
+$sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
+$sql.= " WHERE v.entity = ".$conf->entity;
+
+// Search criteria
+if ($search_ref)	$sql.=" AND v.rowid=".$search_ref;
+if ($search_label) 	$sql.=natural_search(array('v.label'), $search_label);
+if ($search_amount) $sql.=natural_search("v.amount", $search_amount, 1);
+if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
+if ($filtre) {
+    $filtre=str_replace(":","=",$filtre);
+    $sql .= " AND ".$filtre;
+}
+if ($typeid) {
+    $sql .= " AND v.fk_typepayment=".$typeid;
+}
+$sql.= $db->order($sortfield,$sortorder);
+
+//$sql.= " GROUP BY u.rowid, u.lastname, u.firstname, v.rowid, v.fk_user, v.amount, v.label, v.datev, v.fk_typepayment, v.num_payment, pst.code";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
+$sql.= $db->plimit($limit+1,$offset);
+
+$result = $db->query($sql);
+if ($result)
+{
+    $num = $db->num_rows($result);
+    $i = 0;
+    $total = 0 ;
+	$var=true;
+
+	$param='';
+    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
+	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
+	if ($typeid) $param.='&amp;typeid='.$typeid;
+	if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
+
+	print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
+    if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
+    print '<input type="hidden" name="action" value="list">';
+    print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
+    print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
+
+	print_barre_liste($langs->trans("VariousPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
+	
+    print '<div class="div-table-responsive">';
+    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
+
+	print '<tr class="liste_titre">';
+	print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"v.rowid","",$param,"",$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"v.label","",$param,'align="left"',$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"v.datep","",$param,'align="center"',$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("PaymentMode"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
+    if (! empty($conf->banque->enabled)) print_liste_field_titre($langs->trans("BankAccount"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("Sens"),$_SERVER["PHP_SELF"],"v.sens","",$param,'align="right"',$sortfield,$sortorder);
+	print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
+    print "</tr>\n";
+
+	print '<tr class="liste_titre">';
+	// Ref
+	print '<td class="liste_titre" align="left">';
+	print '<input class="flat" type="text" size="3" name="search_ref" value="'.$search_ref.'">';
+	print '</td>';
+	// Label
+	print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$search_label.'"></td>';
+	// Date
+	print '<td class="liste_titre">&nbsp;</td>';
+	// Type
+	print '<td class="liste_titre" align="left">';
+	$form->select_types_paiements($typeid,'typeid','',0,0,1,16);
+	print '</td>';
+	// Account
+	if (! empty($conf->banque->enabled))
+    {
+	    print '<td class="liste_titre">';
+	    $form->select_comptes($search_account,'search_account',0,'',1);
+	    print '</td>';
+    }
+	// Amount
+	print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
+	// Sens
+	print '<td class="liste_titre">&nbsp;</td>';
+
+    print '<td class="liste_titre" align="right">';
+    $searchpicto=$form->showFilterAndCheckAddButtons(0);
+    print $searchpicto;
+    print '</td>';
+    
+	print "</tr>\n";
+
+    while ($i < min($num,$limit))
+    {
+        $obj = $db->fetch_object($result);
+        $var=!$var;
+        print "<tr ".$bc[$var].">";
+
+        $variousstatic->id=$obj->rowid;
+		$variousstatic->ref=$obj->rowid;
+        // Ref
+		print "<td>".$variousstatic->getNomUrl(1)."</td>\n";
+		// Label payment
+        print "<td>".dol_trunc($obj->label,40)."</td>\n";
+		// Date payment
+        print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
+        // Type
+        print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
+		// Account
+    	if (! empty($conf->banque->enabled))
+	    {
+	        print '<td>';
+	        if ($obj->fk_bank > 0)
+	        {
+	        	//$accountstatic->fetch($obj->fk_bank);
+	            $accountstatic->id=$obj->bid;
+	            $accountstatic->ref=$obj->bref;
+	            $accountstatic->number=$obj->bnumber;
+	            $accountstatic->accountancy_number=$obj->account_number;
+	            $accountstatic->accountancy_journal=$obj->accountancy_journal;
+	            $accountstatic->label=$obj->blabel;
+	        	print $accountstatic->getNomUrl(1);
+	        }
+	        else print '&nbsp;';
+	        print '</td>';
+	    }
+        // Amount
+        print "<td align=\"right\">".price($obj->amount)."</td>";
+        // Sens
+		if ($obj->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
+        print "<td align=\"right\">".$sens."</td>";
+        print "<td></td>";
+        print "</tr>\n";
+
+        $total = $total + $obj->amount;
+
+        $i++;
+    }
+
+    $colspan=4;
+    if (! empty($conf->banque->enabled)) $colspan++;
+    print '<tr class="liste_total"><td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
+    print '<td class="liste_total" align="right">'.price($total)."</td>";
+	print "<td></td></tr>";
+
+    print "</table>";
+    print '</div>';
+	print '</form>';
+
+    $db->free($result);
+}
+else
+{
+    dol_print_error($db);
+}
+
+
+llxFooter();
+$db->close();

+ 65 - 0
htdocs/compta/bank/various_payment/info.php

@@ -0,0 +1,65 @@
+<?php
+/* Copyright (C) 2017		Alexandre Spangaro	<aspangaro@zendsi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *	\file       htdocs/compta/bank/various_payment/info.php
+ *	\ingroup    salaries
+ *	\brief      Page with info about salaries contribution
+ */
+
+require '../../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+
+$langs->load("compta");
+$langs->load("bills");
+$langs->load("salaries");
+
+$id=GETPOST('id','int');
+$action=GETPOST("action");
+
+// Security check
+$socid = GETPOST('socid','int');
+if ($user->societe_id) $socid=$user->societe_id;
+$result = restrictedArea($user, 'salaries', '', '', '');
+
+
+/*
+ * View
+ */
+
+llxHeader("",$langs->trans("VariousPayment"));
+
+$object = new PaymentVarious($db);
+$result = $object->fetch($id);
+$object->info($id);
+
+$head = various_payment_prepare_head($object);
+
+dol_fiche_head($head, 'info', $langs->trans("VariousPayment"), 0, 'payment');
+
+
+print '<table width="100%"><tr><td>';
+dol_print_object_info($object);
+print '</td></tr></table>';
+
+print '</div>';
+
+llxFooter();
+
+$db->close();

+ 45 - 0
htdocs/core/lib/bank.lib.php

@@ -134,6 +134,51 @@ function bank_admin_prepare_head($object)
 	return $head;
 }
 
+/**
+ * Prepare array with list of tabs
+ *
+ * @param   Object	$object		Object related to tabs
+ * @return  array				Array of tabs to shoc
+ */
+function various_payment_prepare_head($object) {
+	
+	global $db, $langs, $conf;
+	
+	$h = 0;
+	$head = array();
+
+	$head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$object->id;
+	$head[$h][1] = $langs->trans("Card");
+	$head[$h][2] = 'card';
+	$h++;
+
+    // Show more tabs from modules
+    // Entries must be declared in modules descriptor with line
+    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
+    // $this->tabs = array('entity:-tabname);   												to remove a tab
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'various_payment');
+
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+    require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+	$upload_dir = $conf->banque->dir_output . "/" . dol_sanitizeFileName($object->ref);
+	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
+    $nbLinks=Link::count($db, $object->element, $object->id);
+	$head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/document.php?id='.$object->id;
+	$head[$h][1] = $langs->trans('Documents');
+	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
+	$head[$h][2] = 'documents';
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/info.php?id='.$object->id;
+	$head[$h][1] = $langs->trans("Info");
+	$head[$h][2] = 'info';
+	$h++;
+    
+	complete_head_from_modules($conf,$langs,$object,$head,$h,'various_payment', 'remove');
+
+	return $head;
+}
+
 /**
  *      Check SWIFT informations for a bank account
  *

+ 1 - 9
htdocs/core/modules/modAccounting.class.php

@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2017 Alexandre Spangaro	<aspangaro@zendsi.com>
  * Copyright (C) 2014      Ari Elbaz (elarifr)	<github@accedinfo.com>
  * Copyright (C) 2014 	   Florian Henry        <florian.henry@open-concept.pro>
  * Copyright (C) 2016      Laurent Destailleur 	<eldy@users.sourceforge.net>
@@ -201,14 +201,6 @@ class modAccounting extends DolibarrModules
 				"chaine",
 				"csv"
 		);
-		/* Not required to disable this. This make not possible to do complete reconciliation.
-		Also, this is not a problem, lines added manually will be reported as "not binded into accounting export module
-		and will be binded manually to be created into general ledger
-		$this->const[24] = array(
-				"BANK_DISABLE_DIRECT_INPUT",
-				"yesno",
-				"1"
-		);*/
 
 		// Tabs
 		$this->tabs = array();

+ 20 - 0
htdocs/install/mysql/migration/5.0.0-6.0.0.sql

@@ -124,3 +124,23 @@ INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USER_A
 
 ALTER TABLE llx_chargesociales ADD COLUMN ref varchar(16);
 ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL;
+
+create table llx_payment_various
+(
+  rowid                 integer AUTO_INCREMENT PRIMARY KEY,
+  tms                   timestamp,
+  datec                 datetime,
+  datep                 date,
+  datev                 date,
+  sens                  smallint DEFAULT 0 NOT NULL,
+  amount                double(24,8) DEFAULT 0 NOT NULL,
+  fk_typepayment        integer NOT NULL,
+  num_payment           varchar(50),
+  label                 varchar(255),
+  accountancy_code		varchar(32),
+  entity                integer DEFAULT 1 NOT NULL,
+  note                  text,
+  fk_bank               integer,
+  fk_user_author        integer,
+  fk_user_modif         integer
+)ENGINE=innodb;

+ 37 - 0
htdocs/install/mysql/tables/llx_payment_various.sql

@@ -0,0 +1,37 @@
+-- ===================================================================
+-- Copyright (C) 2017		Alexandre Spangaro <aspangaro@zendsi.com>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+create table llx_payment_various
+(
+  rowid                 integer AUTO_INCREMENT PRIMARY KEY,
+  tms                   timestamp,
+  datec                 datetime,                   -- Create date
+  datep                 date,                       -- date de paiement
+  datev                 date,                       -- date de valeur (this field should not be here, only into bank tables)
+  sens                  smallint DEFAULT 0 NOT NULL,-- Sens of the operation: 0 for debit operation, 1 for credit operation
+  amount                double(24,8) DEFAULT 0 NOT NULL,
+  fk_typepayment        integer NOT NULL,
+  num_payment           varchar(50),				-- ref
+  label                 varchar(255),
+  accountancy_code		varchar(32),
+  entity                integer DEFAULT 1 NOT NULL,	-- multi company id
+  note                  text,
+  fk_bank               integer,
+  fk_user_author        integer,                    -- utilisateur qui a cree l'info
+  fk_user_modif         integer                     -- utilisateur qui a modifié l'info
+)ENGINE=innodb;

+ 5 - 1
htdocs/langs/en_US/banks.lang

@@ -149,4 +149,8 @@ CheckRejected=Check returned
 CheckRejectedAndInvoicesReopened=Check returned and invoices reopened
 BankAccountModelModule=Document templates for bank accounts
 DocumentModelSepaMandate=Template of SEPA mandate. Usefull for european countries in EEC only.
-DocumentModelBan=Template to print a page with BAN information. 
+DocumentModelBan=Template to print a page with BAN information.
+NewVariousPayment=New various payment
+VariousPayment=Various payment
+VariousPayments=Various payments
+ShowVariousPayment=Show various payment