NEW : lettrage in accountancy

This commit is contained in:
florian HENRY 2017-09-26 13:02:29 +02:00
parent f1791b5bf4
commit 6fcfe89565
5 changed files with 759 additions and 710 deletions

View File

@ -25,7 +25,6 @@
* \ingroup Advanced accountancy * \ingroup Advanced accountancy
* \brief Onglet de gestion de parametrages des ventilations * \brief Onglet de gestion de parametrages des ventilations
*/ */
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
@ -44,14 +43,34 @@ $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int'); $page = GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == - 1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if ($sortorder == "") $sortorder = "ASC"; if ($sortorder == "")
if ($sortfield == "") $sortfield = "bk.rowid"; $sortorder = "DESC";
if ($sortfield == "")
$sortfield = "bk.doc_date";
$search_year = GETPOST ( "search_year" ); $search_year = GETPOST("search_year", 'int');
$search_doc_type = GETPOST("search_doc_type", 'alpha');
$search_doc_ref = GETPOST("search_doc_ref", 'alpha');
$lettering = GETPOST('lettering');
if (! empty($lettering)) {
$action = $lettering;
}
$toselect = GETPOST('toselect', 'array');
// Did we click on purge search criteria ?
// All tests are required to be compatible with all browsers
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
$search_year = '';
$search_doc_type = '';
$search_doc_ref = '';
}
// Security check // Security check
$socid = GETPOST("socid", 'int'); $socid = GETPOST("socid", 'int');
@ -59,46 +78,41 @@ $socid = GETPOST("socid",'int');
$object = new Societe($db); $object = new Societe($db);
$object->id = $socid; $object->id = $socid;
$object->fetch($socid); $result = $object->fetch($socid);
if ($result < 0) {
setEventMessage($object->error, 'errors');
}
$form = new Form($db); $form = new Form($db);
$BookKeeping = new lettering($db); $BookKeeping = new lettering($db);
$formaccounting = new FormAccounting($db); $formaccounting = new FormAccounting($db);
/* /*
* Action * Action
*/ */
if ($action == 'lettering') { if ($action == 'lettering') {
$result = $BookKeeping->updatelettrage($_POST['ids']); $result = $BookKeeping->updateLettrage($toselect);
// var_dump($result);
if ($result < 0) { if ($result < 0) {
setEventMessages('', $BookKeeping->errors, 'errors'); setEventMessages('', $BookKeeping->errors, 'errors');
$error ++; $error ++;
} }
} }
if ($action == 'autolettrage') { if ($action == 'autolettrage') {
$result = $BookKeeping->LettrageTiers($socid); $result = $BookKeeping->lettrageTiers($socid);
if ($result < 0) { if ($result < 0) {
setEventMessages('', $BookKeeping->errors, 'errors'); setEventMessages('', $BookKeeping->errors, 'errors');
$error ++; $error ++;
} }
} }
llxHeader('', 'Compta - Grand Livre'); llxHeader('', 'Compta - Grand Livre');
/* /*
* Affichage onglets * Affichage onglets
*/ */
@ -106,10 +120,7 @@ llxHeader ( '', 'Compta - Grand Livre' );
dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); dol_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), 0, 'company');
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">'; print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">';
@ -122,11 +133,11 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>'; print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>';
} }
print '<tr>'; print '<tr>';
print '<td class="nowrap">' . $langs->trans("CustomerCode") . '</td><td colspan="3">'; print '<td class="nowrap">' . $langs->trans("CustomerCode") . '</td><td colspan="3">';
print $object->code_client; print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; if ($object->check_codeclient() != 0)
print ' <font class="error">(' . $langs->trans("WrongCustomerCode") . ')</font>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -139,7 +150,6 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Address // Address
print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">'; print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">';
dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); dol_print_address($object->address, 'gmap', 'thirdparty', $object->id);
@ -153,89 +163,97 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">'; print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
// $img=picto_from_langcode($object->country_code); // $img=picto_from_langcode($object->country_code);
$img = ''; $img = '';
if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); if ($object->isInEEC())
else print ($img?$img.' ':'').$object->country; print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0);
else
print ($img ? $img . ' ' : '') . $object->country;
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
$sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, ";
$sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
$sql .= " WHERE (bk.code_tiers = '" . $object->code_compta . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER. "' )" ; $sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )";
if (dol_strlen($search_year)) { if (dol_strlen($search_year)) {
$sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
$date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
$sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($date_start) . "' AND '" . $db->idate($date_end) . "' )";
} }
$sql .= $db->order($sortfield, $sortorder);
$sql .= " ORDER BY bk.lettering_code ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset );
// echo $sql;
// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG );
$resql = $db->query ( $sql );
if ($resql) {
$num = $db->num_rows ( $resql );
$i = 0;
print '<form name="add" action="?socid='.$object->id.'" method="POST">';
print '<input type="hidden" name="action" value="lettering">';
print '<input type="hidden" name="socid" value="'.$object->id.'">';
print "<table class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
print '<td></td>';
print_liste_field_titre("Doctype", "liste.php", "bk.doc_type" );
print_liste_field_titre("Docdate", "liste.php", "bk.doc_date" );
print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" );
// print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" );
// print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" );
print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" );
print_liste_field_titre("Debit", "liste.php", "bk.debit" );
print_liste_field_titre("Credit", "liste.php", "bk.credit" );
// print_liste_field_titre("Amount", "liste.php", "bk.montant" );
// print_liste_field_titre("Sens", "liste.php", "bk.sens" );
print_liste_field_titre("Codejournal", "liste.php", "bk.code_journal" );
print '<td></td>';
print '<td></td>';
print "</tr>\n";
print '<tr class="liste_titre">';
print '<form action="" method="GET">';
print '<input type="hidden" name="socid" value="' . $_GET ["socid"] . '">';
print '<td><input type="text" name="search_doc_type" value="' . $_GET ["search_doc_type"] . '"></td>';
print '<td><input type="text" name="search_year" value="' . $_GET ["search_year"] . '"></td>';
print '<td><input type="text" name="search_doc_refe" value="' . $_GET ["search_doc_ref"] . '"></td>';
// print '<td><input type="text" name="search_compte" value="' . $_GET ["search_compte"] . '"></td>';
// print '<td><input type="text" name="search_tiers" value="' . $_GET ["search_tiers"] . '"></td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
// print '<td>&nbsp;</td>';
// print '<td>&nbsp;</td>';
print '<td align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" value="' . dol_escape_htmltag ( $langs->trans ( "Search" ) ) . '" title="' . dol_escape_htmltag ( $langs->trans ( "Search" ) ) . '">';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '</form>';
print '</tr>';
$var = false;
$debit = 0; $debit = 0;
$credit = 0; $credit = 0;
$solde = 0; $solde = 0;
// Count total nb of records and calc total sum
$nbtotalofrecords = '';
$resql = $db->query($sql);
if (! $resql) {
dol_print_error($db);
exit();
}
$nbtotalofrecords = $db->num_rows($resql);
while ( $obj = $db->fetch_object($resql) ) {
$debit += $obj->debit;
$credit += $obj->credit;
$solde += ($obj->credit - $obj->debit);
}
$sql .= $db->plimit($limit + 1, $offset);
dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG);
$resql = $db->query($sql);
if (! $resql) {
dol_print_error($db);
exit();
}
$num = $db->num_rows($resql);
dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG);
if ($resql) {
$i = 0;
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="POST">';
print '<input type="hidden" name="socid" value="' . $object->id . '">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
print "<table class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
print '<td></td>';
print "</tr>\n";
print '<tr class="liste_titre">';
print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
print '<td colspan="7">&nbsp;</td>';
print '<td align="right">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
print '</tr>';
$var = false;
$solde = 0;
$tmp = ''; $tmp = '';
while ( $i < $num ) { while ( $obj = $db->fetch_object($resql) ) {
$obj = $db->fetch_object ( $resql );
if ($tmp != $obj->lettering_code || empty($tmp)) if ($tmp != $obj->lettering_code || empty($tmp))
$tmp = $obj->lettering_code; $tmp = $obj->lettering_code;
@ -243,88 +261,59 @@ llxHeader ( '', 'Compta - Grand Livre' );
if ($tmp != $obj->lettering_code || empty($obj->lettering_code)) if ($tmp != $obj->lettering_code || empty($obj->lettering_code))
$var = ! $var; $var = ! $var;
$debit+= $obj->debit;
$credit+= $obj->credit;
$solde += ($obj->credit - $obj->debit); $solde += ($obj->credit - $obj->debit);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>' . $obj->rowid . '</td>';
if (empty($obj->lettering_code)) { if (empty($obj->lettering_code)) {
print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">'; print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
print img_edit(); print img_edit();
print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n"; print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
} } else
else
print '<td>' . $obj->doc_type . '</td>' . "\n"; print '<td>' . $obj->doc_type . '</td>' . "\n";
print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>'; print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
print '<td>' . $obj->doc_ref . '</td>'; print '<td>' . $obj->doc_ref . '</td>';
// print '<td>' . $obj->numero_compte . '</td>';
// print '<td>' . $obj->code_tiers . '</td>';
print '<td>' . $obj->label_compte . '</td>'; print '<td>' . $obj->label_compte . '</td>';
print '<td>' . $obj->debit . '</td>'; print '<td>' . price($obj->debit) . '</td>';
print '<td>' . $obj->credit . '</td>'; print '<td>' . price($obj->credit) . '</td>';
// print '<td>' . $obj->montant . '</td>'; print '<td>' . price($obj->montant) . '</td>';
// print '<td>' . $obj->sens . '</td>'; print '<td>' . $obj->sens . '</td>';
print '<td>' . $obj->code_journal . '</td>'; print '<td>' . $obj->code_journal . '</td>';
print '<td>' . round($solde, 2) . '</td>'; print '<td>' . round($solde, 2) . '</td>';
if (empty($obj->lettering_code)) { if (empty($obj->lettering_code)) {
print '<td><input type="checkbox" name="ids[]" value="' . $obj->rowid . '" /></td>'; print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
} } else
else
print '<td>' . $obj->lettering_code . '</td>'; print '<td>' . $obj->lettering_code . '</td>';
print "</tr>\n"; print "</tr>\n";
$i ++;
} }
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td colspan="4">Mouvement totaux</td>' . "\n"; print '<td colspan="4">Mouvement totaux</td>' . "\n";
print '<td></td>'; print '<td><strong>' . price($debit) . '</strong></td>';
// print '<td></td>'; print '<td><strong>' . price($credit) . '</strong></td>';
// print '<td></td>'; print '<td colspan="5"></td>';
print '<td><strong>' . $debit . '</strong></td>';
print '<td><strong>' . $credit . '</strong></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td colspan="5">Solde Comptable</td>' . "\n"; print '<td colspan="9">Solde Comptable</td>' . "\n";
// print '<td></td>'; print '<td><strong>' . price($credit - $debit) . '</strong></td>';
// print '<td></td>'; print '<td colspan="5"></td>';
print '<td></td>';
print '<td><strong>' . ($credit-$debit) . '</strong></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
print "</table>"; print "</table>";
print '<input class="butAction" type="submit" value="lettering">'; print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
print '<a class="butAction" href="?socid='.$object->id.'&action=autolettrage">auto lettering</a>'; print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=autolettrage">' . $langs->trans('AccountancyAutoLettering') . '</a>';
print "</form>"; print "</form>";
$db->free($resql); $db->free($resql);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
// End of page // End of page
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@ -35,7 +35,6 @@ require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$massaction = GETPOST('massaction', 'alpha'); $massaction = GETPOST('massaction', 'alpha');
$show_files = GETPOST('show_files', 'int'); $show_files = GETPOST('show_files', 'int');
@ -46,14 +45,35 @@ $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int'); $page = GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == - 1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if ($sortorder == "") $sortorder = "ASC"; if ($sortorder == "")
if ($sortfield == "") $sortfield = "bk.rowid"; $sortorder = "DESC";
if ($sortfield == "")
$sortfield = "bk.doc_date";
$search_year = GETPOST ( "search_year" ); $search_year = GETPOST("search_year",'int');
$search_doc_type = GETPOST("search_doc_type",'alpha');
$search_doc_ref = GETPOST("search_doc_ref",'alpha');
$lettering = GETPOST('lettering');
if (!empty($lettering)) {
$action=$lettering;
}
$toselect = GETPOST('toselect','array');
// Did we click on purge search criteria ?
// All tests are required to be compatible with all browsers
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha'))
{
$search_year='';
$search_doc_type='';
$search_doc_ref='';
}
// Security check // Security check
@ -62,42 +82,51 @@ $socid = GETPOST("socid",'int');
$object = new Societe($db); $object = new Societe($db);
$object->id = $socid; $object->id = $socid;
$object->fetch($socid); $result = $object->fetch($socid);
if ($result<0) {
setEventMessage($object->error,'errors');
}
$form = new Form($db); $form = new Form($db);
$BookKeeping = new lettering($db); $BookKeeping = new lettering($db);
$formaccounting = new FormAccounting($db); $formaccounting = new FormAccounting($db);
/* /*
* Action * Action
*/ */
if ($action == 'lettering') { if ($action == 'lettering') {
$result = $BookKeeping->updatelettrage($_POST['ids']); $result = $BookKeeping->updateLettrage($toselect);
// var_dump($result); // var_dump($result);
if ($result < 0) { if ($result < 0) {
setEventMessages('', $BookKeeping->errors, 'errors'); setEventMessages('', $BookKeeping->errors, 'errors');
$error ++; $error ++;
} }
} }
if ($action == 'autolettrage') { if ($action == 'autolettrage') {
$result = $BookKeeping->LettrageTiers($socid); $result = $BookKeeping->lettrageTiers($socid);
if ($result < 0) { if ($result < 0) {
setEventMessages('', $BookKeeping->errors, 'errors'); setEventMessages('', $BookKeeping->errors, 'errors');
$error ++; $error ++;
}
} }
} $title = 'AccountancyLettrage';
llxHeader('', $title);
llxHeader ( '', 'Compta - Grand Livre' ); $param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if (!empty($search_year)) $param.='&search_year='.$search_year;
if (!empty($socid)) $param.='&socid='.$socid;
if (!empty($search_doc_type)) $param.='&search_doc_type='.$search_doc_type;
if (!empty($search_doc_ref)) $param.='&search_doc_ref='.$search_doc_ref;
/* /*
@ -107,10 +136,7 @@ llxHeader ( '', 'Compta - Grand Livre' );
dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); dol_fiche_head($head, 'accounting_supplier', $langs->trans("ThirdParty"), 0, 'company');
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">'; print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">';
@ -123,11 +149,11 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>'; print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>';
} }
print '<tr>'; print '<tr>';
print '<td class="nowrap">' . $langs->trans("SupplierCode") . '</td><td colspan="3">'; print '<td class="nowrap">' . $langs->trans("SupplierCode") . '</td><td colspan="3">';
print $object->code_fournisseur; print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; if ($object->check_codefournisseur() != 0)
print ' <font class="error">(' . $langs->trans("WrongSupplierCode") . ')</font>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -140,7 +166,6 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Address // Address
print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">'; print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">';
dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); dol_print_address($object->address, 'gmap', 'thirdparty', $object->id);
@ -154,182 +179,161 @@ llxHeader ( '', 'Compta - Grand Livre' );
print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">'; print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
// $img=picto_from_langcode($object->country_code); // $img=picto_from_langcode($object->country_code);
$img = ''; $img = '';
if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); if ($object->isInEEC())
else print ($img?$img.' ':'').$object->country; print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0);
else
print ($img ? $img . ' ' : '') . $object->country;
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
// print_r($soc); $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
// exit; $sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, ";
// [code_compta] => 411DOUA $sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
// [code_compta_fournisseur] => 401SUPPCODE
/*
* Mode Liste
*
*
*
*/
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
$sql .= " WHERE (bk.code_tiers = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER. "' )" ; $sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )";
if (dol_strlen($search_year)) { if (dol_strlen($search_year)) {
$sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
$date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
$sql .= " AND ( bk.doc_date BETWEEN '".$db->idate($date_start)."' AND '".$db->idate($date_end)."' )";
} }
$sql.= $db->order($sortfield,$sortorder);
$sql .= " ORDER BY bk.lettering ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); $debit = 0;
$credit = 0;
$solde = 0;
// Count total nb of records and calc total sum
$nbtotalofrecords = '';
$resql = $db->query($sql);
if (! $resql)
{
dol_print_error($db);
exit;
}
$nbtotalofrecords = $db->num_rows($resql);
// echo $sql; while ($obj = $db->fetch_object($resql)) {
// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); $debit += $obj->debit;
$credit += $obj->credit;
$solde += ($obj->credit - $obj->debit);
}
$sql.= $db->plimit($limit+1, $offset);
dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
$resql = $db->query($sql);
if (! $resql)
{
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '" method="POST">';
print '<form name="add" action="?socid='.$object->id.'" method="POST">';
print '<input type="hidden" name="action" value="lettering">';
print '<input type="hidden" name="socid" value="' . $object->id . '">'; print '<input type="hidden" name="socid" value="' . $object->id . '">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td></td>'; print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Doctype", "liste.php", "bk.doc_type" ); print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Docdate", "liste.php", "bk.doc_date" ); print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" ); print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte","",$param,"",$sortfield,$sortorder);
// print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" ); print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit","",$param,"",$sortfield,$sortorder);
// print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" ); print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" ); print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Debit", "liste.php", "bk.debit" ); print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Credit", "liste.php", "bk.credit" ); print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Amount", "liste.php", "bk.montant" ); print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder);
print_liste_field_titre("Sens", "liste.php", "bk.sens" );
print_liste_field_titre("Codejournal", "liste.php", "bk.code_journal" );
print '<td></td>';
print '<td></td>'; print '<td></td>';
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<form action="" method="GET">'; print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
print '<input type="hidden" name="socid" value="' . $_GET ["socid"] . '">'; print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
print '<td><input type="text" name="search_doc_type" value="' . $_GET ["search_doc_type"] . '"></td>'; print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
print '<td><input type="text" name="search_year" value="' . $_GET ["search_year"] . '"></td>'; print '<td colspan="7">&nbsp;</td>';
print '<td><input type="text" name="search_doc_refe" value="' . $_GET ["search_doc_ref"] . '"></td>';
// print '<td><input type="text" name="search_compte" value="' . $_GET ["search_compte"] . '"></td>';
// print '<td><input type="text" name="search_tiers" value="' . $_GET ["search_tiers"] . '"></td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right">'; print '<td align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" value="' . dol_escape_htmltag ( $langs->trans ( "Search" ) ) . '" title="' . dol_escape_htmltag ( $langs->trans ( "Search" ) ) . '">'; $searchpicto=$form->showFilterButtons();
print $searchpicto;
print '</td>'; print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '</form>';
print '</tr>'; print '</tr>';
$var = false; $var = false;
$debit = 0;
$credit = 0;
$solde = 0; $solde = 0;
$tmp = ''; $tmp = '';
while ( $i < $num ) { while ($obj = $db->fetch_object($resql)) {
$obj = $db->fetch_object ( $resql );
if($tmp !=$obj->lettering || empty($tmp) ) if ($tmp != $obj->lettering_code || empty($tmp))
$tmp =$obj->lettering; $tmp = $obj->lettering_code;
if($tmp !=$obj->lettering || empty($obj->lettering)) if ($tmp != $obj->lettering_code || empty($obj->lettering_code))
$var = ! $var; $var = ! $var;
$debit+= $obj->debit;
$credit+= $obj->credit;
$solde += ($obj->credit - $obj->debit); $solde += ($obj->credit - $obj->debit);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>' . $obj->rowid . '</td>'; if (empty($obj->lettering_code)) {
if(empty($obj->lettering)){
print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">'; print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
print img_edit(); print img_edit();
print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n"; print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
} } else
else
print '<td>' . $obj->doc_type . '</td>' . "\n"; print '<td>' . $obj->doc_type . '</td>' . "\n";
print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>'; print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
print '<td>' . $obj->doc_ref . '</td>'; print '<td>' . $obj->doc_ref . '</td>';
// print '<td>' . $obj->numero_compte . '</td>';
// print '<td>' . $obj->code_tiers . '</td>';
print '<td>' . $obj->label_compte . '</td>'; print '<td>' . $obj->label_compte . '</td>';
print '<td>' . $obj->debit . '</td>'; print '<td>' . price($obj->debit) . '</td>';
print '<td>' . $obj->credit . '</td>'; print '<td>' . price($obj->credit) . '</td>';
print '<td>' . $obj->montant . '</td>'; print '<td>' . price($obj->montant) . '</td>';
print '<td>' . $obj->sens . '</td>'; print '<td>' . $obj->sens . '</td>';
print '<td>' . $obj->code_journal . '</td>'; print '<td>' . $obj->code_journal . '</td>';
print '<td>' . round($solde, 2) . '</td>'; print '<td>' . round($solde, 2) . '</td>';
if(empty($obj->lettering)){ if (empty($obj->lettering_code)) {
print '<td><input type="checkbox" name="ids[]" value="' . $obj->rowid . '" /></td>'; print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
} } else
else print '<td>' . $obj->lettering_code . '</td>';
print '<td>' . $obj->lettering . '</td>';
print "</tr>\n"; print "</tr>\n";
$i ++;
} }
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td colspan="4">Mouvement totaux</td>' . "\n"; print '<td colspan="4">Mouvement totaux</td>' . "\n";
print '<td></td>'; print '<td><strong>' . price($debit) . '</strong></td>';
print '<td></td>'; print '<td><strong>' . price($credit) . '</strong></td>';
print '<td></td>'; print '<td colspan="5"></td>';
print '<td><strong>' . $debit . '</strong></td>';
print '<td><strong>' . $credit . '</strong></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td colspan="5">Solde Comptable</td>' . "\n"; print '<td colspan="9">Solde Comptable</td>' . "\n";
print '<td></td>'; print '<td><strong>' . price($credit - $debit) . '</strong></td>';
print '<td></td>'; print '<td colspan="5"></td>';
print '<td></td>';
print '<td><strong>' . ($credit-$debit) . '</strong></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
print "</table>"; print "</table>";
print '<input class="butAction" type="submit" value="lettering">'; print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
print '<a class="butAction" href="?socid='.$object->id.'&action=autolettrage">auto lettering</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '&action=autolettrage">'.$langs->trans('AccountancyAutoLettering').'</a>';
print "</form>"; print "</form>";
$db->free($resql); $db->free($resql);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
// End of page // End of page
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@ -22,12 +22,10 @@
* \ingroup Advanced accountancy * \ingroup Advanced accountancy
* \brief File of class for lettering * \brief File of class for lettering
*/ */
include_once DOL_DOCUMENT_ROOT . "/accountancy/class/bookkeeping.class.php"; include_once DOL_DOCUMENT_ROOT . "/accountancy/class/bookkeeping.class.php";
include_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php"; include_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php";
include_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php"; include_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php";
/** /**
* Class lettering * Class lettering
*/ */
@ -40,36 +38,32 @@ class lettering extends BookKeeping
* @return void * @return void
*/ */
public function lettrageTiers($socid) { public function lettrageTiers($socid) {
$db = $this->db; $db = $this->db;
$object = new Societe($this->db); $object = new Societe($this->db);
$object->id = $socid; $object->id = $socid;
$object->fetch($socid); $object->fetch($socid);
if ($object->code_compta == '411CUSTCODE') {
if( $object->code_compta == '411CUSTCODE')
$object->code_compta = ''; $object->code_compta = '';
}
if( $object->code_compta_fournisseur == '401SUPPCODE') if ($object->code_compta_fournisseur == '401SUPPCODE') {
$object->code_compta_fournisseur = ''; $object->code_compta_fournisseur = '';
}
/*$sql = "SELECT DISTINCT bk.rowid, bk.lettering_code";
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.lettering_code, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
$sql .= " WHERE code_journal = 'BQ' AND ( "; $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) AND ( ";
if (! empty($object->code_compta)) if (! empty($object->code_compta))
$sql .= " bk.code_tiers = '" . $object->code_compta . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur))
$sql .= " OR "; $sql .= " OR ";
if (! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta_fournisseur))
$sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
$sql .= " ) AND ( bk.date_lettering ='' OR bk.date_lettering IS NULL ) AND bk.lettering_code !='' ";
$sql .= " GROUP BY bk.lettering_code ";
$sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) ";
$sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) ";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
@ -85,11 +79,11 @@ class lettering extends BookKeeping
$sql .= " WHERE bk.lettering_code = '" . $obj->lettering_code . "' "; $sql .= " WHERE bk.lettering_code = '" . $obj->lettering_code . "' ";
$sql .= " AND ( "; $sql .= " AND ( ";
if (! empty($object->code_compta)) if (! empty($object->code_compta))
$sql .= " bk.code_tiers = '" . $object->code_compta . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur))
$sql .= " OR "; $sql .= " OR ";
if (! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta_fournisseur))
$sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
$sql .= " ) "; $sql .= " ) ";
// echo $sql; // echo $sql;
$resql2 = $db->query($sql); $resql2 = $db->query($sql);
@ -97,203 +91,253 @@ class lettering extends BookKeeping
$num2 = $db->num_rows($resql2); $num2 = $db->num_rows($resql2);
$i2 = 0; $i2 = 0;
$ids = array(); $ids = array();
while ( $i2 < $num2 ) { while ( $obj2 = $db->fetch_object($resql2) ) {
$obj2 = $db->fetch_object ( $resql2 );
$i2++;
$ids[] = $obj2->rowid; $ids[] = $obj2->rowid;
} }
if (count($ids) > 1) { if (count($ids) > 1) {
$result = $this->updatelettrage($ids); $result = $this->updatelettrage($ids);
// var_dump($result);
// if( $result < 0 ){
// setEventMessages('', $BookKeeping->errors, 'errors' );
// $error++;
//
// }
} }
} }
} }
} } else {
setEventMessage($this->db->lasterror,'errors');
return -1;
}*/
/** /**
Prise en charge des lettering complexe avec prelevment , virement * Prise en charge des lettering complexe avec prelevment , virement
*/ */
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type "; $sql = "SELECT DISTINCT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.thirdparty_code, ";
$sql .= " bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant ";
$sql .= " , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu ON(bk.fk_doc = bu.fk_bank AND bu.type IN ('payment', 'payment_supplier') ) "; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu ON(bk.fk_doc = bu.fk_bank AND bu.type IN ('payment', 'payment_supplier') ) ";
$sql .= " WHERE code_journal = 'BQ' AND ( "; $sql .= " WHERE ( ";
if (! empty($object->code_compta)) if (! empty($object->code_compta))
$sql .= " bk.code_tiers = '" . $object->code_compta . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur))
$sql .= " OR "; $sql .= " OR ";
if (! empty($object->code_compta_fournisseur)) if (! empty($object->code_compta_fournisseur))
$sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
$sql .= " ) AND date_lettering ='' "; $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) ";
$sql .= " GROUP BY bk.lettering_code "; $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) ";
$sql.= $db->order('bk.doc_date','DESC');
// echo $sql; // echo $sql;
// //
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0;
while ( $i < $num ) { while ( $obj = $db->fetch_object($resql)) {
$obj = $db->fetch_object ( $resql );
$ids = array(); $ids = array();
$i++; $ids_fact = array();
// print_r($obj);
if ($obj->type == 'payment_supplier') { if ($obj->type == 'payment_supplier') {
$ids[] = $obj->rowid;
$sql= 'SELECT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank '; $sql = 'SELECT DISTINCT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank, facf.rowid as fact_id';
$sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.ref) "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = payf.fk_bank AND bk.code_journal='".$obj->code_journal."')";
// $sqlmid.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid=facf.fk_soc"; $sql .= " WHERE payfacf.fk_paiementfourn = '" . $obj->url_id . "' ";
// $sqlmid.= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement as payc ON payc.id=payf.fk_paiement"; $sql .= " AND code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) ";
$sql .= " WHERE 1 ";
$sql .= " AND fk_paiementfourn = '".$obj->url_id."' ";
// $sql .= " AND (bk.numero_compte = '" . $object->code_compta . "' OR bk.numero_compte = '" . $object->code_compta_fournisseur . "') ";
$sql .= " AND ( "; $sql .= " AND ( ";
if(!empty($object->code_compta) ) if (! empty($object->code_compta)) {
$sql .= " bk.code_tiers = '" . $object->code_compta . "' "; $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) )
$sql .= " OR ";
if(!empty($object->code_compta_fournisseur) )
$sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' ";
$sql .= " ) ";
// echo $sql;
// exit;
} }
elseif($obj->type =='payment' ){ if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) {
$ids[] = $obj->rowid;
$sql= 'SELECT bk.rowid,fac.facnumber , pay.fk_bank ';
$sql.= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid) ";
$sql .= " WHERE 1 ";
$sql .= " AND payfac.fk_paiement = '".$obj->url_id."' ";
$sql .= " AND ( ";
if(!empty($object->code_compta) )
$sql .= " bk.code_tiers = '" . $object->code_compta . "' ";
if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) )
$sql .= " OR "; $sql .= " OR ";
if(!empty($object->code_compta_fournisseur) )
$sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' ";
$sql .= " ) ";
// echo $sql;
} }
if (! empty($object->code_compta_fournisseur)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
}
$sql .= " ) ";
$resql2 = $db->query($sql); $resql2 = $db->query($sql);
if ($resql2) { if ($resql2) {
$num2 = $db->num_rows ( $resql2 ); while ($obj2 = $db->fetch_object($resql2)) {
$i2 = 0; $ids[$obj2->rowid] = $obj2->rowid;
$ids_fact[] = $obj2->fact_id;
while ( $i2 < $num2 ) { }
$obj2 = $db->fetch_object ( $resql2 );
$i2++; } else {
$ids[] = $obj2->rowid; $this->errors[] = $this->db->lasterror;
return -1;
}
if (count($ids_fact)) {
$sql = 'SELECT bk.rowid, facf.ref, facf.ref_supplier ';
$sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.rowid AND facf.rowid IN (".implode(',',$ids_fact)."))";
$sql .= " WHERE bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=3) ";
$sql .= " AND ( ";
if (! empty($object->code_compta)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
}
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) {
$sql .= " OR ";
}
if (! empty($object->code_compta_fournisseur)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
}
$sql .= " ) ";
$resql2 = $db->query($sql);
if ($resql2) {
while ($obj2 = $db->fetch_object($resql2)) {
$ids[$obj2->rowid] = $obj2->rowid;
}
} else {
$this->errors[] = $this->db->lasterror;
return -1;
}
}
} elseif ($obj->type == 'payment') {
$sql = 'SELECT DISTINCT bk.rowid, fac.ref, fac.ref, pay.fk_bank, fac.rowid as fact_id';
$sql .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='".$obj->code_journal."')";
$sql .= " WHERE payfac.fk_paiement = '" . $obj->url_id . "' ";
$sql .= " AND bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) ";
$sql .= " AND ( ";
if (! empty($object->code_compta)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
}
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) {
$sql .= " OR ";
}
if (! empty($object->code_compta_fournisseur)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
}
$sql .= " ) ";
$resql2 = $db->query($sql);
if ($resql2) {
while ($obj2 = $db->fetch_object($resql2)) {
$ids[$obj2->rowid] = $obj2->rowid;
$ids_fact[] = $obj2->fact_id;
}
} else {
$this->errors[] = $this->db->lasterror;
return -1;
}
if (count($ids_fact)) {
$sql = 'SELECT bk.rowid, fac.ref, fac.ref_supplier ';
$sql .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (".implode(',',$ids_fact)."))";
$sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=2) ";
$sql .= " AND ( ";
if (! empty($object->code_compta)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta . "' ";
}
if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) {
$sql .= " OR ";
}
if (! empty($object->code_compta_fournisseur)) {
$sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' ";
}
$sql .= " ) ";
$resql2 = $db->query($sql);
if ($resql2) {
while ($obj2 = $db->fetch_object($resql2)) {
$ids[$obj2->rowid] = $obj2->rowid;
}
} else {
$this->errors[] = $this->db->lasterror;
return -1;
}
}
} }
// print_r($ids);
// exit;
if (count($ids) > 1) { if (count($ids) > 1) {
$result = $this->updatelettrage($ids); $result = $this->updatelettrage($ids);
// var_dump($result);
// if( $result < 0 ){
// setEventMessages('', $BookKeeping->errors, 'errors' );
// $error++;
//
// }
} }
// exit;
} }
} }
if ($error) {
foreach ( $this->errors as $errmsg ) {
dol_syslog(get_class($this) . "::".__METHOD__ . $errmsg, LOG_ERR);
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
}
return - 1 * $error;
} else {
return 1;
}
} }
/**
} *
* @param array $ids
* @param string $notrigger
public function updatelettrage($ids, $notrigger=false){ * @return number
*/
public function updateLettrage($ids = array(), $notrigger = false) {
$error = 0; $error = 0;
$sql = "SELECT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
$sql .= " lettering_code != '' GROUP BY lettering_code ORDER BY lettering_code DESC limit 1; ";
// echo $sql; $sql = "SELECT DISTINCT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE ";
$sql .= " lettering_code != '' ORDER BY lettering_code DESC limit 1; ";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$lettre = (empty($obj->lettering_code) ? 'AAA' : $obj->lettering_code); $lettre = (empty($obj->lettering_code) ? 'AAA' : $obj->lettering_code);
if (! empty($obj->lettering_code)) if (! empty($obj->lettering_code))
$lettre ++; $lettre ++;
} } else {
else{ $this->errors[] = 'Error' . $this->db->lasterror();
$this->errors[] = 'Error'.$this->db->lasterror();; ;
$error ++; $error ++;
} }
// var_dump(__line__, $error);
$sql = "SELECT SUM(ABS(debit)) as deb, SUM(ABS(credit)) as cred FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; $sql = "SELECT SUM(ABS(debit)) as deb, SUM(ABS(credit)) as cred FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE ";
$sql .= " rowid IN (" . implode(',', $ids) . ") "; $sql .= " rowid IN (" . implode(',', $ids) . ") ";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
// print_r($obj);
if (! (round(abs($obj->deb), 2) === round(abs($obj->cred), 2))) { if (! (round(abs($obj->deb), 2) === round(abs($obj->cred), 2))) {
// echo $sql;
// print_r($obj);
$this->errors[] = 'Total not exacts ' . round(abs($obj->deb), 2) . ' vs ' . round(abs($obj->cred), 2); $this->errors[] = 'Total not exacts ' . round(abs($obj->deb), 2) . ' vs ' . round(abs($obj->cred), 2);
$error ++; $error ++;
} }
} } else {
else{ $this->errors[] = 'Erreur sql' . $this->db->lasterror();
$this->errors[] = 'Erreur sql'.$this->db->lasterror();; ;
$error ++; $error ++;
} }
// Update request // Update request
$now = dol_now(); $now = dol_now();
$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET"; $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET";
$sql .= " lettering_code='" . $lettre . "'"; $sql .= " lettering_code='" . $lettre . "'";
$sql.= " , date_lettering = " .$now ; // todo correct date it's false $sql .= " , date_lettering = '" . $this->db->idate($now)."'"; // todo correct date it's false
$sql .= " WHERE rowid IN (" . implode(',', $ids) . ") "; $sql .= " WHERE rowid IN (" . implode(',', $ids) . ") ";
// echo $sql ;
//
// var_dump(__line__, $error);
// print_r($this->errors);
// exit;
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) {
$error ++;
$this->errors[] = "Error " . $this->db->lasterror();
}
if (! $error) if (! $error) {
{ if (! $notrigger) {
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you // Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger. // want this action calls a trigger.
@ -305,26 +349,18 @@ class lettering extends BookKeeping
// // End call triggers // // End call triggers
} }
} }
// var_dump(__line__, $error);
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ( $this->errors as $errmsg ) {
// foreach($this->errors as $errmsg) dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR);
// { $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
// dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
// $this->error.=($this->error?', '.$errmsg:$errmsg);
// }
$this->db->rollback();
// echo $this->error;
// var_dump(__line__, $error);
return -1*$error;
} }
else $this->db->rollback();
{ return - 1 * $error;
} else {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
} }
} }

