FIX serious bugs in accounting (error management, transactions, bad

values set)
This commit is contained in:
Laurent Destailleur 2017-04-29 14:53:29 +02:00
parent 2e6d865c7d
commit faddcb28ac
11 changed files with 731 additions and 461 deletions

View File

@ -169,7 +169,15 @@ class BookKeeping extends CommonObject
if (empty($this->numero_compte) || $this->numero_compte == '-1') if (empty($this->numero_compte) || $this->numero_compte == '-1')
{ {
$langs->load("errors"); $langs->load("errors");
$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet); if (in_array($this->doc_type, array('bank', 'expense_report')))
{
$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
}
else
{
$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type);
}
return -1; return -1;
} }
@ -178,11 +186,12 @@ class BookKeeping extends CommonObject
$this->piece_num = 0; $this->piece_num = 0;
// first check if line not yet in bookkeeping // First check if line not yet already in bookkeeping
$sql = "SELECT count(*) as nb"; $sql = "SELECT count(*) as nb";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE doc_type = '" . $this->doc_type . "'"; $sql .= " WHERE doc_type = '" . $this->doc_type . "'";
$sql .= " AND fk_docdet = " . $this->fk_docdet; $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 numero_compte = '" . $this->numero_compte . "'"; $sql .= " AND numero_compte = '" . $this->numero_compte . "'";
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";

View File

