Merge remote-tracking branch 'uptream/develop' into 6.0-multijournal

This commit is contained in:
Alexandre SPANGARO 2017-05-01 08:16:55 +02:00
commit cbd0598611
11 changed files with 195 additions and 210 deletions

View File

@ -611,7 +611,9 @@ if (empty($reshook))
{
$db->begin();
// Boucle sur chaque taux de tva
$amount_ht = $amount_tva = $amount_ttc = array();
// Loop on each vat rate
$i = 0;
foreach ($object->lines as $line)
{
@ -630,20 +632,19 @@ if (empty($reshook))
$discount->description = '(CREDIT_NOTE)';
elseif ($object->type == Facture::TYPE_DEPOSIT)
$discount->description = '(DEPOSIT)';
elseif ($object->type == Facture::TYPE_STANDARD)
elseif ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION)
$discount->description = '(EXCESS RECEIVED)';
else {
setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
}
$discount->tva_tx = abs($object->total_ttc);
$discount->fk_soc = $object->socid;
$discount->fk_facture_source = $object->id;
$error = 0;
if ($object->type == Facture::TYPE_STANDARD) {
// If we're on a standard invoice, we have to get excess received to create it in TTC wuthout VAT
if ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION)
{
// If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT
$sql = 'SELECT SUM(pf.amount) as total_paiements
FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p
@ -663,8 +664,9 @@ if (empty($reshook))
$error++;
}
} else {
}
if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
{
foreach ($amount_ht as $tva_tx => $xxx)
{
$discount->amount_ht = abs($amount_ht[$tva_tx]);
@ -871,19 +873,6 @@ if (empty($reshook))
$object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,'','','TTC');
}
}
// Add predefined lines
/*
TODO delete
for($i = 1; $i <= $NBLINES; $i ++) {
if ($_POST['idprod' . $i]) {
$product = new Product($db);
$product->fetch($_POST['idprod' . $i]);
$startday = dol_mktime(12, 0, 0, $_POST['date_start' . $i . 'month'], $_POST['date_start' . $i . 'day'], $_POST['date_start' . $i . 'year']);
$endday = dol_mktime(12, 0, 0, $_POST['date_end' . $i . 'month'], $_POST['date_end' . $i . 'day'], $_POST['date_end' . $i . 'year']);
$result = $object->addline($product->description, $product->price, $_POST['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod' . $i], $_POST['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
}
}*/
}
}

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
@ -221,7 +221,7 @@ if (empty($reshook))
$db->begin();
// Clean parameters amount if payment is for a credit note
if (GETPOST('type') == 2)
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE)
{
foreach ($amounts as $key => $value) // How payment is dispatch
{
@ -249,7 +249,7 @@ if (empty($reshook))
// Creation of payment line
$paiement = new Paiement($db);
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array with all payments dispatching
$paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
$paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement');
$paiement->num_paiement = GETPOST('num_paiement');
@ -257,7 +257,7 @@ if (empty($reshook))
if (! $error)
{
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0));
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); // This include closing invoices
if ($paiement_id < 0)
{
setEventMessages($paiement->error, $paiement->errors, 'errors');
@ -268,7 +268,7 @@ if (empty($reshook))
if (! $error)
{
$label='(CustomerInvoicePayment)';
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) $label='(CustomerInvoicePaymentBack)'; // Refund of a credit note
$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
if ($result < 0)
{
@ -281,7 +281,7 @@ if (empty($reshook))
{
$db->commit();
// If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
// If payment dispatching on more than one invoice, we keep on summary page, otherwise jump on invoice card
$invoiceid=0;
foreach ($paiement->amounts as $key => $amount)
{
@ -309,7 +309,7 @@ if (empty($reshook))
* View
*/
llxHeader();
llxHeader('', $langs->trans("Payment"));
$form=new Form($db);
@ -324,8 +324,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$facture->fetch_thirdparty();
$title='';
if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
if ($facture->type != Facture::TYPE_CREDIT_NOTE) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $title.=$langs->trans("EnterPaymentDueToCustomer");
print load_fiche_titre($title);
// Initialize data for confirmation (this is used because data can be change during confirmation)
@ -347,7 +347,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Add realtime total information
if ($conf->use_javascript_ajax)
if (! empty($conf->use_javascript_ajax))
{
print "\n".'<script type="text/javascript" language="javascript">';
print '$(document).ready(function () {
@ -369,7 +369,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
if ($(\'#fieldchqemetteur\').val() == \'\')
{
var emetteur = ('.$facture->type.' == 2) ? \''.dol_escape_js(dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_NOM)).'\' : jQuery(\'#thirdpartylabel\').val();
var emetteur = ('.$facture->type.' == '.Facture::TYPE_CREDIT_NOTE.') ? \''.dol_escape_js(dol_escape_htmltag($conf->global->MAIN_INFO_SOCIETE_NOM)).'\' : jQuery(\'#thirdpartylabel\').val();
$(\'#fieldchqemetteur\').val(emetteur);
}
}
@ -437,14 +437,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
';
print ' });'."\n";
if (!empty($conf->use_javascript_ajax)){
//Add js for AutoFill
print ' $(document).ready(function () {';
print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
$("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
});';
print ' });'."\n";
}
//Add js for AutoFill
print ' $(document).ready(function () {';
print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
$("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
});';
print ' });'."\n";
print ' </script>'."\n";
}

View File

@ -255,7 +255,7 @@ class Paiement extends CommonObject
{
if (! empty($conf->prelevement->enabled))
{
// TODO Check if this payment has a withdraw request
// FIXME Check if this invoice has a withdraw request
// if not, $mustwait++; // This will disable automatic close on invoice to allow to process
}
}
@ -275,11 +275,61 @@ class Paiement extends CommonObject
else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
else
{
$result=$invoice->set_paid($user,'','');
if ($result<0)
// If invoice is a down payment, we also convert down payment to discount
if ($invoice->type == Facture::TYPE_DEPOSIT)
{
$this->error=$invoice->error;
$error++;
$amount_ht = $amount_tva = $amount_ttc = array();
// Loop on each vat rate
$i = 0;
foreach ($invoice->lines as $line)
{
if ($line->total_ht!=0)
{ // no need to create discount if amount is null
$amount_ht[$line->tva_tx] += $line->total_ht;
$amount_tva[$line->tva_tx] += $line->total_tva;
$amount_ttc[$line->tva_tx] += $line->total_ttc;
$i ++;
}
}
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute($this->db);
$discount->description = '(DEPOSIT)';
$discount->fk_soc = $invoice->socid;
$discount->fk_facture_source = $invoice->id;
foreach ($amount_ht as $tva_tx => $xxx)
{
$discount->amount_ht = abs($amount_ht[$tva_tx]);
$discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
$discount->tva_tx = abs($tva_tx);
$result = $discount->create($user);
if ($result < 0)
{
$error++;
break;
}
}
if ($error)
{
setEventMessages($discount->error, $discount->errors, 'errors');
$error++;
}
}
// Set invoice to paid
if (! $error)
{
$result=$invoice->set_paid($user,'','');
if ($result<0)
{
$this->error=$invoice->error;
$error++;
}
}
}
}

View File

@ -51,7 +51,8 @@ abstract class CommonInvoice extends CommonObject
const TYPE_DEPOSIT = 3;
/**
* Proforma invoice
* Proforma invoice.
* @deprectad Remove this. A "proforma invoice" is an order with a look of invoice, not an invoice !
*/
const TYPE_PROFORMA = 4;

View File

@ -4674,7 +4674,26 @@ abstract class CommonObject
*/
public function createCommon(User $user, $notrigger = false)
{
foreach ($this->fields as $k => $v) {
$keys[] = $k;
$values[] = $this->quote($v);
}
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.'
( '.implode( ",", $keys ).' )
VALUES ( '.implode( ",", $values ).' ) ';
$res = $this->query($sql);
if($res===false) {
return false;
}
// TODO Add triggers
return true;
}
@ -4690,7 +4709,6 @@ abstract class CommonObject
{
}
/**
* Update object into database
@ -4702,10 +4720,36 @@ abstract class CommonObject
*/
public function updateCommon(User $user, $notrigger = false)
{
foreach ($this->fields as $k => $v) {
if (is_array($key)){
$i=array_search($k, $key);
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'=' .$this->quote( $v ) ;
continue;
}
}
$tmp[] = $k.'='.$this->quote($v);
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ;
$res = $this->query( $sql );
if($res===false) {
//error
return false;
}
// TODO Add triggers
return true;
}
/**
* Delete object in database
*
@ -4718,4 +4762,20 @@ abstract class CommonObject
{
}
/**
* Add quote to field value if necessary
*
* @param string|int $value value to protect
* @return string|int
*/
function quote($value) {
if(is_null($value)) return 'NULL';
else if(is_numeric($value)) return $value;
else return "'".$this->escape( $value )."'";
}
}

View File

@ -295,122 +295,5 @@ abstract class DoliDB implements Database
{
return $this->lastqueryerror;
}
/*
* Add quote to field value if necessary
*
* @param string|int $value value to protect
* @return string|int
*/
function quote($value) {
if(is_null($value)) return 'NULL';
else if(is_numeric($value)) return $value;
else return "'".$this->escape( $value )."'";
}
/**
* Generate and execute Update SQL commande
*
* @param string $table table to update
* @param array $values array of values to update
* @param int|string|array $key key of value to select row to update
* @return bool|result false or boolean
*/
function update($table,$fields,$key){
foreach ($fields as $k => $v) {
if (is_array($key)){
$i=array_search($k , $key );
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'=' .$this->quote( $v ) ;
continue;
}
}
$tmp[] = $k.'='.$this->quote($v);
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ;
$res = $this->query( $sql );
if($res===false) {
//error
return false;
}
return true;
}
/**
* Generate and execute Insert SQL commande
*
* @param string $table table to update
* @param array $values array of values to update
* @return bool|result false or boolean
*/
function insert($table,$fields){
foreach ($fields as $k => $v) {
$keys[] = $k;
$values[] = $this->quote($v);
}
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.'
( '.implode( ",", $keys ).' )
VALUES ( '.implode( ",", $values ).' ) ';
$res = $this->query($sql);
if($res===false) {
return false;
}
return true;
}
/**
* Generate and execute Delete SQL commande
*
* @param string $table table for the delete
* @param array $values array of values to delete
* @param int|string|array $key key of value to select row to update
* @return bool|result false or boolean
*/
function delete($table,$fields,$key){
foreach ($fields as $k => $v) {
if (is_array($key)){
$i=array_search($k , $key );
if ( $i !== false) {
$where[] = $key[$i].'=' . $this->quote( $v ) ;
continue;
}
} else {
if ( $k == $key) {
$where[] = $k.'='.$this->quote( $v ) ;
continue;
}
}
}
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.implode(' AND ',$where);
$res = $this->query( $sql );
if($res===false) {
return false;
}
return true;
}
}