View File

@ -432,6 +432,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->journal_label = $journal_label; $bookkeeping->journal_label = $journal_label;
$bookkeeping->fk_user_author = $user->id; $bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->date_lim_reglement = $now;
// No subledger_account value for the bank line // No subledger_account value for the bank line
if ($tabtype[$key] == 'payment') { if ($tabtype[$key] == 'payment') {
@ -493,6 +494,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->journal_label = $journal_label; $bookkeeping->journal_label = $journal_label;
$bookkeeping->fk_user_author = $user->id; $bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now; $bookkeeping->date_create = $now;
$bookkeeping->date_lim_reglement = $now;
if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
$bookkeeping->label_operation = ''; $bookkeeping->label_operation = '';

View File

@ -123,6 +123,24 @@ function societe_prepare_head(Societe $object)
$h++; $h++;
} }
// Tab to accountancy
if (! empty($conf->accounting->enabled) && $object->client>0)
{
$head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage.php?socid='.$object->id;
$head[$h][1] = $langs->trans("TabAccountingCustomer");
$head[$h][2] = 'accounting';
$h++;
}
// Tab to accountancy
if (! empty($conf->accounting->enabled) && $object->fournisseur>0)
{
$head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage_supplier.php?socid='.$object->id;
$head[$h][1] = $langs->trans("TabAccountingSupplier");
$head[$h][2] = 'accounting_supplier';
$h++;
}
// Related items // Related items
if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled)) if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled))
{ {