@ -43,6 +43,7 @@ $langs->load("productbatch");
$account_parent = GETPOST('account_parent'); $account_parent = GETPOST('account_parent');
$changeaccount = GETPOST('changeaccount'); $changeaccount = GETPOST('changeaccount');
// Search Getpost // Search Getpost
$search_lineid = GETPOST('search_lineid', 'int');
$search_ref = GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('search_ref', 'alpha');
$search_invoice = GETPOST('search_invoice', 'alpha'); $search_invoice = GETPOST('search_invoice', 'alpha');
$search_label = GETPOST('search_label', 'alpha'); $search_label = GETPOST('search_label', 'alpha');
@ -86,6 +87,7 @@ $formventilation = new FormVentilation($db);
// Purge search criteria // Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
{ {
$search_lineid = '';
$search_ref = ''; $search_ref = '';
$search_invoice = ''; $search_invoice = '';
$search_label = ''; $search_label = '';
@ -151,7 +153,7 @@ print '<script type="text/javascript">
* Customer Invoice lines * Customer Invoice lines
*/ */
$sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.ref_client,"; $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.ref_client,";
$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc,"; $sql .= " fd.rowid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc,";
$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,"; $sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number, aa.label as label_compte,"; $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number, aa.label as label_compte,";
$sql .= " fd.situation_percent, co.label as country, s.tva_intra"; $sql .= " fd.situation_percent, co.label as country, s.tva_intra";
@ -169,6 +171,9 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
} else { } 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_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
} }
if ($search_lineid) {
$sql .= natural_search("fd.rowid", $search_lineid, 1);
}
if (strlen(trim($search_invoice))) { if (strlen(trim($search_invoice))) {
$sql .= natural_search("f.facnumber", $search_invoice); $sql .= natural_search("f.facnumber", $search_invoice);
} }
@ -257,7 +262,7 @@ if ($result) {
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
@ -328,13 +333,16 @@ if ($result) {
print '<td align="right">' . price($objp->total_ht) . '</td>'; print '<td align="right">' . price($objp->total_ht) . '</td>';
print '<td align="center">' . price($objp->tva_tx) . '</td>'; print '<td align="center">' . price($objp->tva_tx) . '</td>';
print '<td>'; print '<td>';
print $codecompta . ' <a href="./card.php?id=' . $objp->fdid . '">'; print $codecompta . ' <a href="./card.php?id=' . $objp->rowid . '">';
print img_edit(); print img_edit();
print '</a>'; print '</a>';
print '</td>'; print '</td>';
print '<td>' . $objp->country .'</td>'; print '<td>' . $objp->country .'</td>';
print '<td>' . $objp->tva_intra . '</td>'; print '<td>' . $objp->tva_intra . '</td>';
print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->fdid . '"/></td>';
print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
print "</tr>"; print "</tr>";
$i ++; $i ++;

View File

@ -52,6 +52,7 @@ $toselect = GETPOST('toselect', 'array');
$mesCasesCochees = GETPOST('toselect', 'array'); $mesCasesCochees = GETPOST('toselect', 'array');
// Search Getpost // Search Getpost
$search_lineid = GETPOST('search_lineid', 'int');
$search_invoice = GETPOST('search_invoice', 'alpha'); $search_invoice = GETPOST('search_invoice', 'alpha');
$search_ref = GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('search_ref', 'alpha');
$search_label = GETPOST('search_label', 'alpha'); $search_label = GETPOST('search_label', 'alpha');
@ -100,6 +101,7 @@ if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction !=
// Purge search criteria // Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
{ {
$search_lineid = '';
$search_ref = ''; $search_ref = '';
$search_invoice = ''; $search_invoice = '';
$search_label = ''; $search_label = '';
@ -177,7 +179,7 @@ llxHeader('', $langs->trans("Ventilation"));
// Customer Invoice lines // Customer Invoice lines
$sql = "SELECT f.facnumber, f.rowid as facid, f.datef, f.type as ftype,"; $sql = "SELECT f.facnumber, f.rowid as facid, f.datef, f.type as ftype,";
$sql .= " l.fk_product, l.description, l.total_ht, l.rowid, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line,"; $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,";
$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 .= " 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 .= " aa.rowid as aarowid";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
@ -189,6 +191,9 @@ $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
$sql .= " AND product_type <= 2"; $sql .= " AND product_type <= 2";
$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')"; $sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')";
// Add search filter like // Add search filter like
if ($search_lineid) {
$sql .= natural_search("l.rowid", $search_lineid, 1);
}
if (strlen(trim($search_invoice))) { if (strlen(trim($search_invoice))) {
$sql .= natural_search("f.facnumber",$search_invoice); $sql .= natural_search("f.facnumber",$search_invoice);
} }
@ -274,7 +279,7 @@ if ($result) {
// We add search filter // We add search filter
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';

View File

@ -106,7 +106,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
$idpays = $p[0]; $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,"; $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,";
$sql .= " ba.courant, ba.ref as baref, ba.account_number,"; $sql .= " ba.courant, ba.ref as baref, ba.account_number,";
$sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,"; $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,";
$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as name, u.firstname as firstname, bu2.type as typeop"; $sql .= " u.accountancy_code, u.rowid as userid, u.lastname as name, u.firstname as firstname, bu2.type as typeop";
@ -341,6 +341,7 @@ if (! $error && $action == 'writebookkeeping') {
// Line into bank account // Line into bank account
foreach ( $tabbq[$key] as $k => $mt ) foreach ( $tabbq[$key] as $k => $mt )
{ {
if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
@ -417,12 +418,14 @@ if (! $error && $action == 'writebookkeeping') {
} }
} }
} }
}
// Third party // Third party
if (! $errorforline) if (! $errorforline)
{ {
// Line into thirdparty account // Line into thirdparty account
foreach ( $tabtp[$key] as $k => $mt ) { foreach ( $tabtp[$key] as $k => $mt ) {
if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
@ -479,12 +482,22 @@ if (! $error && $action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
} }
}
}
if (! $errorforline) if (! $errorforline)
{ {
@ -512,6 +525,7 @@ if (! $error && $action == 'writebookkeeping') {
} }
// Export // Export
/*
if ($action == 'export_csv') { if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
@ -678,7 +692,7 @@ if ($action == 'export_csv') {
} }
} }
} }
*/
@ -702,17 +716,18 @@ if (empty($action) || $action == 'view') {
$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);
$varlink = 'id_account=' . $id_bank_account; $varlink = 'id_account=' . $id_bank_account;
report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
'action' => ''
), '', $varlink);
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans('Export') . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>'; print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans('Export') . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
} else { } else {
print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />'; print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
} }*/
print '<div class="tabsAction">';
print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print '</div>';
// TODO Avoid using js. We can use a direct link with $param // TODO Avoid using js. We can use a direct link with $param
print ' print '

