Merge remote-tracking branch 'origin/3.7' into develop

Conflicts:
	README.md
	htdocs/accountancy/journal/bankjournal.php
	htdocs/accountancy/journal/cashjournal.php
This commit is contained in:
Laurent Destailleur 2015-02-26 13:36:07 +01:00
commit daabc113a5
21 changed files with 473 additions and 877 deletions

View File

@ -21,8 +21,9 @@ vous devez vous réorienter vers DoliWamp (la version tout-en-un
de Dolibarr pour Windows), DoliDeb (la version tout-en-un pour Debian ou de Dolibarr pour Windows), DoliDeb (la version tout-en-un pour Debian ou
Ubuntu) ou DoliRpm (la version tout-en-un de Dolibarr pour Fedora, Redhat, Ubuntu) ou DoliRpm (la version tout-en-un de Dolibarr pour Fedora, Redhat,
OpenSuse, Mandriva ou Mageia). OpenSuse, Mandriva ou Mageia).
Vous pouvez les télécharger à l'adresse:
http://www.dolibarr.org/downloads/ Vous pouvez les télécharger depuis la rubrique *download* du portail officiel:
http://www.dolibarr.org/
Si vous avez déjà installé un serveur Web avec PHP et une base de donnée (Mysql), Si vous avez déjà installé un serveur Web avec PHP et une base de donnée (Mysql),
vous pouvez installer Dolibarr avec cette version de la manière suivante: vous pouvez installer Dolibarr avec cette version de la manière suivante:

View File

