Fix dispatching replacement invoice into bookkeeping (not used by most

countries in europe)
This commit is contained in:
Laurent Destailleur 2018-01-09 19:12:08 +01:00
parent 9f79ad800b
commit 9b448459c9
3 changed files with 245 additions and 97 deletions

View File

@ -94,7 +94,7 @@ if (! GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end)
$idpays = $mysoc->country_id; $idpays = $mysoc->country_id;
$sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,f.ref_supplier, f.date_lim_reglement as dlf, "; $sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,f.ref_supplier, f.date_lim_reglement as dlf, f.close_code,";
$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tva as total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code,"; $sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tva as total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code,";
$sql .= " s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; $sql .= " s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
$sql .= " p.accountancy_code_buy , aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; $sql .= " p.accountancy_code_buy , aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
@ -180,9 +180,9 @@ if ($result) {
$tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')'; $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')';
$tabfac[$obj->rowid]["refsologest"] = $obj->ref; $tabfac[$obj->rowid]["refsologest"] = $obj->ref;
$tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier; $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier;
$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]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
//$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid; //$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid;
// Avoid warnings // Avoid warnings
@ -219,6 +219,9 @@ if ($action == 'writebookkeeping') {
$now = dol_now(); $now = dol_now();
$error = 0; $error = 0;
$companystatic = new Societe($db);
$invoicestatic = new FactureFournisseur($db);
foreach ($tabfac as $key => $val) { // Loop on each invoice foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0; $errorforline = 0;
@ -228,22 +231,37 @@ if ($action == 'writebookkeeping') {
$db->begin(); $db->begin();
$companystatic = new Societe($db);
$invoicestatic = new FactureFournisseur($db);
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
$companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
$companystatic->code_client = $tabcompany[$key]['code_client']; $companystatic->code_client = $tabcompany[$key]['code_client'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->client = $tabcompany[$key]['code_client']; $companystatic->fournisseur = 1;
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = (string) $val["refsologest"]; $invoicestatic->ref = (string) $val["refsologest"];
$invoicestatic->refsupplier = $val["refsuppliersologest"]; $invoicestatic->ref_supplier = $val["refsuppliersologest"];
$invoicestatic->type = $val["type"]; $invoicestatic->type = $val["type"];
$invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day');
// Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
$replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If not already into bookkeeping, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
continue;
}
// Thirdparty // Thirdparty
if (! $errorforline) if (! $errorforline)
@ -262,7 +280,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur']; $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur'];
$bookkeeping->subledger_label = ''; // TODO To complete $bookkeeping->subledger_label = ''; // TODO To complete
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
$bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("SubledgerAccount"); $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("SubledgerAccount");
$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;
@ -313,7 +331,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->subledger_account = ''; $bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = ''; $bookkeeping->subledger_label = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
$bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label; $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $accountingaccount->label;
$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;
@ -370,7 +388,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->subledger_account = ''; $bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = ''; $bookkeeping->subledger_label = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
$bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:''); $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:'');
$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;
@ -420,7 +438,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->subledger_account = ''; $bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = ''; $bookkeeping->subledger_label = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
$bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT").' NPR'; $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT").' NPR';
$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;
@ -523,65 +541,84 @@ if ($action == 'exportcsv') {
foreach ( $tabfac as $key => $val ) foreach ( $tabfac as $key => $val )
{ {
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
$companystatic->fournisseur = 1; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
$companystatic->code_client = $tabcompany[$key]['code_client'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->fournisseur = 1;
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = $val["refsologest"]; $invoicestatic->ref = $val["refsologest"];
$invoicestatic->ref_supplier = $val["refsuppliersologest"]; $invoicestatic->ref_supplier = $val["refsuppliersologest"];
$invoicestatic->type = $val["type"]; $invoicestatic->type = $val["type"];
$invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32); $invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32);
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day'); $date = dol_print_date($val["date"], 'day');
// Third party // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
foreach ( $tabttc[$key] as $k => $mt ) { $replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If not already into bookkeeping, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
continue;
}
// Third party
foreach ( $tabttc[$key] as $k => $mt ) {
print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep;
print '"' . $val["refsologest"] . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep;
print '"' . $journal . '"' ;
print "\n";
}
// Product / Service
foreach ( $tabht[$key] as $k => $mt ) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
if ($mt) {
print '"' . $key . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . $val["refsologest"] . '"' . $sep; print '"' . $val["refsologest"] . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '""' . $sep;
print '"' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep;
print '"' . $journal . '"' ; print '"' . $journal . '"' ;
print "\n"; print "\n";
} }
}
// Product / Service // VAT
foreach ( $tabht[$key] as $k => $mt ) { $listoftax = array(0, 1, 2);
$accountingaccount = new AccountingAccount($db); foreach ($listoftax as $numtax) {
$accountingaccount->fetch(null, $k, true); $arrayofvat = $tabtva;
if ($mt) { if ($numtax == 1) $arrayofvat = $tablocaltax1;
print '"' . $key . '"' . $sep; if ($numtax == 2) $arrayofvat = $tablocaltax2;
print '"' . $date . '"' . $sep;
print '"' . $val["refsologest"] . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
print '""' . $sep;
print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep;
print '"' . $journal . '"' ;
print "\n";
}
}
// VAT foreach ($arrayofvat[$key] as $k => $mt) {
$listoftax = array(0, 1, 2);
foreach ($listoftax as $numtax) {
$arrayofvat = $tabtva;
if ($numtax == 1) $arrayofvat = $tablocaltax1;
if ($numtax == 2) $arrayofvat = $tablocaltax2;
foreach ($arrayofvat[$key] as $k => $mt) {
if ($mt) { if ($mt) {
print '"' . $key . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
@ -600,21 +637,24 @@ if ($action == 'exportcsv') {
} }
// VAT counterpart for NPR // VAT counterpart for NPR
foreach ( $tabother[$key] as $k => $mt ) { if (is_array($tabother[$key]))
if ($mt) { {
print '"' . $key . '"' . $sep; foreach ( $tabother[$key] as $k => $mt ) {
print '"' . $date . '"' . $sep; if ($mt) {
print '"' . $val["refsologest"] . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . $val["refsologest"] . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . ' NPR"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . ' NPR"' . $sep;
print '"' . $journal . '"' ; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print "\n"; print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep;
print '"' . $journal . '"' ;
print "\n";
}
} }
} }
} }
@ -701,20 +741,54 @@ if (empty($action) || $action == 'view') {
foreach ( $tabfac as $key => $val ) foreach ( $tabfac as $key => $val )
{ {
$invoicestatic->id = $key;
$invoicestatic->type = $val["type"];
$invoicestatic->ref = $val["refsologest"];
$invoicestatic->ref_supplier = $val["refsuppliersologest"];
$invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32);
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
$companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
$companystatic->code_client = $tabcompany[$key]['code_client'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->fournisseur = 1; $companystatic->fournisseur = 1;
$invoicestatic->id = $key;
$invoicestatic->ref = $val["refsologest"];
$invoicestatic->ref_supplier = $val["refsuppliersologest"];
$invoicestatic->type = $val["type"];
$invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32);
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day'); $date = dol_print_date($val["date"], 'day');
// Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
$replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If no, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
print '<tr class="oddeven">';
print "<td><!-- Replaced invoice --></td>";
print "<td>" . $date . "</td>";
print "<td><strike>" . $invoicestatic->getNomUrl(1) . "</strike></td>";
// Account
print "<td>";
print $langs->trans("Replaced");
print '</td>';
// Subledger account
print "<td>";
print '</td>';
print "<td>";
print "</td>";
print '<td align="right"></td>';
print '<td align="right"></td>';
print "</tr>";
continue;
}
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print '<tr class="oddeven">'; print '<tr class="oddeven">';

View File

@ -89,7 +89,7 @@ if (! GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end)
$idpays = $mysoc->country_id; $idpays = $mysoc->country_id;
$sql = "SELECT f.rowid, f.facnumber, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr,"; $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,";
$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,"; $sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,";
$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
$sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; $sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
@ -190,6 +190,7 @@ 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]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
//$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid; //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
// Avoid warnings // Avoid warnings
@ -222,6 +223,9 @@ if ($action == 'writebookkeeping') {
$now = dol_now(); $now = dol_now();
$error = 0; $error = 0;
$companystatic = new Societe($db);
$invoicestatic = new Facture($db);
foreach ($tabfac as $key => $val) { // Loop on each invoice foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0; $errorforline = 0;
@ -231,18 +235,35 @@ if ($action == 'writebookkeeping') {
$db->begin(); $db->begin();
$companystatic = new Societe($db);
$invoicestatic = new Facture($db);
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
$companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
$companystatic->code_client = $tabcompany[$key]['code_client']; $companystatic->code_client = $tabcompany[$key]['code_client'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->client = 3;
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = (string) $val["ref"]; $invoicestatic->ref = (string) $val["ref"];
$invoicestatic->type = $val["type"];
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day');
// Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
$replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If not already into bookkeeping, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
continue;
}
// Thirdparty // Thirdparty
if (! $errorforline) if (! $errorforline)
@ -482,13 +503,31 @@ if ($action == 'exportcsv') {
$companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
$companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
$companystatic->code_client = $tabcompany[$key]['code_client']; $companystatic->code_client = $tabcompany[$key]['code_client'];
$companystatic->code_fournisseur = $tabcompany[$key]['code_supplier']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->client = 3;
$invoicestatic->id = $key; $invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"]; $invoicestatic->ref = (string) $val["ref"];
$invoicestatic->type = $val["type"];
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day'); $date = dol_print_date($val["date"], 'day');
// Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
$replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If not already into bookkeeping, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
continue;
}
// Third party // Third party
foreach ($tabttc[$key] as $k => $mt) { foreach ($tabttc[$key] as $k => $mt) {
print '"' . $key . '"' . $sep; print '"' . $key . '"' . $sep;
@ -631,15 +670,11 @@ if (empty($action) || $action == 'view') {
$r = ''; $r = '';
$invoicestatic = new Facture($db);
$companystatic = new Client($db); $companystatic = new Client($db);
$invoicestatic = new Facture($db);
foreach ( $tabfac as $key => $val ) foreach ( $tabfac as $key => $val )
{ {
$invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"];
$companystatic->id = $tabcompany[$key]['id']; $companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name']; $companystatic->name = $tabcompany[$key]['name'];
$companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta = $tabcompany[$key]['code_compta'];
@ -648,10 +683,47 @@ if (empty($action) || $action == 'view') {
$companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
$companystatic->client = 3; $companystatic->client = 3;
$invoicestatic->id = $key;
$invoicestatic->ref = (string) $val["ref"];
$invoicestatic->type = $val["type"];
$invoicestatic->close_code = $val["close_code"];
$date = dol_print_date($val["date"], 'day'); $date = dol_print_date($val["date"], 'day');
// Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
$replacedinvoice = 0;
if ($invoicestatic->close_code == 'replaced')
{
$replacedinvoice = 1;
$alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
if ($alreadydispatched) $replacedinvoice = 2;
}
// If not already into bookkeeping, we won't add it, if yes, we will also add the counterpart.
if ($replacedinvoice == 1)
{
print '<tr class="oddeven">';
print "<td><!-- Replaced invoice --></td>";
print "<td>" . $date . "</td>";
print "<td><strike>" . $invoicestatic->getNomUrl(1) . "</strike></td>";
// Account
print "<td>";
print $langs->trans("Replaced");
print '</td>';
// Subledger account
print "<td>";
print '</td>';
print "<td>";
print "</td>";
print '<td align="right"></td>';
print '<td align="right"></td>';
print "</tr>";
continue;
}
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ($tabttc[$key] as $k => $mt)
{
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print "<td><!-- Thirdparty --></td>"; print "<td><!-- Thirdparty --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
@ -681,7 +753,8 @@ if (empty($action) || $action == 'view') {
} }
// Product / Service // Product / Service
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);
@ -713,7 +786,8 @@ if (empty($action) || $action == 'view') {
// VAT // VAT
$listoftax = array(0, 1, 2); $listoftax = array(0, 1, 2);
foreach ($listoftax as $numtax) { foreach ($listoftax as $numtax)
{
$arrayofvat = $tabtva; $arrayofvat = $tabtva;
if ($numtax == 1) $arrayofvat = $tablocaltax1; if ($numtax == 1) $arrayofvat = $tablocaltax1;
if ($numtax == 2) $arrayofvat = $tablocaltax2; if ($numtax == 2) $arrayofvat = $tablocaltax2;

View File

@ -334,7 +334,7 @@ abstract class CommonInvoice extends CommonObject
} }
/** /**
* Return if an invoice was dispatched in bookkeeping * Return if an invoice was dispatched into bookkeeping
* *
* @return int <0 if KO, 0=no, 1=yes * @return int <0 if KO, 0=no, 1=yes
*/ */