View File

@ -157,7 +157,12 @@ if ($action == 'writebookkeeping') {
{ {
$errorforline = 0; $errorforline = 0;
$db->begin();
if (! $errorforline)
{
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
if ($mt) {
// get compte id and label // get compte id and label
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
@ -179,12 +184,25 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
}
}
}
if (! $errorforline)
{
// Fees // Fees
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
@ -212,6 +230,14 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
@ -219,7 +245,11 @@ if ($action == 'writebookkeeping') {
} }
} }
} }
}
}
if (! $errorforline)
{
// VAT // VAT
// var_dump($tabtva); // var_dump($tabtva);
foreach ( $tabtva[$key] as $k => $mt ) { foreach ( $tabtva[$key] as $k => $mt ) {
@ -244,9 +274,19 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($object->error, $object->errors, 'errors'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
} }
} }
} }
@ -286,7 +326,7 @@ $form = new Form($db);
$userstatic = new User($db); $userstatic = new User($db);
// Export // Export
if ($action == 'export_csv') { /*if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL; $journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL;
@ -393,6 +433,7 @@ if ($action == 'export_csv') {
} }
} }
} }
*/
if (empty($action) || $action == 'view') { if (empty($action) || $action == 'view') {
@ -406,17 +447,18 @@ if (empty($action) || $action == 'view') {
$description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>'; $description.= $langs->trans("DescJournalOnlyBindedVisible").'<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($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
'action' => ''
));
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>'; print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
} else { } else {
print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />'; print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
} }*/
print '<div class="tabsAction">';
print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print '</div>';
print ' print '
<script type="text/javascript"> <script type="text/javascript">
@ -511,10 +553,10 @@ if (empty($action) || $action == 'view') {
print "</tr>"; print "</tr>";
} }
} }
print '<tr class="oddeven">';
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print '<tr class="oddeven">';
print "<td><!-- Thirdparty --></td>"; print "<td><!-- Thirdparty --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>"; print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
@ -531,9 +573,9 @@ if (empty($action) || $action == 'view') {
print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("Code_tiers") . "</td>"; print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("Code_tiers") . "</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>"; print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
}
print "</tr>"; print "</tr>";
} }
}
print "</table>"; print "</table>";

View File

