FIX Several bugs in accounting module.
This commit is contained in:
parent
04b1535b12
commit
c9bfb6e945
@ -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)
|
||||||
{
|
{
|
||||||
@ -456,17 +501,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) {
|
report_header($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 +531,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%\">";
|
||||||
@ -498,7 +544,6 @@ if (empty($action) || $action == 'view') {
|
|||||||
print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
|
print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
$var = true;
|
|
||||||
$r = '';
|
$r = '';
|
||||||
|
|
||||||
$invoicestatic = new FactureFournisseur($db);
|
$invoicestatic = new FactureFournisseur($db);
|
||||||
@ -563,10 +608,10 @@ if (empty($action) || $action == 'view') {
|
|||||||
print "</tr>";
|
print "</tr>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print "<tr " . $bc[$var] . ">";
|
|
||||||
|
|
||||||
// Third party
|
// Third party
|
||||||
foreach ( $tabttc[$key] as $k => $mt ) {
|
foreach ( $tabttc[$key] as $k => $mt ) {
|
||||||
|
print "<tr " . $bc[$var] . ">";
|
||||||
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>";
|
||||||
@ -586,8 +631,8 @@ 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>";
|
||||||
|
}
|
||||||
|
|
||||||
$var = ! $var;
|
$var = ! $var;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
{
|
{
|
||||||
@ -458,6 +499,7 @@ if ($action == 'export_csv') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (empty($action) || $action == 'view') {
|
if (empty($action) || $action == 'view') {
|
||||||
|
|
||||||
llxHeader('', $langs->trans("SellsJournal"));
|
llxHeader('', $langs->trans("SellsJournal"));
|
||||||
@ -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) {
|
report_header($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%\">";
|
||||||
@ -553,8 +595,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 ) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user