View File

@ -447,7 +447,7 @@ CantRemovePaymentWithOneInvoicePaid=Can't remove payment since there is at least
ExpectedToPay=Expected payment
CantRemoveConciliatedPayment=Can't remove conciliated payment
PayedByThisPayment=Paid by this payment
ClosePaidInvoicesAutomatically=Classify "Paid" all standard, situation or replacement invoices entirely paid.
ClosePaidInvoicesAutomatically=Classify "Paid" all standard, down payment or replacement invoices entirely paid.
ClosePaidCreditNotesAutomatically=Classify "Paid" all credit notes entirely paid back.
ClosePaidContributionsAutomatically=Classify "Paid" all social or fiscal contributions entirely paid.
AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be automatically closed to status "Paid".

View File

@ -1271,9 +1271,10 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
{
$enablebrowsernotif=false;
if (! empty($conf->agenda->enabled) && ! empty($conf->global->AGENDA_NOTIFICATION)) $enablebrowsernotif=true;
if ($conf->browser->layout == 'phone') $enablebrowsernotif=false;
if ($enablebrowsernotif)
{
print '<!-- Includes JS of Dolibarr -->'."\n";
print '<!-- Includes JS of Dolibarr (brwoser layout = '.$conf->browser->layout.')-->'."\n";
print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_notification.js.php?version='.urlencode(DOL_VERSION).($ext?'&amp;'.$ext:'').'"></script>'."\n";
}
}

