diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 3e600755330..47d28991846 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -193,13 +193,18 @@ class BookKeeping extends CommonObject
$this->piece_num = 0;
- // First check if line not yet already in bookkeeping
+ // First check if line not yet already in bookkeeping.
+ // Note that we must include doc_type - fk_doc - numero_compte - label to be sure to have unicity of line (we may have several lines
+ // with same doc_type, fk_odc, numero_compte for 1 invoice line when using localtaxes with same account)
+ // WARNING: This is not reliable, label may have been modified. This is just a small protection.
+ // The page to make journalization make the test on couple doc_type - fk_doc only.
$sql = "SELECT count(*) as nb";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'";
$sql .= " AND fk_doc = " . $this->fk_doc;
- $sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines
+ //$sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 if record is for several lines
$sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'";
+ $sql .= " AND label_operation = '" . $this->db->escape($this->label_operation) . "'";
$sql .= " AND entity IN (" . getEntity('accountancy') . ")";
$resql = $this->db->query($sql);
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 193dd88b81f..18a440f0e25 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -99,6 +99,8 @@ $accounting = new AccountingAccount($db);
$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
$aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
+$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
+
/*
* Action
@@ -140,6 +142,7 @@ if (empty($reshook))
if ($massaction == 'ventil') {
$msg='';
+
//print '
' . $langs->trans("Processing") . '...
';
if (! empty($mesCasesCochees)) {
$msg = '' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'
';
@@ -167,7 +170,7 @@ if ($massaction == 'ventil') {
$accountventilated = new AccountingAccount($db);
$accountventilated->fetch($monCompte, '');
- dol_syslog("/accountancy/customer/list.php sql=" . $sql, LOG_DEBUG);
+ dol_syslog("accountancy/customer/list.php sql=" . $sql, LOG_DEBUG);
if ($db->query($sql)) {
$msg.= '' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '
';
$ok++;
@@ -197,23 +200,30 @@ $formother = new FormOther($db);
llxHeader('', $langs->trans("Ventilation"));
+if (empty($chartaccountcode))
+{
+ print $langs->trans("ErrorChartOfAccountSystemNotSelected");
+ llxFooter();
+ $db->close();
+ exit;
+}
+
// Customer Invoice lines
-$sql = "SELECT f.facnumber, f.rowid as facid, f.datef, f.type as ftype,";
-$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
-$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.accountancy_code_sell as code_sell, p.tva_tx as tva_tx_prod,";
-$sql .= " aa.rowid as aarowid";
+$sql = "SELECT f.rowid as facid, f.facnumber, f.datef, f.type as ftype,";
+$sql.= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
+$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.accountancy_code_sell as code_sell, p.tva_tx as tva_tx_prod,";
+$sql.= " aa.rowid as aarowid";
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
-$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
-$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
-$sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
-$sql .= " AND product_type <= 2";
-$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='' OR p.accountancy_code_sell NOT IN
- (SELECT aa.account_number FROM " . MAIN_DB_PREFIX . "accounting_account as aa , " . MAIN_DB_PREFIX . "accounting_system as asy WHERE fk_pcg_version = asy.pcg_version AND asy.rowid ='" . $conf->global->CHARTOFACCOUNTS . "'))";
+$sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
+$sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.fk_pcg_version = '" . $chartaccountcode."'";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.fk_pcg_version = '" . $chartaccountcode."'";
+$sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
+$sql.= " AND product_type <= 2";
// Add search filter like
if ($search_lineid) {
$sql .= natural_search("l.rowid", $search_lineid, 1);
@@ -255,7 +265,7 @@ else if ($search_year > 0)
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
} else {
- $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
+ $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
}
$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy
@@ -276,7 +286,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
-dol_syslog("/accountancy/customer/list.php", LOG_DEBUG);
+dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
$num_lines = $db->num_rows($result);
@@ -466,9 +476,11 @@ if ($result) {
print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
print '';
+ // Column with checkbox
print '';
- print ' aarowid ? "checked" : "") . '/>';
+ print ' aarowid ? "checked" : "") . '/>';
print ' ';
+
print '';
$i ++;
}
diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php
index 7a35fe0f725..0e4b9b05ac9 100644
--- a/htdocs/accountancy/expensereport/list.php
+++ b/htdocs/accountancy/expensereport/list.php
@@ -92,6 +92,8 @@ if (! $user->rights->accounting->bind->write)
$formaccounting = new FormAccounting($db);
$accounting = new AccountingAccount($db);
+$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
+
/*
* Action
@@ -182,18 +184,24 @@ $formother = new FormOther($db);
llxHeader('', $langs->trans("ExpenseReportsVentilation"));
+if (empty($chartaccountcode))
+{
+ print $langs->trans("ErrorChartOfAccountSystemNotSelected");
+ llxFooter();
+ $db->close();
+ exit;
+}
+
// Expense report lines
$sql = "SELECT er.ref, er.rowid as erid, er.date_debut,";
-$sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht as price, erd.fk_code_ventilation, erd.tva_tx as tva_tx_line, erd.vat_src_code, erd.date,";
-$sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label, f.accountancy_code as code_buy,";
-$sql .= " aa.rowid as aarowid";
-$sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
-$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport_det as erd ON er.rowid = erd.fk_expensereport";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON f.accountancy_code = aa.account_number";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
-$sql .= " WHERE er.fk_statut > 4 AND erd.fk_code_ventilation <= 0";
-$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR f.accountancy_code IS NULL OR f.accountancy_code ='')";
+$sql.= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht as price, erd.fk_code_ventilation, erd.tva_tx as tva_tx_line, erd.vat_src_code, erd.date,";
+$sql.= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label, f.accountancy_code as code_buy,";
+$sql.= " aa.rowid as aarowid";
+$sql.= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
+$sql.= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport_det as erd ON er.rowid = erd.fk_expensereport";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'";
+$sql.= " WHERE er.fk_statut > 4 AND erd.fk_code_ventilation <= 0";
// Add search filter like
if (strlen(trim($search_expensereport))) {
$sql .= natural_search("er.ref",$search_expensereport);
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 8fb68b24665..f06221a63f1 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -596,8 +596,9 @@ if (! $error && $action == 'writebookkeeping') {
if ($totaldebit != $totalcredit)
{
+ $error++;
$errorforline++;
- setEventMessages('Try to insert a non balanced transaction in book. Canceled. Surely a bug.', null, 'errors');
+ setEventMessages('Try to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors');
}
if (! $errorforline)
@@ -642,7 +643,7 @@ if (! $error && $action == 'writebookkeeping') {
$param.='&date_endday='.$date_endday;
$param.='&date_endmonth='.$date_endmonth;
$param.='&date_endyear='.$date_endyear;
- $param.='&in_bookeeping='.$in_bookeeping;
+ $param.='&in_bookkeeping='.$in_bookkeeping;
header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
exit;
}
diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php
index 524115e9d67..f324cbd3369 100644
--- a/htdocs/accountancy/journal/expensereportsjournal.php
+++ b/htdocs/accountancy/journal/expensereportsjournal.php
@@ -341,8 +341,9 @@ if ($action == 'writebookkeeping') {
if ($totaldebit != $totalcredit)
{
+ $error++;
$errorforline++;
- setEventMessages('Try to insert a non balanced transaction in book. Canceled. Surely a bug.', null, 'errors');
+ setEventMessages('Try to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors');
}
if (! $errorforline)
@@ -361,6 +362,8 @@ if ($action == 'writebookkeeping') {
}
}
+ $tabpay = $taber;
+
if (empty($error) && count($tabpay) > 0) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
@@ -385,7 +388,7 @@ if ($action == 'writebookkeeping') {
$param.='&date_endday='.$date_endday;
$param.='&date_endmonth='.$date_endmonth;
$param.='&date_endyear='.$date_endyear;
- $param.='&in_bookeeping='.$in_bookeeping;
+ $param.='&in_bookkeeping='.$in_bookkeeping;
header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
exit;
}
@@ -520,7 +523,7 @@ if (empty($action) || $action == 'view') {
$description.= $langs->trans("DescJournalOnlyBindedVisible").' ';
$listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger"));
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 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). ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
$varlink = 'id_journal=' . $id_journal;
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index cd490dceb2b..c8b0f297f26 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -156,6 +156,8 @@ if ($result) {
$vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code?' ('.$obj->vat_src_code.')':''), $mysoc, $mysoc, 0);
$compta_tva = (! empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
+ $compta_localtax1 = (! empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
+ $compta_localtax2 = (! empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
// Define array to display all VAT rates that use this accounting account $compta_tva
if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code))
@@ -388,8 +390,9 @@ if ($action == 'writebookkeeping') {
if ($totaldebit != $totalcredit)
{
+ $error++;
$errorforline++;
- setEventMessages('Try to insert a non balanced transaction in book. Canceled. Surely a bug.', null, 'errors');
+ setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
}
if (! $errorforline)
@@ -408,6 +411,8 @@ if ($action == 'writebookkeeping') {
}
}
+ $tabpay = $tabfac;
+
if (empty($error) && count($tabpay) > 0) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
@@ -432,7 +437,7 @@ if ($action == 'writebookkeeping') {
$param.='&date_endday='.$date_endday;
$param.='&date_endmonth='.$date_endmonth;
$param.='&date_endyear='.$date_endyear;
- $param.='&in_bookeeping='.$in_bookeeping;
+ $param.='&in_bookkeeping='.$in_bookkeeping;
header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
exit;
}
@@ -551,7 +556,7 @@ if (empty($action) || $action == 'view') {
}
$listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger"));
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 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). ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
$varlink = 'id_journal=' . $id_journal;
@@ -712,7 +717,8 @@ if (empty($action) || $action == 'view') {
// Subledger account
print "";
print ' ';
- print "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:'');
+ print " ";
+ print $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:'');
print " ";
print '' . ($mt >= 0 ? price($mt) : '') . " ";
print '' . ($mt < 0 ? price(- $mt) : '') . " ";
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 4f61a246c89..4f77c102788 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -193,7 +193,7 @@ if ($result) {
$tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
$tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
- $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
+ if (empty($line->tva_npr)) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; // We ignore line if VAT is a NPR
$tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
$tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
$tabcompany[$obj->rowid] = array (
@@ -396,8 +396,9 @@ if ($action == 'writebookkeeping') {
if ($totaldebit != $totalcredit)
{
+ $error++;
$errorforline++;
- setEventMessages('Try to insert a non balanced transaction in book. Canceled. Surely a bug.', null, 'errors');
+ setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
}
if (! $errorforline)
@@ -417,6 +418,8 @@ if ($action == 'writebookkeeping') {
}
+ $tabpay = $tabfac;
+
if (empty($error) && count($tabpay) > 0) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
@@ -441,7 +444,7 @@ if ($action == 'writebookkeeping') {
$param.='&date_endday='.$date_endday;
$param.='&date_endmonth='.$date_endmonth;
$param.='&date_endyear='.$date_endyear;
- $param.='&in_bookeeping='.$in_bookeeping;
+ $param.='&in_bookkeeping='.$in_bookkeeping;
header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
exit;
}
@@ -560,7 +563,7 @@ if (empty($action) || $action == 'view') {
$description .= $langs->trans("DepositsAreIncluded");
$listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger"));
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 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). ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
$varlink = 'id_journal=' . $id_journal;
diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php
index 786df760f6a..1d1d451f9ae 100644
--- a/htdocs/accountancy/supplier/lines.php
+++ b/htdocs/accountancy/supplier/lines.php
@@ -368,13 +368,13 @@ if ($result) {
print '';
print '' . price($objp->total_ht) . ' ';
- print '' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . ' ';
- print '';
+ print ' ' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . ' ';
+ print '';
print $codecompta . ' ';
print img_edit();
print ' ';
- print '' . $objp->country .' ';
- print '' . $objp->tva_intra . ' ';
+ print '' . $objp->country .' ';
+ print '' . $objp->tva_intra . ' ';
print ' ';
print "";
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index c95cb3f2c3d..5d9871eecfb 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -100,6 +100,8 @@ $accounting = new AccountingAccount($db);
$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
$aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
+$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
+
/*
* Action
@@ -117,39 +119,40 @@ if (empty($reshook))
// Purge search criteria
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
{
- $search_lineid = '';
- $search_ref = '';
- $search_invoice = '';
- $search_label = '';
- $search_desc = '';
- $search_amount = '';
- $search_account = '';
- $search_vat = '';
- $search_day = '';
- $search_month = '';
- $search_year = '';
+ $search_lineid = '';
+ $search_ref = '';
+ $search_invoice = '';
+ $search_label = '';
+ $search_desc = '';
+ $search_amount = '';
+ $search_account = '';
+ $search_vat = '';
+ $search_day = '';
+ $search_month = '';
+ $search_year = '';
}
// Mass actions
- $objectclass='AccountingAccount';
+ $objectclass='AccountingAccount';
$permtoread = $user->rights->accounting->read;
$permtodelete = $user->rights->accounting->delete;
$uploaddir = $conf->accounting->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
+
if ($massaction == 'ventil') {
$msg='';
+
//print '' . $langs->trans("Processing") . '...
';
if (! empty($mesCasesCochees)) {
$msg = '' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'
';
$msg.='';
- $mesCodesVentilChoisis = $codeventil;
$cpt = 0;
$ok=0;
$ko=0;
- foreach ( $mesCasesCochees as $maLigneCochee ) {
+ foreach ($mesCasesCochees as $maLigneCochee) {
$maLigneCourante = explode("_", $maLigneCochee);
$monId = $maLigneCourante[0];
$monCompte = GETPOST('codeventil'.$monId);
@@ -198,9 +201,17 @@ $formother = new FormOther($db);
llxHeader('', $langs->trans("SuppliersVentilation"));
+if (empty($chartaccountcode))
+{
+ print $langs->trans("ErrorChartOfAccountSystemNotSelected");
+ llxFooter();
+ $db->close();
+ exit;
+}
+
// Supplier Invoice Lines
-$sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef,";
-$sql.= " l.rowid, l.fk_product, l.description, l.total_ht as price, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
+$sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
+$sql.= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.accountancy_code_buy as code_buy, p.tva_tx as tva_tx_prod,";
$sql.= " aa.rowid as aarowid";
$parameters=array();
@@ -209,12 +220,9 @@ $sql.=$hookmanager->resPrint;
$sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
$sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
-$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number";
-$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
+$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'";
$sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
$sql.= " AND product_type <= 2";
-$sql.= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_buy IS NULL OR p.accountancy_code_buy =''OR p.accountancy_code_buy NOT IN
- (SELECT aa.account_number FROM " . MAIN_DB_PREFIX . "accounting_account as aa , " . MAIN_DB_PREFIX . "accounting_system as asy WHERE fk_pcg_version = asy.pcg_version AND asy.rowid ='" . $conf->global->CHARTOFACCOUNTS . "'))";
// Add search filter like
if ($search_lineid) {
$sql .= natural_search("l.rowid", $search_lineid, 1);
@@ -253,6 +261,11 @@ else if ($search_year > 0)
{
$sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
}
+if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+ $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_SITUATION . ")";
+} else {
+ $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_DEPOSIT . "," . FactureFournisseur::TYPE_SITUATION . ")";
+}
$sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
// Add where from hooks
@@ -325,9 +338,8 @@ if ($result) {
$moreforfilter = '';
- print '
';
-
- print '
'."\n";
+ print '';
+ print '
'."\n";
// We add search filter
print '';
@@ -446,7 +458,7 @@ if ($result) {
print '';
print '';
- print price($objp->price);
+ print price($objp->total_ht);
print ' ';
// Vat rate
@@ -471,12 +483,12 @@ if ($result) {
print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
print '';
- // Colonne choix ligne a ventiler
+ // Column with checkbox
print '';
print ' aarowid ? "checked" : "") . '/>';
print ' ';
- print " ";
+ print '';
$i ++;
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index b5b95a2e92d..e3d9ab1fde0 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -4400,6 +4400,7 @@ class FactureLigne extends CommonInvoiceLine
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);
$this->info_bits = $objp->info_bits;
+ $this->tva_npr = ($objp->info_bits & 1 == 1) ? 1 : 0;
$this->special_code = $objp->special_code;
$this->total_ht = $objp->total_ht;
$this->total_tva = $objp->total_tva;
diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php
index 4bad3c224f7..3db85f08fe0 100644
--- a/htdocs/core/db/mysqli.class.php
+++ b/htdocs/core/db/mysqli.class.php
@@ -109,12 +109,17 @@ class DoliDBMysqli extends DoliDB
$this->database_name = $name;
$this->ok = true;
- // If client connected with different charset than Dolibarr HTML output
- $clientmustbe='';
- if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8';
- if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1';
+ // If client is old latin, we force utf8
+ $clientmustbe=empty($conf->db->dolibarr_main_db_character_set)?'utf8':$conf->db->dolibarr_main_db_character_set;
+ if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
+
if ($this->db->character_set_name() != $clientmustbe) {
- $this->db->set_charset($clientmustbe);
+ $this->db->set_charset($clientmustbe); // This set charset, but with a bad collation
+
+ $collation = $conf->db->dolibarr_main_db_collation;
+ if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
+
+ if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
}
}
else
@@ -133,14 +138,19 @@ class DoliDBMysqli extends DoliDB
if ($this->connected)
{
- // If client connected with different charset than Dolibarr HTML output
- $clientmustbe='';
- if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8';
- if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1';
+ // If client is old latin, we force utf8
+ $clientmustbe=$conf->db->dolibarr_main_db_character_set;
+ if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
+
if ($this->db->character_set_name() != $clientmustbe) {
- $this->db->set_charset($clientmustbe);
+ $this->db->set_charset($clientmustbe); // This set utf8_general_ci
+
+ $collation = $conf->db->dolibarr_main_db_collation;
+ if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
+
+ if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
}
- }
+ }
}
}
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index a0db1fade81..a3ae4ba693a 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -2518,6 +2518,7 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->product_type = $obj->product_type;
$this->product_label = $obj->label;
$this->info_bits = $obj->info_bits;
+ $this->tva_npr = ($objp->info_bits & 1 == 1) ? 1 : 0;
$this->fk_parent_line = $obj->fk_parent_line;
$this->special_code = $obj->special_code;
$this->rang = $obj->rang;
diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index 650ebafe74c..d6460672e41 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -183,6 +183,16 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
print ''.$langs->trans("ServerVersion").' ';
print ''.$version.' ';
dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ServerVersion") . ": " .$version);
+ if ($db->type == 'mysqli')
+ {
+ $tmparray = $db->db->get_charset();
+ print ''.$langs->trans("ClientCharset").' ';
+ print ''.$tmparray->charset.' ';
+ dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ClientCharset") . ": " .$tmparray->charset);
+ print ''.$langs->trans("ClientSortingCharset").' ';
+ print ''.$tmparray->collation.' ';
+ dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ClientCollation") . ": " .$tmparray->collation);
+ }
// Test database version requirement
$versionmindb=explode('.',$db::VERSIONMIN);
diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang
index 26ea4f34711..6ffde31eef4 100644
--- a/htdocs/langs/en_US/accountancy.lang
+++ b/htdocs/langs/en_US/accountancy.lang
@@ -167,7 +167,7 @@ DeleteMvt=Delete Ledger lines
DelYear=Year to delete
DelJournal=Journal to delete
ConfirmDeleteMvt=This will delete all lines of the Ledger for year and/or from a specific journal. At least one criteria is required.
-ConfirmDeleteMvtPartial=This will delete the selected line(s) of the Ledger
+ConfirmDeleteMvtPartial=This will delete the transaction from the Ledger (all lines related to same transaction will be deleted)
DelBookKeeping=Delete record of the Ledger
FinanceJournal=Finance journal
ExpenseReportsJournal=Expense reports journal
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index fa138c15dea..63269cadc5d 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -40,6 +40,8 @@ WebUserGroup=Web server user/group
NoSessionFound=Your PHP seems to not allow to list active sessions. Directory used to save sessions (%s ) might be protected (For example, by OS permissions or by PHP directive open_basedir).
DBStoringCharset=Database charset to store data
DBSortingCharset=Database charset to sort data
+ClientCharset=Client charset
+ClientSortingCharset=Client collation
WarningModuleNotActive=Module %s must be enabled
WarningOnlyPermissionOfActivatedModules=Only permissions related to activated modules are shown here. You can activate other modules in the Home->Setup->Modules page.
DolibarrSetup=Dolibarr install or upgrade