@ -22,7 +22,7 @@ Other licenses apply for some included dependencies. See [COPYRIGHT](COPYRIGHT)
### Download ### Download
Official releases are available on the [website](http://www.dolibarr.org/downloads). Releases can be downloaded from [official website](http://www.dolibarr.org/).
### Simple setup ### Simple setup

View File

@ -103,9 +103,7 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; $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 bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
// To isolate the cash of the other accounts $sql .= " WHERE ba.rowid=".$id_accountancy_journal;
$sql .= " WHERE ba.courant <> 2";
$sql .= " AND ba.rowid=".$id_accountancy_journal;
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {
$sql .= " AND ba.entity = " . $conf->entity; $sql .= " AND ba.entity = " . $conf->entity;
} }
@ -172,7 +170,8 @@ if ($result) {
// get_url may return -1 which is not traversable // get_url may return -1 which is not traversable
if (is_array($links)) if (is_array($links))
{ {
foreach ($links as $key => $val)
foreach ( $links as $key => $val )
{ {
$tabtype[$obj->rowid] = $links[$key]['type']; $tabtype[$obj->rowid] = $links[$key]['type'];
@ -200,24 +199,6 @@ if ($result) {
$chargestatic->id = $links[$key]['url_id']; $chargestatic->id = $links[$key]['url_id'];
$chargestatic->ref = $links[$key]['url_id']; $chargestatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
if ($reg[1] == 'socialcontribution')
$reg[1] = 'SocialContribution';
$chargestatic->lib = $langs->trans($reg[1]);
}
else if ($links[$key]['type'] == 'company')
{
$societestatic->id = $links[$key]['url_id'];
$societestatic->name = $links[$key]['label'];
$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
}
else if ($links[$key]['type'] == 'sc')
{
$chargestatic->id = $links[$key]['url_id'];
$chargestatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2); $tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) { if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
if ($reg[1] == 'socialcontribution') if ($reg[1] == 'socialcontribution')
@ -238,6 +219,7 @@ if ($result) {
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid";
$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid; $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid); $resultmid = $db->query($sqlmid);
if ($resultmid) if ($resultmid)
@ -257,6 +239,7 @@ if ($result) {
{ {
$paymentsalstatic->id = $links[$key]['url_id']; $paymentsalstatic->id = $links[$key]['url_id'];
$paymentsalstatic->ref = $links[$key]['url_id']; $paymentsalstatic->ref = $links[$key]['url_id'];
$paymentsalstatic->label = $links[$key]['label'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2); $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
$tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount; $tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount;
} }
@ -269,36 +252,14 @@ if ($result) {
$tabtp [$obj->rowid] [$accountancy_account_salary] += $obj->amount; $tabtp [$obj->rowid] [$accountancy_account_salary] += $obj->amount;
}*/ }*/
} }
else if ($links[$key]['type'] == 'payment_vat')
{
$paymentvatstatic->id = $links[$key]['url_id'];
$paymentvatstatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
$tabtp[$obj->rowid][$cpttva] += $obj->amount;
}
else if ($links[$key]['type'] == 'payment_salary')
{
$paymentsalstatic->id = $links[$key]['url_id'];
$paymentsalstatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
$tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount;
}
else if ($links[$key]['type'] == 'banktransfert')
{
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
$tabtp[$obj->rowid][$cpttva] += $obj->amount;
}
/*else {
$tabtp [$obj->rowid] [$accountancy_account_salary] += $obj->amount;
}*/
}
} }
$tabbq[$obj->rowid][$compta_bank] += $obj->amount; $tabbq[$obj->rowid][$compta_bank] += $obj->amount;
// if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
$i ++; $i++;
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
@ -306,17 +267,16 @@ if ($result) {
/* /*
* Actions * Actions
* FIXME Action should be before any view
*/ */
// Write bookkeeping // Write bookkeeping
if ($action == 'writeBookKeeping') if ($action == 'writeBookKeeping')
{ {
$error = 0; $error = 0;
foreach ($tabpay as $key => $val) foreach ( $tabpay as $key => $val )
{ {
// Bank // Bank
foreach ($tabbq[$key] as $k => $mt) foreach ( $tabbq[$key] as $k => $mt )
{ {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
@ -368,7 +328,7 @@ if ($action == 'writeBookKeeping')
} }
} }
// Third party // Third party
foreach ($tabtp[$key] as $k => $mt) foreach ( $tabtp[$key] as $k => $mt )
{ {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
@ -467,6 +427,7 @@ if ($action == 'export_csv')
foreach ( $tabpay as $key => $val ) { foreach ( $tabpay as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
@ -484,8 +445,12 @@ if ($action == 'export_csv')
} }
// Third party // Third party
foreach ( $tabtp[$key] as $k => $mt ) { if (is_array ( $tabtp[$key]))
if ($mt) { {
foreach ( $tabtp[$key] as $k => $mt )
{
if ($mt)
{
print $date . $sep; print $date . $sep;
print $bank_journal . $sep; print $bank_journal . $sep;
if ($val["lib"] == '(SupplierInvoicePayment)') { if ($val["lib"] == '(SupplierInvoicePayment)') {
@ -502,6 +467,25 @@ if ($action == 'export_csv')
} }
} }
} }
else
{
foreach ( $tabbq[$key] as $k => $mt )
{
if (1)
{
print $date . $sep;
print $bank_journal . $sep;
print $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . $sep;
print $sep;
print ($mt < 0 ? 'D' : 'C') . $sep;
print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
print $val["type_payment"] . $sep;
print $val["ref"] . $sep;
print "\n";
}
}
}
}
} else // Model Classic Export } else // Model Classic Export
{ {
foreach ( $tabpay as $key => $val ) { foreach ( $tabpay as $key => $val ) {
@ -522,7 +506,10 @@ if ($action == 'export_csv')
} }
// Third party // Third party
foreach ( $tabtp[$key] as $k => $mt ) { if (is_array ( $tabtp[$key]))
{
foreach ( $tabtp[$key] as $k => $mt )
{
if ($mt) { if ($mt) {
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . $val["type_payment"] . '"' . $sep; print '"' . $val["type_payment"] . '"' . $sep;
@ -534,6 +521,23 @@ if ($action == 'export_csv')
} }
} }
} }
else
{
foreach ( $tabbq[$key] as $k => $mt )
{
if (1)
{
print '"' . $date . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep;
print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . '"' . $sep;
print '"' . $langs->trans("Bank") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"';
print "\n";
}
}
}
}
} }
} }
else else
@ -544,13 +548,53 @@ else
llxHeader('', $langs->trans("BankJournal")); llxHeader('', $langs->trans("BankJournal"));
$namereport = $langs->trans("BankJournal"); $namereport = $langs->trans("BankJournal");
$namelink = ''; $description = $langs->trans("DescBankJournal");
$periodlink = '';
$exportlink = '';
$builddate = time();
$description = $langs->trans("DescBankJournal") . '<br>';
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
report_header($namereport, $namelink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
// Report
$h=0;
$head[$h][0] = $_SERVER["PHP_SELF"].'?id_account='.$id_accountancy_journal;
$head[$h][1] = $langs->trans("Report");
$head[$h][2] = 'report';
dol_fiche_head($head, $hselected);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id_account='.$id_accountancy_journal.'">';
print '<table width="100%" class="border">';
// Title
print '<tr>';
print '<td valign="top" width="110">'.$langs->trans("ReportName").'</td>';
print '<td colspan="3">'.$namereport.'</td>';
print '</td>';
print '</tr>';
// Period report
print '<tr>';
print '<td>'.$langs->trans("ReportPeriod").'</td>';
if (! $periodlink) print '<td colspan="3">';
else print '<td>';
if ($period) print $period;
if ($periodlink) print '</td><td colspan="2">'.$periodlink;
print '</td>';
print '</tr>';
// Description
print '<tr>';
print '<td valign="top">'.$langs->trans("ReportDescription").'</td>';
print '<td colspan="3">'.$description.'</td>';
print '</tr>';
print '<tr>';
print '<td colspan="4" align="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></td>';
print '</tr>';
print '</table>';
print '</form>';
print '</div>';
// End report
print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />'; print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
@ -611,6 +655,8 @@ else
} }
// Third party // Third party
if (is_array ( $tabtp[$key]))
{
foreach ( $tabtp[$key] as $k => $mt ) { foreach ( $tabtp[$key] as $k => $mt ) {
if ($k != 'type') { if ($k != 'type') {
print "<tr " . $bc[$var] . ">"; print "<tr " . $bc[$var] . ">";
@ -624,7 +670,21 @@ else
print "</tr>"; print "</tr>";
} }
} }
}
else
{
foreach ( $tabbq[$key] as $k => $mt )
{
print "<tr " . $bc[$var] . ">";
print "<td>" . $date . "</td>";
print "<td>" . $reflabel . "</td>";
print "<td>" . $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . "</td>";
print "<td>" . $langs->trans('ThirdParty') . "</td>";
print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
}
}
$var = ! $var; $var = ! $var;
} }