View File

@ -23,7 +23,7 @@
require_once '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
@ -463,7 +463,8 @@ function card_line(&$inventory, &$lines, $mode)
if(!empty($TCacheEntrepot[$Inventorydet->fk_warehouse])) $e = $TCacheEntrepot[$Inventorydet->fk_warehouse];
elseif($e->fetch($Inventorydet->fk_warehouse) > 0) $TCacheEntrepot[$e->id] = $e;
$qty = (float)GETPOST('qty_to_add')[$k];
$qtytoadd = GETPOST('qty_to_add', 'array');
$qty = (float) $qtytoadd[$k];
$lines[]=array(
'produit' => $product->getNomUrl(1).'&nbsp;-&nbsp;'.$product->label,

View File

@ -23,7 +23,7 @@
require_once '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/inventory/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';

View File

@ -103,7 +103,7 @@ class Listview
/**
* @param string $key field name
* @param array $TParam array of configuration
* @param string $TParam array of configuration
* @return array
*/
private function getSearchKey($key, &$TParam)
@ -149,7 +149,7 @@ class Listview
/**
* @param array $TSQLMore contain some additional sql instructions
* @param string $TSQLMore contain some additional sql instructions
* @param string $value date with read format
* @param string $sKey field name
*/
@ -181,9 +181,9 @@ class Listview
/**
* @param array $TSQLMore contain some additional sql instructions
* @param string $TSQLMore contain some additional sql instructions
* @param string $value value to filter
* @param array $TParam array of configuration
* @param string $TParam array of configuration
* @param string $sKey field name
* @param string $key reference of sKey to find value into TParam
* @return bool
@ -222,7 +222,7 @@ class Listview
/**
* @param string $sql standard select sql
* @param array $TParam array of configuration
* @param string $TParam array of configuration
* @return string
*/
private function search($sql, &$TParam)
@ -289,7 +289,7 @@ class Listview
/**
* @param string $sql standard select sql
* @param array $TParam array of configuration
* @param string $TParam array of configuration
* @return string
*/
public function render($sql, $TParam=array())
@ -321,8 +321,8 @@ class Listview
}
/**
* @param array $THeader the configuration of header
* @param array $TParam array of configuration
* @param string $THeader the configuration of header
* @param string $TParam array of configuration
* @return array
*/
private function setSearch(&$THeader, &$TParam)
@ -427,8 +427,8 @@ class Listview
/**
* Function to analyse and calculate the total from a column
*
* @param $TField
* @param $TParam
* @param string $TField TField
* @param string $TParam TParam
* @return array
*/
private function get_total(&$TField, &$TParam)
@ -495,9 +495,9 @@ class Listview
*/
/**
* @param $TParam
* @param $TField
* @param $THeader
* @param string $TParam TParam
* @param string $TField TField
* @param string $THeader THeader
* @return array
*/
private function setExport(&$TParam, $TField, $THeader)
@ -535,8 +535,8 @@ class Listview
}
/**
* @param $TField
* @param $TTotalGroup
* @param string $TField TField
* @param string $TTotalGroup TTotalGroup
* @return array
*/
private function addTotalGroup($TField, $TTotalGroup)
@ -594,11 +594,11 @@ class Listview
}
/**
* @param $THeader
* @param $TField
* @param $TTotal
* @param $TTotalGroup
* @param $TParam
* @param string $THeader THeader
* @param string $TField TField
* @param string $TTotal TTotal
* @param string $TTotalGroup TTotalGroup
* @param string $TParam TParam
* @return string
*/
private function renderList(&$THeader, &$TField, &$TTotal, &$TTotalGroup, &$TParam)
@ -723,9 +723,9 @@ class Listview
}
/**
* @param $db
* @param $TField
* @param array $TParam
* @param string $db Db
* @param string $TField TField
* @param string $TParam TParam
*/
public function renderArray(&$db, $TField, $TParam=array())
{
@ -744,9 +744,9 @@ class Listview
/**
* @param $THeader
* @param $TField
* @param $TParam
* @param string $THeader THeader
* @param string $TField TField
* @param string $TParam TParam
* @return bool
*/
private function parse_array(&$THeader, &$TField, &$TParam)
@ -853,8 +853,8 @@ class Listview
}
/**
* @param $TParam
* @param $line_number
* @param string $TParam TParam
* @param string $line_number aaa
* @return bool
*/
private function in_view(&$TParam, $line_number)
@ -874,9 +874,9 @@ class Listview
}
/**
* @param $TField
* @param $TParam
* @param $currentLine
* @param string $TField TField
* @param string $TParam TParam
* @param string $currentLine aaa
*/
private function set_line(&$TField, &$TParam, $currentLine)
{
@ -910,7 +910,7 @@ class Listview
if(isset($TParam['eval'][$field]) && in_array($field,array_keys($row)))
{
$strToEval = 'return '.strtr( $TParam['eval'][$field] , array_merge( $trans, array('@val@'=>$row[$field]) )).';';
$strToEval = 'return '.strtr( $TParam['eval'][$field], array_merge( $trans, array('@val@'=>$row[$field]) )).';';
$row[$field] = eval($strToEval);
}
@ -932,7 +932,7 @@ class Listview
if($TParam['type'][$field]=='hour') { $row[$field] = date('H:i', strtotime($row[$field])); }
if($TParam['type'][$field]=='money') { $row[$field] = '<div align="right">'.price($row[$field],0,'',1,-1,2).'</div>'; }
if($TParam['type'][$field]=='number') { $row[$field] = '<div align="right">'.price($row[$field]).'</div>'; }
if($TParam['type'][$field]=='integer') { $row[$field] = '<div align="right">'.(int)$row[$field].'</div>'; }
if($TParam['type'][$field]=='integer') { $row[$field] = '<div align="right">'.((int) $row[$field]).'</div>'; }
}
if(isset($TParam['link'][$field]))
@ -945,7 +945,7 @@ class Listview
{
if(isset($TParam['translate'][$field][''])) unset($TParam['translate'][$field]['']);
$row[$field] = strtr( $row[$field] , $TParam['translate'][$field]);
$row[$field] = strtr( $row[$field], $TParam['translate'][$field]);
}
}
}
@ -986,8 +986,8 @@ class Listview
}
/**
* @param $sql
* @param $TParam
* @param string $sql sql
* @param string $TParam TParam
* @return string
*/
private function limitSQL($sql, &$TParam)
@ -1001,10 +1001,10 @@ class Listview
}
/**
* @param $THeader
* @param $TField
* @param $TParam
* @param $sql
* @param string $THeader THeader
* @param string $TField TField
* @param string $TParam TParam
* @param string $sql sql
*/
private function parse_sql(&$THeader, &$TField, &$TParam, $sql)
{