FIX accounting transfer when nb of lines is not zero but amount is zero

This commit is contained in:
Laurent Destailleur 2024-09-24 11:43:31 +02:00
parent ceee0a9885
commit 7ff3d7356d
5 changed files with 72 additions and 71 deletions

View file

@ -101,13 +101,14 @@ $formaccounting = new FormAccounting($db);
if (!empty($id)) {
$sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
$sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
$sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.fk_code_ventilation,";
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,";
if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
$sql .= " ppe.accountancy_code_sell as code_sell,";
} else {
$sql .= " p.accountancy_code_sell as code_sell,";
}
$sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
$sql .= " aa.account_number, aa.label";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
@ -139,18 +140,23 @@ if (!empty($id)) {
print '<table class="border centpercent">';
// Ref facture
// Ref invoice
print '<tr><td>'.$langs->trans("Invoice").'</td>';
$facture_static->ref = $objp->ref;
$facture_static->id = $objp->facid;
print '<td>'.$facture_static->getNomUrl(1).'</td>';
print '</tr>';
print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
print '<td>'.nl2br($objp->description).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
print '<tr><td>'.$langs->trans("Description").'</td>';
print '<td>'.dolPrintHTML($objp->description).'</td></tr>';
print '<tr><td>'.$langs->trans("ProductLabel").'</td>';
print '<td>'.dol_trunc($objp->product_label, 24).'</td></tr>';
print '<tr><td>'.$langs->trans("Account").'</td><td>';
print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
print '</td></tr>';
print '</table>';
print dol_get_fiche_end();

View file

@ -17,7 +17,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
@ -40,17 +39,6 @@ $langs->loadLangs(array("compta", "bills", "other", "accountancy"));
$validatemonth = GETPOSTINT('validatemonth');
$validateyear = GETPOSTINT('validateyear');
// Security check
if (!isModEnabled('accounting')) {
accessforbidden();
}
if ($user->socid > 0) {
accessforbidden();
}
if (!$user->hasRight('accounting', 'bind', 'write')) {
accessforbidden();
}
$accountingAccount = new AccountingAccount($db);
$month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
@ -84,7 +72,7 @@ if (!isModEnabled('accounting')) {
if ($user->socid > 0) {
accessforbidden();
}
if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
if (!$user->hasRight('accounting', 'bind', 'write')) {
accessforbidden();
}
@ -259,7 +247,7 @@ if ($action == 'validatehistory' && $user->hasRight('accounting', 'bind', 'write
}
if ($suggestedid > 0) {
$sqlupdate = "UPDATE ".MAIN_DB_PREFIX."facturedet";
$sqlupdate = "UPDATE ".$db->prefix()."facturedet";
$sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid);
$sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
@ -320,7 +308,7 @@ if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
$y = $year_current;
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
@ -362,8 +350,9 @@ for ($i = 1; $i <= 12; $i++) {
$j -= 12;
}
$sql .= " SUM(".$db->ifsql("MONTH(f.datef) = ".((string) $j), "fd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
$sql .= " SUM(".$db->ifsql("MONTH(f.datef) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
}
$sql .= " SUM(fd.total_ht) as total";
$sql .= " SUM(fd.total_ht) as total, COUNT(fd.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
@ -420,6 +409,7 @@ if ($resql) {
print $row[1];
}
print '</td>';
for ($i = 2; $i <= 13; $i++) {
$cursormonth = (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
if ($cursormonth > 12) {
@ -428,17 +418,19 @@ if ($resql) {
$cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
$tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
print '<td class="right nowraponall amount">';
print price($row[$i]);
print '<td class="right nowraponall amount" title="'.price($row[2*$i - 2]).' - '.$row[2*$i - 1].' lines">';
print price($row[2*$i - 2]);
// Add link to make binding
if (!empty(price2num($row[$i]))) {
if (!empty(price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
print '</a>';
}
print '</td>';
}
print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
print '</tr>';
}
$db->free($resql);
@ -584,7 +576,7 @@ if (getDolGlobalString('SHOW_TOTAL_OF_PREVIOUS_LISTS_IN_LIN_PAGE')) { // This pa
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td lass="left">'.$langs->trans("TotalVente").'</td>';
print '<tr class="liste_titre"><td class="left">'.$langs->trans("TotalVente").'</td>';
for ($i = 1; $i <= 12; $i++) {
$j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
if ($j > 12) {

View file

@ -77,17 +77,17 @@ if (!$user->hasRight('accounting', 'bind', 'write')) {
*/
if (($action == 'clean' || $action == 'validatehistory') && $user->hasRight('accounting', 'bind', 'write')) {
// Clean database
// Clean database by removing binding done on non existing or no more existing accounts
$db->begin();
$sql1 = "UPDATE ".MAIN_DB_PREFIX."expensereport_det as erd";
$sql1 = "UPDATE ".$db->prefix()."expensereport_det as erd";
$sql1 .= " SET fk_code_ventilation = 0";
$sql1 .= ' WHERE erd.fk_code_ventilation NOT IN';
$sql1 .= ' (SELECT accnt.rowid ';
$sql1 .= ' FROM '.MAIN_DB_PREFIX.'accounting_account as accnt';
$sql1 .= ' INNER JOIN '.MAIN_DB_PREFIX.'accounting_system as syst';
$sql1 .= ' FROM '.$db->prefix().'accounting_account as accnt';
$sql1 .= ' INNER JOIN '.$db->prefix().'accounting_system as syst';
$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.((int) getDolGlobalInt('CHARTOFACCOUNTS')).' AND accnt.entity = '.((int) $conf->entity).')';
$sql1 .= ' AND erd.fk_expensereport IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'expensereport WHERE entity = '.((int) $conf->entity).')';
$sql1 .= ' AND fk_code_ventilation <> 0';
$sql1 .= ' AND erd.fk_expensereport IN (SELECT rowid FROM '.$db->prefix().'expensereport WHERE entity = '.((int) $conf->entity).')';
$sql1 .= " AND fk_code_ventilation <> 0";
dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
$resql1 = $db->query($sql1);
if (!$resql1) {
@ -194,7 +194,7 @@ print '</span><br>';
$y = $year_current;
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
@ -238,8 +238,9 @@ for ($i = 1; $i <= 12; $i++) {
$j -= 12;
}
$sql .= " SUM(".$db->ifsql("MONTH(er.date_debut) = ".((int) $j), "erd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
$sql .= " SUM(".$db->ifsql("MONTH(er.date_debut) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
}
$sql .= " SUM(erd.total_ht) as total";
$sql .= " SUM(erd.total_ht) as total, COUNT(erd.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
@ -294,17 +295,17 @@ if ($resql) {
$cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
$tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
print '<td class="right nowraponall amount">';
print price($row[$i]);
print '<td class="right nowraponall amount" title="'.price($row[2*$i - 2]).' - '.$row[2*$i - 1].' lines">';
print price($row[2*$i - 2]);
// Add link to make binding
if (!empty(price2num($row[$i]))) {
if (!empty(price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
print '</a>';
}
print '</td>';
}
print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
print '</tr>';
}
$db->free($resql);
@ -371,14 +372,12 @@ if ($resql) {
while ($row = $db->fetch_row($resql)) {
print '<tr class="oddeven">';
print '<td>';
print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
if ($row[0] == 'tobind') {
//print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
} else {
print length_accountg($row[0]).' - ';
}
//print '</td>';
//print '<td>';
if ($row[0] == 'tobind') {
print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/expensereport/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
} else {

View file

@ -141,20 +141,23 @@ if (!empty($id)) {
print '<table class="border centpercent">';
// ref invoice
// Ref invoice
print '<tr><td>'.$langs->trans("BillsSuppliers").'</td>';
$facturefournisseur_static->ref = $objp->ref;
$facturefournisseur_static->id = $objp->facid;
print '<td>'.$facturefournisseur_static->getNomUrl(1).'</td>';
print '</tr>';
print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
print '<td>'.stripslashes(nl2br($objp->description)).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("ProductLabel").'</td>';
print '<td>'.dol_trunc($objp->product_label, 24).'</td>';
print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
print '<tr><td>'.$langs->trans("Description").'</td>';
print '<td>'.dolPrintHTML($objp->description).'</td></tr>';
print '<tr><td>'.$langs->trans("ProductLabel").'</td>';
print '<td>'.dol_trunc($objp->product_label, 24).'</td></tr>';
print '<tr><td>'.$langs->trans("Account").'</td><td>';
print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
print '</td></tr>';
print '</table>';
print dol_get_fiche_end();

View file

@ -81,7 +81,7 @@ if (!$user->hasRight('accounting', 'bind', 'write')) {
*/
if (($action == 'clean' || $action == 'validatehistory') && $user->hasRight('accounting', 'bind', 'write')) {
// Clean database
// Clean database by removing binding done on non existing or no more existing accounts
$db->begin();
$sql1 = "UPDATE ".$db->prefix()."facture_fourn_det as fd";
$sql1 .= " SET fk_code_ventilation = 0";
@ -178,31 +178,31 @@ if ($action == 'validatehistory' && $user->hasRight('accounting', 'bind', 'write
while ($i < min($num_lines, 10000)) { // No more than 10000 at once
$objp = $db->fetch_object($result);
$thirdpartystatic->id = $objp->socid;
$thirdpartystatic->name = $objp->name;
$thirdpartystatic->client = $objp->client;
$thirdpartystatic->fournisseur = $objp->fournisseur;
$thirdpartystatic->code_client = $objp->code_client;
$thirdpartystatic->code_compta_client = $objp->code_compta_client;
$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
$thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
$thirdpartystatic->email = $objp->email;
$thirdpartystatic->country_code = $objp->country_code;
$thirdpartystatic->tva_intra = $objp->tva_intra;
$thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
$thirdpartystatic->name = !empty($objp->name) ? $objp->name : "";
$thirdpartystatic->client = !empty($objp->client) ? $objp->client : "";
$thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur : "";
$thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client : "";
$thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client : "";
$thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur : "";
$thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur : "";
$thirdpartystatic->email = !empty($objp->email) ? $objp->email : "";
$thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code : "";
$thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra : "";
$thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
$product_static->ref = $objp->product_ref;
$product_static->id = $objp->product_id;
$product_static->type = $objp->type;
$product_static->label = $objp->product_label;
$product_static->status = $objp->status;
$product_static->status_buy = $objp->status_buy;
$product_static->status = !empty($objp->status) ? $objp->status : 0;
$product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
$product_static->accountancy_code_sell = $objp->code_sell;
$product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
$product_static->accountancy_code_sell_export = $objp->code_sell_export;
$product_static->accountancy_code_buy = $objp->code_buy;
$product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
$product_static->accountancy_code_buy_export = $objp->code_buy_export;
$product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy : "";
$product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra : "";
$product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export : "";
$product_static->tva_tx = $objp->tva_tx_prod;
$facture_static->ref = $objp->ref;
@ -301,7 +301,7 @@ print '</span><br>';
$y = $year_current;
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'">'.img_picto('', 'link', 'class="paddingright fa-color-unset smallpaddingimp"').$langs->trans("ValidateHistory").'</a>';
$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
@ -344,8 +344,9 @@ for ($i = 1; $i <= 12; $i++) {
$j -= 12;
}
$sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
$sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
}
$sql .= " SUM(ffd.total_ht) as total";
$sql .= " SUM(ffd.total_ht) as total, COUNT(ffd.rowid) as nb";
$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
$sql .= " LEFT JOIN ".$db->prefix()."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
@ -405,17 +406,17 @@ if ($resql) {
$cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
$tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
print '<td class="right nowraponall amount">';
print price($row[$i]);
print '<td class="right nowraponall amount" title="'.price($row[2*$i - 2]).' - '.$row[2*$i - 1].' lines">';
print price($row[2*$i - 2]);
// Add link to make binding
if (!empty(price2num($row[$i]))) {
if (!empty(price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
print '</a>';
}
print '</td>';
}
print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
print '</tr>';
}
$db->free($resql);