View File

@ -1,533 +0,0 @@
<?php
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013-2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.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/accountancy/journal/cashjournal.php
* \ingroup Accounting Expert
* \brief Page with cash journal
*/
require '../../main.inc.php';
// Class
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
// Langs
$langs->load("companies");
$langs->load("other");
$langs->load("compta");
$langs->load("bank");
$langs->load("accountancy");
$date_startmonth = GETPOST('date_startmonth');
$date_startday = GETPOST('date_startday');
$date_startyear = GETPOST('date_startyear');
$date_endmonth = GETPOST('date_endmonth');
$date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
// Security check
if ($user->societe_id > 0)
accessforbidden();
$action = GETPOST('action');
/*
* View
*/
$year_current = strftime("%Y", dol_now());
$pastmonth = strftime("%m", dol_now()) - 1;
$pastmonthyear = $year_current;
if ($pastmonth == 0) {
$pastmonth = 12;
$pastmonthyear --;
}
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
$date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
$date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
}
$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
$idpays = $p[0];
$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, soc.code_compta, ba.courant,";
$sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop";
$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 . "societe as soc on bu1.url_id=soc.rowid";
// Code opération type caisse
$sql .= " WHERE ba.courant = 2";
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND ba.entity = " . $conf->entity;
}
if ($date_start && $date_end)
$sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'";
$sql .= " ORDER BY b.datev";
$object = new Account($db);
$paymentstatic = new Paiement($db);
$paymentsupplierstatic = new PaiementFourn($db);
$societestatic = new Societe($db);
$chargestatic = new ChargeSociales($db);
$paymentvatstatic = new TVA($db);
dol_syslog("accountancy/journal/cashjournal.php:: sql=" . $sql, LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
// les variables
$cptfour = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"));
$cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"));
$cpttva = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) ? $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE : $langs->trans("CodeNotDef"));
$cptsociale = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) ? $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE : $langs->trans("CodeNotDef"));
$tabpay = array ();
$tabbq = array ();
$tabtp = array ();
$tabcompany = array ();
$tabtype = array ();
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($result);
// controls
$compta_bank = $obj->account_number;
if ($obj->label == '(SupplierInvoicePayment)')
$compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $cptfour);
if ($obj->label == '(CustomerInvoicePayment)')
$compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $cptcli);
if ($obj->typeop == '(BankTransfert)')
$compta_soc = $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH;
// variable bookkeeping
$tabpay[$obj->rowid]["date"] = $obj->do;
$tabpay[$obj->rowid]["ref"] = $obj->label;
$tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) {
$tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
} else {
$tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60);
}
$links = $object->get_url($obj->rowid);
// get_url may return -1 which is not traversable
if (is_array($links))
{
foreach ( $links as $key => $val )
{
$tabtype[$obj->rowid] = $links[$key]['type'];
if ($links[$key]['type'] == 'payment') {
$paymentstatic->id = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
} else if ($links[$key]['type'] == 'payment_supplier') {
$paymentsupplierstatic->id = $links[$key]['url_id'];
$paymentsupplierstatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
} else if ($links[$key]['type'] == 'company') {
$societestatic->id = $links[$key]['url_id'];
$societestatic->name = $links[$key]['label'];
$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
} else if ($links[$key]['type'] == 'sc') {
$chargestatic->id = $links[$key]['url_id'];
$chargestatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
if ($reg[1] == 'socialcontribution')
$reg[1] = 'SocialContribution';
$chargestatic->lib = $langs->trans($reg[1]);
} else {
$chargestatic->lib = $links[$key]['label'];
}
$chargestatic->ref = $chargestatic->lib;
$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
$sqlmid = 'SELECT cchgsoc.accountancy_code';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid";
$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
}
/*else {
$tabtp [$obj->rowid] [$cptsociale] += $obj->amount;
}*/
}
}
}
$tabbq[$obj->rowid][$compta_bank] += $obj->amount;
// if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
$i ++;
}
} else {
dol_print_error($db);
}
/*
* Actions
*/
// write bookkeeping
if ($action == 'writeBookKeeping')
{
$error = 0;
foreach ( $tabpay as $key => $val )
{
// cash
foreach ( $tabbq[$key] as $k => $mt )
{
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'cash';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->code_tiers = $tabcompany[$key]['code_client'];
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $compte->label;
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt >= 0 ? $mt : 0);
$bookkeeping->credit = ($mt < 0 ? - $mt : 0);
$bookkeeping->code_journal = $conf->global->ACCOUNTING_CASH_JOURNAL;
if ($tabtype[$key] == 'payment')
{
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
} else if ($tabtype[$key] == 'payment_supplier') {
$sqlmid = 'SELECT facf.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
}
$result = $bookkeeping->create();
if ($result < 0) {
$error ++;
setEventMessage($object->errors, 'errors');
}
}
// third party
foreach ( $tabtp[$key] as $k => $mt ) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'cash';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->label_compte = $tabcompany[$key]['name'];
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt < 0 ? - $mt : 0);
$bookkeeping->credit = ($mt >= 0 ? $mt : 0);
$bookkeeping->code_journal = $conf->global->ACCOUNTING_CASH_JOURNAL;
if ($tabtype[$key] == 'sc') {
$bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment') {
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
} else if ($tabtype[$key] == 'payment_supplier') {
$sqlmid = 'SELECT facf.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
} else if ($tabtype[$key] == 'company') {
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
} else {
$bookkeeping->doc_ref = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
}
$result = $bookkeeping->create();
if ($result < 0) {
$error ++;
setEventMessage($object->errors, 'errors');
}
}
}
if (empty($error)) {
setEventMessage($langs->trans('Success'), 'mesgs');
}
}
// Export
if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$cash_journal = $conf->global->ACCOUNTING_CASH_JOURNAL;
header('Content-Type: text/csv');
header('Content-Disposition:attachment;filename=journal_caisse.csv');
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export
{
$sep = ";";
foreach ( $tabpay as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
// Cash
foreach ( $tabbq[$key] as $k => $mt ) {
print $date . $sep;
print $cash_journal . $sep;
print length_accountg(html_entity_decode($k)) . $sep;
print $sep;
print ($mt < 0 ? 'C' : 'D') . $sep;
print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
print $val["type_payment"] . $sep;
print $val["ref"] . $sep;
print "\n";
}
// Third party
foreach ( $tabtp[$key] as $k => $mt ) {
if ($mt) {
print $date . $sep;
print $cash_journal . $sep;
if ($val["lib"] == '(SupplierInvoicePayment)') {
print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
} else {
print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
}
print length_accounta(html_entity_decode($k)) . $sep;
print ($mt < 0 ? 'D' : 'C') . $sep;
print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
print $val["type_payment"] . $sep;
print $val["ref"] . $sep;
print "\n";
}
}
}
} else // Model Classic Export
{
foreach ( $tabpay as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), 'day');
// Cash
foreach ( $tabbq[$key] as $k => $mt ) {
print '"' . $date . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep;
print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
print '"' . $langs->trans("Cash") . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
print "\n";
}
// Third party
foreach ( $tabtp[$key] as $k => $mt ) {
if ($mt) {
print '"' . $date . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . $langs->trans("ThirdParty") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"';
print "\n";
}
}
}
}
} else {
$form = new Form($db);
llxHeader('', $langs->trans("CashJournal"), '');
$name = $langs->trans("CashJournal");
$nomlink = '';
$periodlink = '';
$exportlink = '';
$builddate = time();
$description = $langs->trans("DescCashJournal") . '<br>';
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
report_header($name, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writeBookKeeping();" />';
print '
<script type="text/javascript">
function launch_export() {
$("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
$("div.fiche div.tabBar form input[type=\"submit\"]").click();
$("div.fiche div.tabBar form input[name=\"action\"]").val("");
}
function writeBookKeeping() {
$("div.fiche div.tabBar form input[name=\"action\"]").val("writeBookKeeping");
$("div.fiche div.tabBar form input[type=\"submit\"]").click();
$("div.fiche div.tabBar form input[name=\"action\"]").val("");
}
</script>';
/*
* Show result array
*/
print '<br><br>';
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print "<td>" . $langs->trans("Date") . "</td>";
print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
print "<td>" . $langs->trans("Account") . "</td>";
print "<td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
print "</tr>\n";
$var = true;
$r = '';
foreach ( $tabpay as $key => $val ) {
$date = dol_print_date($db->jdate($val["date"]), 'day');
// Cash
foreach ( $tabbq[$key] as $k => $mt ) {
if (1) {
print "<tr " . $bc[$var] . " >";
print "<td>" . $date . "</td>";
print "<td>" . $val["lib"] . "</td>";
print "<td>" . length_accountg($k) . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
print "</tr>";
}
}
// third party
foreach ( $tabtp[$key] as $k => $mt ) {
if ($k != 'type') {
print "<tr " . $bc[$var] . ">";
print "<td>" . $date . "</td>";
print "<td>" . $val["soclib"] . "</td>";
print "<td>" . length_accounta($k) . "</td>";
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
}
}
$var = ! $var;
}
print "</table>";
// End of page
llxFooter();
}
$db->close();

View File

@ -316,7 +316,7 @@ class ActionComm extends CommonObject
} }
$sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
$sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['mandatory']?$val['mandatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['mandatory'])?'0':$val['mandatory']).", ".(empty($val['transparency'])?'0':$val['transparency']).", ".(empty($val['answer_status'])?'0':$val['answer_status']).")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) if (! $resql)
@ -680,7 +680,7 @@ class ActionComm extends CommonObject
foreach($this->userassigned as $key => $val) foreach($this->userassigned as $key => $val)
{ {
$sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
$sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['manadatory']?$val['manadatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['manadatory'])?'0':$val['manadatory']).", ".(empty($val['transparency'])?'0':$val['transparency']).", ".(empty($val['answer_status'])?'0':$val['answer_status']).")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) if (! $resql)

View File

@ -267,6 +267,8 @@ class Mailing extends CommonObject
$object=new Mailing($this->db); $object=new Mailing($this->db);
$object->context['createfromclone']='createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -362,6 +364,8 @@ class Mailing extends CommonObject
} }
unset($object->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -235,27 +235,30 @@ class Propal extends CommonObject
return -5; return -5;
} }
$propalligne=new PropaleLigne($this->db); $line=new PropaleLigne($this->db);
$propalligne->fk_propal=$this->id;
$propalligne->fk_remise_except=$remise->id; $this->line->context = $this->context;
$propalligne->desc=$remise->description; // Description ligne
$propalligne->tva_tx=$remise->tva_tx; $line->fk_propal=$this->id;
$propalligne->subprice=-$remise->amount_ht; $line->fk_remise_except=$remise->id;
$propalligne->fk_product=0; // Id produit predefini $line->desc=$remise->description; // Description ligne
$propalligne->qty=1; $line->tva_tx=$remise->tva_tx;
$propalligne->remise=0; $line->subprice=-$remise->amount_ht;
$propalligne->remise_percent=0; $line->fk_product=0; // Id produit predefini
$propalligne->rang=-1; $line->qty=1;
$propalligne->info_bits=2; $line->remise=0;
$line->remise_percent=0;
$line->rang=-1;
$line->info_bits=2;
// TODO deprecated // TODO deprecated
$propalligne->price=-$remise->amount_ht; $line->price=-$remise->amount_ht;
$propalligne->total_ht = -$remise->amount_ht; $line->total_ht = -$remise->amount_ht;
$propalligne->total_tva = -$remise->amount_tva; $line->total_tva = -$remise->amount_tva;
$propalligne->total_ttc = -$remise->amount_ttc; $line->total_ttc = -$remise->amount_ttc;
$result=$propalligne->insert(); $result=$line->insert();
if ($result > 0) if ($result > 0)
{ {
$result=$this->update_price(1); $result=$this->update_price(1);
@ -272,7 +275,7 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$propalligne->error; $this->error=$line->error;
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -389,6 +392,8 @@ class Propal extends CommonObject
// Insert line // Insert line
$this->line=new PropaleLigne($this->db); $this->line=new PropaleLigne($this->db);
$this->line->context = $this->context;
$this->line->fk_propal=$this->id; $this->line->fk_propal=$this->id;
$this->line->label=$label; $this->line->label=$label;
$this->line->desc=$desc; $this->line->desc=$desc;
@ -541,6 +546,8 @@ class Propal extends CommonObject
// Update line // Update line
$this->line=new PropaleLigne($this->db); $this->line=new PropaleLigne($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new PropaleLigne($this->db); $staticline=new PropaleLigne($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);
@ -949,6 +956,8 @@ class Propal extends CommonObject
{ {
global $user,$langs,$conf,$hookmanager; global $user,$langs,$conf,$hookmanager;
$this->context['createfromclone']='createfromclone';
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
@ -1042,6 +1051,8 @@ class Propal extends CommonObject
// End call triggers // End call triggers
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {
@ -3112,6 +3123,7 @@ class PropaleLigne extends CommonObject
if (empty($this->special_code)) $this->special_code=0; if (empty($this->special_code)) $this->special_code=0;
if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->subprice)) $this->subprice=0;
if (empty($this->pa_ht)) $this->pa_ht=0; if (empty($this->pa_ht)) $this->pa_ht=0;

View File

@ -877,6 +877,8 @@ class Commande extends CommonOrder
$error=0; $error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// get extrafields so they will be clone // get extrafields so they will be clone
@ -941,6 +943,8 @@ class Commande extends CommonOrder
// End call triggers // End call triggers
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {
@ -1200,6 +1204,8 @@ class Commande extends CommonOrder
// Insert line // Insert line
$this->line=new OrderLine($this->db); $this->line=new OrderLine($this->db);
$this->line->context = $this->context;
$this->line->fk_commande=$this->id; $this->line->fk_commande=$this->id;
$this->line->label=$label; $this->line->label=$label;
$this->line->desc=$desc; $this->line->desc=$desc;
@ -1314,6 +1320,8 @@ class Commande extends CommonOrder
$line=new OrderLine($this->db); $line=new OrderLine($this->db);
$line->context = $this->context;
$line->fk_product=$idproduct; $line->fk_product=$idproduct;
$line->desc=$prod->description; $line->desc=$prod->description;
$line->qty=$qty; $line->qty=$qty;
@ -2396,6 +2404,8 @@ class Commande extends CommonOrder
// Update line // Update line
$this->line=new OrderLine($this->db); $this->line=new OrderLine($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new OrderLine($this->db); $staticline=new OrderLine($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);

View File

@ -300,6 +300,8 @@ class BankCateg // extends CommonObject
$object=new BankCateg($this->db); $object=new BankCateg($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -327,6 +329,8 @@ class BankCateg // extends CommonObject
} }
unset($object->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -639,6 +639,8 @@ class Facture extends CommonInvoice
$error=0; $error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// get extrafields so they will be clone // get extrafields so they will be clone
@ -725,6 +727,8 @@ class Facture extends CommonInvoice
// End call triggers // End call triggers
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {
@ -2120,6 +2124,9 @@ class Facture extends CommonInvoice
// Insert line // Insert line
$this->line=new FactureLigne($this->db); $this->line=new FactureLigne($this->db);
$this->line->context = $this->context;
$this->line->fk_facture=$this->id; $this->line->fk_facture=$this->id;
$this->line->label=$label; // deprecated $this->line->label=$label; // deprecated
$this->line->desc=$desc; $this->line->desc=$desc;
@ -2263,6 +2270,8 @@ class Facture extends CommonInvoice
// Update line into database // Update line into database
$this->line=new FactureLigne($this->db); $this->line=new FactureLigne($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new FactureLigne($this->db); $staticline=new FactureLigne($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);
@ -2403,6 +2412,8 @@ class Facture extends CommonInvoice
$line=new FactureLigne($this->db); $line=new FactureLigne($this->db);
$line->context = $this->context;
// For triggers // For triggers
$line->fetch($rowid); $line->fetch($rowid);

View File

@ -33,6 +33,7 @@ class PaymentTerm // extends CommonObject
var $errors=array(); //!< To return several error codes (or messages) var $errors=array(); //!< To return several error codes (or messages)
//public $element='c_payment_term'; //!< Id that identify managed objects //public $element='c_payment_term'; //!< Id that identify managed objects
//public $table_element='c_payment_term'; //!< Name of table without prefix where object is stored //public $table_element='c_payment_term'; //!< Name of table without prefix where object is stored
var $context =array();
var $id; var $id;
@ -409,6 +410,8 @@ class PaymentTerm // extends CommonObject
$object=new PaymentTerm($this->db); $object=new PaymentTerm($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -436,6 +439,8 @@ class PaymentTerm // extends CommonObject
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -384,6 +384,8 @@ class PaymentSocialContribution extends CommonObject
$object=new PaymentSocialContribution($this->db); $object=new PaymentSocialContribution($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -411,6 +413,8 @@ class PaymentSocialContribution extends CommonObject
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -49,6 +49,7 @@ abstract class CommonObject
public $errors; public $errors;
public $canvas; // Contains canvas name if it is public $canvas; // Contains canvas name if it is
public $context=array(); // Use to pass context information
public $name; public $name;
public $lastname; public $lastname;

View File

@ -354,6 +354,7 @@ class ImportCsv extends ModeleImports
} }
else else
{ {
$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
// For each table to insert, me make a separate insert // For each table to insert, me make a separate insert
foreach($objimport->array_import_tables[0] as $alias => $tablename) foreach($objimport->array_import_tables[0] as $alias => $tablename)
{ {
@ -590,7 +591,7 @@ class ImportCsv extends ModeleImports
elseif (preg_match('/^lastrowid-/',$val)) elseif (preg_match('/^lastrowid-/',$val))
{ {
$tmp=explode('-',$val); $tmp=explode('-',$val);
$lastinsertid=$this->db->last_insert_id($tmp[1]); $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
$listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key);
$listvalues.=$lastinsertid; $listvalues.=$lastinsertid;
//print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
@ -632,6 +633,7 @@ class ImportCsv extends ModeleImports
if ($sql) if ($sql)
{ {
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
$last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
if ($resql) if ($resql)
{ {
//print '.'; //print '.';

View File

@ -718,6 +718,8 @@ class Cronjob extends CommonObject
$object=new Cronjob($this->db); $object=new Cronjob($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -744,6 +746,8 @@ class Cronjob extends CommonObject
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -1044,6 +1044,8 @@ class CommandeFournisseur extends CommonOrder
$error=0; $error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -1080,6 +1082,8 @@ class CommandeFournisseur extends CommonOrder
// End call triggers // End call triggers
} }
unset($this->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -1716,6 +1716,8 @@ class FactureFournisseur extends CommonInvoice
$object=new FactureFournisseur($this->db); $object=new FactureFournisseur($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -1762,6 +1764,8 @@ class FactureFournisseur extends CommonInvoice
} }
unset($object->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -324,6 +324,8 @@ class Productbatch extends CommonObject
$object=new Productbatch($this->db); $object=new Productbatch($this->db);
$object->context['createfromclone']='createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -350,6 +352,8 @@ class Productbatch extends CommonObject
} }
unset($object->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {

View File

@ -853,6 +853,8 @@ class Productcustomerprice extends CommonObject
$object = new Productcustomerprice($this->db); $object = new Productcustomerprice($this->db);
$object->context['createfromclone']='createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -875,6 +877,8 @@ class Productcustomerprice extends CommonObject
if (! $error) { if (! $error) {
} }
unset($object->context['createfromclone']);
// End // End
if (! $error) { if (! $error) {
$this->db->commit(); $this->db->commit();

View File

@ -1039,6 +1039,8 @@ class Project extends CommonObject
$clone_project=new Project($this->db); $clone_project=new Project($this->db);
$clone_project->context['createfromclone']='createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -1092,8 +1094,6 @@ class Project extends CommonObject
if (! $error) if (! $error)
{ {
$this->db->commit();
//Get the new project id //Get the new project id
$clone_project_id=$clone_project->id; $clone_project_id=$clone_project->id;
@ -1247,23 +1247,19 @@ class Project extends CommonObject
} }
} }
} }
}
unset($clone_project->context['createfromclone']);
if (! $error) if (! $error)
{ {
$this->db->commit();
return $clone_project_id; return $clone_project_id;
} }
else else
{
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
}
else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1; return -1;
} }
} }

View File

@ -1092,6 +1092,8 @@ class Task extends CommonObject
$clone_task=new Task($this->db); $clone_task=new Task($this->db);
$origin_task=new Task($this->db); $origin_task=new Task($this->db);
$clone_task->context['createfromclone']='createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
@ -1158,8 +1160,6 @@ class Task extends CommonObject
// End // End
if (! $error) if (! $error)
{ {
$this->db->commit();
$clone_task_id=$clone_task->id; $clone_task_id=$clone_task->id;
$clone_task_ref = $clone_task->ref; $clone_task_ref = $clone_task->ref;
@ -1279,20 +1279,19 @@ class Task extends CommonObject
{ {
//TODO clone time of affectation //TODO clone time of affectation
} }
}
unset($clone_task->context['createfromclone']);
if (! $error) if (! $error)
{ {
$this->db->commit();
return $clone_task_id; return $clone_task_id;
} }
else else
{
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
}
else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1; return -1;
} }
} }