diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index c8b0f297f26..a07fbd3a96d 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -132,6 +132,7 @@ if ($result) { $tablocaltax1 = array (); $tablocaltax2 = array (); $tabcompany = array (); + $tabother = array(); $num = $db->num_rows($result); @@ -158,6 +159,7 @@ if ($result) { $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); + $compta_counterpart_tva_npr = (! empty($conf->global->ACCOUNTING_COUNTERPART_VAT_NPR)) ? $conf->global->ACCOUNTING_COUNTERPART_VAT_NPR : 'NotDefined'; // Define array to display all VAT rates that use this accounting account $compta_tva if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) @@ -165,6 +167,9 @@ if ($result) { $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); } + $line = new SupplierInvoiceLine($db); + $line->fetch($obj->fdid); + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr); $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')'; @@ -185,6 +190,10 @@ if ($result) { $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc; $tabht[$obj->rowid][$compta_prod] += $obj->total_ht; $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; + if (! empty($line->tva_npr)) // Add an entry for counterpart + { + $tabother[$obj->rowid][$compta_counterpart_tva_npr] += $obj->total_tva; + } $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1; $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2; $tabcompany[$obj->rowid] = array ( @@ -192,9 +201,9 @@ if ($result) { 'name' => $obj->name, 'code_fournisseur' => $obj->code_fournisseur, 'code_compta_fournisseur' => $compta_soc - ); + ); - $i ++; + $i++; } } else { dol_print_error($db); @@ -388,6 +397,55 @@ if ($action == 'writebookkeeping') { } } + // Counterpart of VAT for VAT NPR + // var_dump($tabother); + if (! $errorforline) + { + foreach ( $tabother[$key] as $k => $mt ) { + if ($mt) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->date_lim_reglement = $val["datereg"]; + $bookkeeping->doc_ref = $val["refsologest"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'supplier_invoice'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add + $bookkeeping->thirdparty_code = $companystatic->code_fournisseur; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT").' NPR'; + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; + $bookkeeping->debit = ($mt > 0) ? $mt : 0; + $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + + $totaldebit += $bookkeeping->debit; + $totalcredit += $bookkeeping->credit; + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + if ($totaldebit != $totalcredit) { $error++; @@ -535,6 +593,25 @@ if ($action == 'exportcsv') { print "\n"; } } + + // VAT counterpart for NPR + foreach ( $tabother[$key] as $k => $mt ) { + if ($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 '"' . length_accounta(html_entity_decode($k)) . '"' . $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("VAT") . ' NPR"' . $sep; + print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; + print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep; + print '"' . $journal . '"' ; + print "\n"; + } + } } } } @@ -701,31 +778,59 @@ if (empty($action) || $action == 'view') { foreach ( $arrayofvat[$key] as $k => $mt ) { if ($mt) { - print ''; - print ""; - print "" . $date . ""; - print "" . $invoicestatic->getNomUrl(1) . ""; - // Account - print ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Purchase").')'.''; + print ''; + print ""; + print "" . $date . ""; + print "" . $invoicestatic->getNomUrl(1) . ""; + // Account + print ""; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Purchase").')'.''; + } + else print $accountoshow; + print ""; + // Subledger account + print ""; + print ''; + 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) : '') . ""; + print ""; } - else print $accountoshow; - print ""; - // Subledger account - print ""; - print ''; - 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) : '') . ""; - print ""; - } } } + + // VAT counterpart for NPR + foreach ( $tabother[$key] as $k => $mt ) { + print ''; + print ""; + print "" . $date . ""; + print "" . $invoicestatic->getNomUrl(1) . ""; + $companystatic->id = $tabcompany[$key]['id']; + $companystatic->name = $tabcompany[$key]['name']; + $companystatic->supplier_code = $tabcompany[$key]['code_supplier']; + // Account + print ""; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account'.''; + } + else print $accountoshow; + print ''; + // Subledger account + print ""; + print ''; + print "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT") . " NPR (counterpart)"; + print '' . ($mt < 0 ? - price(- $mt) : '') . ""; + print '' . ($mt >= 0 ? price($mt) : '') . ""; + print ""; + } + } print ""; diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 4f77c102788..ffa27ee8fda 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -161,9 +161,10 @@ if ($result) { $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); } - // Situation invoices handling $line = new FactureLigne($db); $line->fetch($obj->fdid); + + // Situation invoices handling $prev_progress = $line->get_prev_progress($obj->fdid); if ($obj->type == Facture::TYPE_SITUATION) { // Avoid divide by 0 diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index a3ae4ba693a..2af027e60e2 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -2518,7 +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->tva_npr = ($obj->info_bits & 1 == 1) ? 1 : 0; $this->fk_parent_line = $obj->fk_parent_line; $this->special_code = $obj->special_code; $this->rang = $obj->rang;