@ -109,6 +109,7 @@ dol_syslog('accountancy/journal/purchasesjournal.php:: $sql=' . $sql);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
// les variables // les variables
$cptfour = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER)) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"); $cptfour = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER)) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef");
$cpttva = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef"); $cpttva = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef");
@ -123,8 +124,10 @@ if ($result) {
$i = 0; $i = 0;
while ( $i < $num ) { while ( $i < $num ) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
// contrôles // contrôles
$compta_soc = (! empty($obj->code_compta_fournisseur)) ? $obj->code_compta_fournisseur : $cptfour; $compta_soc = (! empty($obj->code_compta_fournisseur)) ? $obj->code_compta_fournisseur : $cptfour;
$compta_prod = $obj->compte; $compta_prod = $obj->compte;
if (empty($compta_prod)) { if (empty($compta_prod)) {
if ($obj->product_type == 0) if ($obj->product_type == 0)
@ -144,14 +147,21 @@ if ($result) {
$tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["type"] = $obj->type;
$tabfac[$obj->rowid]["description"] = $obj->description; $tabfac[$obj->rowid]["description"] = $obj->description;
$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid; //$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid;
// Avoid warnings
if (! isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0;
if (! isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0;
if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
$tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc; $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
$tabht[$obj->rowid][$compta_prod] += $obj->total_ht; $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
$tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
$tabcompany[$obj->rowid] = array ( $tabcompany[$obj->rowid] = array (
'id' => $obj->socid, 'id' => $obj->socid,
'name' => $obj->name, 'name' => $obj->name,
'code_fournisseur' => $obj->code_compta_fournisseur 'code_fournisseur' => $obj->code_fournisseur,
'code_compta_fournisseur' => $compta_soc
); );
$i ++; $i ++;
@ -165,7 +175,7 @@ if ($action == 'writebookkeeping') {
$now = dol_now(); $now = dol_now();
$error = 0; $error = 0;
foreach ($tabfac as $key => $val) foreach ($tabfac as $key => $val) // Loop on each invoice
{ {
$errorforline = 0; $errorforline = 0;
@ -188,19 +198,21 @@ if ($action == 'writebookkeeping') {
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->client = $tabcompany[$key]['code_client']; $companystatic->client = $tabcompany[$key]['code_client'];
if (! $errorforline)
{
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
// get compte id and label // get compte id and label
if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->doc_type = 'supplier_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur']; $bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur'];
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers");
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; $bookkeeping->numero_compte = $tabcompany[$key]['code_compta_fournisseur'];
$bookkeeping->montant = $mt; $bookkeeping->montant = $mt;
$bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
$bookkeeping->debit = ($mt <= 0) ? $mt : 0; $bookkeeping->debit = ($mt <= 0) ? $mt : 0;
@ -210,13 +222,26 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
}
}
}
// Product / Service // Product / Service
if (! $errorforline)
{
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true); $accountingaccount->fetch(null, $k, true);
@ -230,7 +255,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->doc_type = 'supplier_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->code_tiers = ''; $bookkeeping->code_tiers = '';
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label; $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label;
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
@ -243,6 +268,14 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
@ -250,9 +283,13 @@ if ($action == 'writebookkeeping') {
} }
} }
} }
}
}
// VAT // VAT
// var_dump($tabtva); // var_dump($tabtva);
if (! $errorforline)
{
foreach ( $tabtva[$key] as $k => $mt ) { foreach ( $tabtva[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
// get compte id and label // get compte id and label
@ -262,7 +299,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->doc_type = 'supplier_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->code_tiers = ''; $bookkeeping->code_tiers = '';
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]; $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key];
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
@ -275,14 +312,22 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($object->error, $object->errors, 'errors'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
} }
} }
} }
if (! $errorforline) if (! $errorforline)
{ {
@ -319,7 +364,7 @@ $form = new Form($db);
$companystatic = new Fournisseur($db); $companystatic = new Fournisseur($db);
// Export // Export
if ($action == 'export_csv') { /*if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; $journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
@ -437,6 +482,7 @@ if ($action == 'export_csv') {
} }
} }
} }
*/
if (empty($action) || $action == 'view') { if (empty($action) || $action == 'view') {
@ -456,17 +502,18 @@ if (empty($action) || $action == 'view') {
} }
$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($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
'action' => ''
));
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>'; print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
} else { } else {
print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />'; print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
} }*/
print '<div class="tabsAction">';
print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print '</div>';
print ' print '
<script type="text/javascript"> <script type="text/javascript">
@ -485,7 +532,7 @@ if (empty($action) || $action == 'view') {
/* /*
* Show result array * Show result array
*/ */
print '<br><br>'; print '<br>';
$i = 0; $i = 0;
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
@ -562,10 +609,10 @@ if (empty($action) || $action == 'view') {
print "</tr>"; print "</tr>";
} }
} }
print '<tr class="oddeven">';
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print '<tr class="oddeven">';
print "<td><!-- Thirdparty --></td>"; print "<td><!-- Thirdparty --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
@ -585,9 +632,9 @@ if (empty($action) || $action == 'view') {
// print "</td>"; // print "</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>"; print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
}
print "</tr>"; print "</tr>";
} }
}
print "</table>"; print "</table>";

View File

@ -100,7 +100,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
$sql .= " WHERE fd.fk_code_ventilation > 0"; $sql .= " WHERE fd.fk_code_ventilation > 0";
$sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy $sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy
$sql .= " AND f.fk_statut > 0"; $sql .= " AND f.fk_statut > 0"; // TODO Facture annulée ?
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { 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 . ")"; $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
} else { } else {
@ -124,10 +124,12 @@ if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
$cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef");
while ( $i < $num ) { while ( $i < $num ) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
// les variables // les variables
$cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef");
$compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli; $compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
$compta_prod = $obj->compte; $compta_prod = $obj->compte;
@ -164,20 +166,21 @@ if ($result) {
$tabfac[$obj->rowid]["ref"] = $obj->facnumber; $tabfac[$obj->rowid]["ref"] = $obj->facnumber;
$tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["type"] = $obj->type;
$tabfac[$obj->rowid]["description"] = $obj->label_compte; $tabfac[$obj->rowid]["description"] = $obj->label_compte;
$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid; //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
if (! isset($tabttc[$obj->rowid][$compta_soc]))
$tabttc[$obj->rowid][$compta_soc] = 0; // Avoid warnings
if (! isset($tabht[$obj->rowid][$compta_prod])) if (! isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0;
$tabht[$obj->rowid][$compta_prod] = 0; if (! isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0;
if (! isset($tabtva[$obj->rowid][$compta_tva])) if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
$tabtva[$obj->rowid][$compta_tva] = 0;
$tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio; $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
$tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio; $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
$tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
$tabcompany[$obj->rowid] = array ( $tabcompany[$obj->rowid] = array (
'id' => $obj->socid, 'id' => $obj->socid,
'name' => $obj->name, 'name' => $obj->name,
'code_client' => $obj->code_compta 'code_client' => $obj->code_client,
'code_compta' => $compta_soc
); );
$i ++; $i ++;
@ -191,7 +194,7 @@ if ($action == 'writebookkeeping') {
$now = dol_now(); $now = dol_now();
$error = 0; $error = 0;
foreach ( $tabfac as $key => $val ) { foreach ( $tabfac as $key => $val ) { // Loop on each invoice
$errorforline = 0; $errorforline = 0;
@ -211,16 +214,20 @@ if ($action == 'writebookkeeping') {
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = (string) $val["ref"]; $invoicestatic->ref = (string) $val["ref"];
// Thirdparty
if (! $errorforline)
{
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"]; $bookkeeping->doc_ref = $val["ref"];
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'customer_invoice'; $bookkeeping->doc_type = 'customer_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->code_tiers = $tabcompany[$key]['code_client']; $bookkeeping->code_tiers = $tabcompany[$key]['code_client'];
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; $bookkeeping->numero_compte = $tabcompany[$key]['code_compta'];
// $bookkeeping->label_compte = $tabcompany[$key]['name']; // $bookkeeping->label_compte = $tabcompany[$key]['name'];
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers");
$bookkeeping->montant = $mt; $bookkeeping->montant = $mt;
@ -232,13 +239,26 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
}
}
}
// Product / Service // Product / Service
if (! $errorforline)
{
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
// get compte id and label // get compte id and label
@ -250,7 +270,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'customer_invoice'; $bookkeeping->doc_type = 'customer_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add;
$bookkeeping->code_tiers = ''; $bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label; $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label;
@ -263,6 +283,14 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++;
$errorforline++;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
@ -270,9 +298,13 @@ if ($action == 'writebookkeeping') {
} }
} }
} }
}
}
// VAT // VAT
// var_dump($tabtva); // var_dump($tabtva);
if (! $errorforline)
{
foreach ( $tabtva[$key] as $k => $mt ) { foreach ( $tabtva[$key] as $k => $mt ) {
if ($mt) { if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
@ -281,7 +313,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->doc_type = 'customer_invoice'; $bookkeeping->doc_type = 'customer_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->code_tiers = ''; $bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key];
@ -294,13 +326,22 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user); $result = $bookkeeping->create($user);
if ($result < 0) { if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
{
$error++; $error++;
$errorforline++; $errorforline++;
setEventMessages($object->error, $object->errors, 'errors'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
}
else
{
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
} }
} }
} }
if (! $errorforline) if (! $errorforline)
{ {
@ -337,7 +378,7 @@ if ($action == 'writebookkeeping') {
$form = new Form($db); $form = new Form($db);
// Export // Export
if ($action == 'export_csv') { /*if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
@ -457,6 +498,7 @@ if ($action == 'export_csv') {
} }
} }
} }
*/
if (empty($action) || $action == 'view') { if (empty($action) || $action == 'view') {
@ -474,17 +516,17 @@ if (empty($action) || $action == 'view') {
else else
$description .= $langs->trans("DepositsAreIncluded"); $description .= $langs->trans("DepositsAreIncluded");
$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($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
'action' => ''
));
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>'; print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
} else { } else {
print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />'; print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
} }*/
print '<div class="tabsAction">';
print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print '</div>';
print ' print '
<script type="text/javascript"> <script type="text/javascript">
@ -503,7 +545,7 @@ if (empty($action) || $action == 'view') {
/* /*
* Show result array * Show result array
*/ */
print '<br><br>'; print '<br>';
$i = 0; $i = 0;
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
@ -552,8 +594,8 @@ if (empty($action) || $action == 'view') {
print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . "</td>"; print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . "</td>";
print "</td><td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>"; print "</td><td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>"; print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
}
print "</tr>"; print "</tr>";
}
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {

View File

@ -44,6 +44,7 @@ $langs->load("productbatch");
$account_parent = GETPOST('account_parent'); $account_parent = GETPOST('account_parent');
$changeaccount = GETPOST('changeaccount'); $changeaccount = GETPOST('changeaccount');
// Search Getpost // Search Getpost
$search_lineid = GETPOST('search_lineid', 'int');
$search_ref = GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('search_ref', 'alpha');
$search_invoice = GETPOST('search_invoice', 'alpha'); $search_invoice = GETPOST('search_invoice', 'alpha');
$search_label = GETPOST('search_label', 'alpha'); $search_label = GETPOST('search_label', 'alpha');
@ -85,6 +86,7 @@ $formventilation = new FormVentilation($db);
// Purge search criteria // Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
{ {
$search_lineid = '';
$search_ref = ''; $search_ref = '';
$search_invoice = ''; $search_invoice = '';
$search_label = ''; $search_label = '';
@ -148,7 +150,7 @@ print '<script type="text/javascript">
* Supplier Invoice lines * Supplier Invoice lines
*/ */
$sql = "SELECT f.rowid as facid, f.ref as facnumber, f.ref_supplier, f.libelle as invoice_label, f.datef,"; $sql = "SELECT f.rowid as facid, f.ref as facnumber, f.ref_supplier, f.libelle as invoice_label, f.datef,";
$sql.= " l.fk_product, l.description, l.total_ht , l.qty, l.rowid, l.tva_tx, aa.label, aa.account_number, "; $sql.= " l.rowid, l.fk_product, l.description, l.total_ht , l.qty, l.tva_tx, aa.label, aa.account_number, ";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type"; $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type";
$sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
$sql.= " , " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql.= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
@ -156,6 +158,9 @@ $sql.= " , " . MAIN_DB_PREFIX . "facture_fourn_det as l";
$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
$sql.= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 "; $sql.= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
$sql.= " AND aa.rowid = l.fk_code_ventilation"; $sql.= " AND aa.rowid = l.fk_code_ventilation";
if ($search_lineid) {
$sql .= natural_search("l.rowid", $search_lineid, 1);
}
if (strlen(trim($search_invoice))) { if (strlen(trim($search_invoice))) {
$sql .= natural_search("f.ref", $search_invoice); $sql .= natural_search("f.ref", $search_invoice);
} }
@ -240,7 +245,7 @@ if ($result) {
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';

View File

@ -52,6 +52,7 @@ $toselect = GETPOST('toselect', 'array');
$mesCasesCochees = GETPOST('toselect', 'array'); $mesCasesCochees = GETPOST('toselect', 'array');
// Search Getpost // Search Getpost
$search_lineid = GETPOST('search_lineid', 'int');
$search_invoice = GETPOST('search_invoice', 'alpha'); $search_invoice = GETPOST('search_invoice', 'alpha');
$search_ref = GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('search_ref', 'alpha');
$search_label = GETPOST('search_label', 'alpha'); $search_label = GETPOST('search_label', 'alpha');
@ -101,6 +102,7 @@ if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction !=
// Purge search criteria // Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
{ {
$search_lineid = '';
$search_ref = ''; $search_ref = '';
$search_invoice = ''; $search_invoice = '';
$search_label = ''; $search_label = '';
@ -179,7 +181,7 @@ llxHeader('', $langs->trans("SuppliersVentilation"));
// Supplier Invoice Lines // Supplier Invoice Lines
$sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef,"; $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef,";
$sql.= " l.fk_product, l.description, l.total_ht as price, l.rowid, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, "; $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, ";
$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.= " 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"; $sql.= " aa.rowid as aarowid";
$sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
@ -191,6 +193,9 @@ $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
$sql.= " AND product_type <= 2"; $sql.= " AND product_type <= 2";
$sql.= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_buy IS NULL OR p.accountancy_code_buy ='')"; $sql.= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_buy IS NULL OR p.accountancy_code_buy ='')";
// Add search filter like // Add search filter like
if ($search_lineid) {
$sql .= natural_search("l.rowid", $search_lineid, 1);
}
if (strlen(trim($search_invoice))) { if (strlen(trim($search_invoice))) {
$sql .= natural_search("f.ref",$search_invoice); $sql .= natural_search("f.ref",$search_invoice);
} }
@ -272,7 +277,7 @@ if ($result) {
// We add search filter // We add search filter
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>'; print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';

View File

@ -202,3 +202,95 @@ function length_accounta($accounta)
return $accounta; return $accounta;
} }
} }
/**
* Show header of a VAT report
*
* @param string $nom Name of report
* @param string $variante Link for alternate report
* @param string $period Period of report
* @param string $periodlink Link to switch period
* @param string $description Description
* @param timestamp|integer $builddate Date generation
* @param string $exportlink Link for export or ''
* @param array $moreparam Array with list of params to add into form
* @param string $calcmode Calculation mode
* @param string $varlink Add a variable into the address of the page
* @return void
*/
function journalHead($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='')
{
global $langs;
if (empty($hselected)) $hselected='report';
print "\n\n<!-- debut cartouche journal -->\n";
if(! empty($varlink)) $varlink = '?'.$varlink;
$h=0;
$head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
$head[$h][1] = $langs->trans("Journal");
$head[$h][2] = 'journal';
dol_fiche_head($head, 'journal');
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">';
foreach($moreparam as $key => $value)
{
print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
}
print '<table width="100%" class="border">';
// Ligne de titre
print '<tr>';
print '<td width="110">'.$langs->trans("Name").'</td>';
if (! $variantexxx) print '<td colspan="3">';
else print '<td>';
print $nom;
if ($variantexxx) print '</td><td colspan="2">'.$variantexxx;
print '</td>';
print '</tr>';
// Calculation mode
if ($calcmode)
{
print '<tr>';
print '<td width="110">'.$langs->trans("CalculationMode").'</td>';
if (! $variante) print '<td colspan="3">';
else print '<td>';
print $calcmode;
if ($variante) print '</td><td colspan="2">'.$variante;
print '</td>';
print '</tr>';
}
// Ligne de la periode d'analyse du rapport
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>';
// Ligne de description
print '<tr>';
print '<td>'.$langs->trans("ReportDescription").'</td>';
print '<td colspan="3">'.$description.'</td>';
print '</tr>';
print '</table>';
print '<br><div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
print '</form>';
dol_fiche_end();
print "\n<!-- fin cartouche journal -->\n\n";
}

View File

@ -3328,7 +3328,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
$return.= "\n"; $return.= "\n";
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>'; $return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'id="pictotitle"', $pictoisfullpath).'</td>'; if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle" id="pictotitle"', $pictoisfullpath).'</td>';
$return.= '<td class="nobordernopadding" valign="middle">'; $return.= '<td class="nobordernopadding" valign="middle">';
$return.= '<div class="titre">'.$titre.'</div>'; $return.= '<div class="titre">'.$titre.'</div>';
$return.= '</td>'; $return.= '</td>';