diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php index 5f621a55186..782a7de7aa4 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php @@ -21,11 +21,10 @@ */ /** - * \file accounting/bookkeeping/thirdparty_lettrage.php + * \file accounting/bookkeeping/thirdparty_lettrage.php * \ingroup Advanced accountancy - * \brief Onglet de gestion de parametrages des ventilations + * \brief Onglet de gestion de parametrages des ventilations */ - require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; @@ -34,296 +33,286 @@ 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 . '/core/lib/company.lib.php'; -$action=GETPOST('action','aZ09'); -$massaction=GETPOST('massaction','alpha'); -$show_files=GETPOST('show_files','int'); -$confirm=GETPOST('confirm','alpha'); +$action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); +$show_files = GETPOST('show_files', 'int'); +$confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if (empty($page) || $page == - 1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if ($sortorder == "") $sortorder = "ASC"; -if ($sortfield == "") $sortfield = "bk.rowid"; +if ($sortorder == "") + $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 -$socid = GETPOST("socid",'int'); +$socid = GETPOST("socid", 'int'); // if ($user->societe_id) $socid=$user->societe_id; $object = new Societe($db); $object->id = $socid; -$object->fetch($socid); - +$result = $object->fetch($socid); +if ($result < 0) { + setEventMessage($object->error, 'errors'); +} $form = new Form($db); $BookKeeping = new lettering($db); $formaccounting = new FormAccounting($db); - /* * Action */ if ($action == 'lettering') { - $result = $BookKeeping->updatelettrage($_POST['ids']); - -// var_dump($result); - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; + $result = $BookKeeping->updateLettrage($toselect); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; } } if ($action == 'autolettrage') { - $result = $BookKeeping->LettrageTiers($socid); - - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; - - } + $result = $BookKeeping->lettrageTiers($socid); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; + } } +llxHeader('', 'Compta - Grand Livre'); -llxHeader ( '', 'Compta - Grand Livre' ); +/* + * Affichage onglets + */ +$head = societe_prepare_head($object); +dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); - /* - * Affichage onglets - */ - $head = societe_prepare_head($object); +dol_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), 0, 'company'); - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); +print ''; +print ''; - dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); +if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field +{ + print ''; +} +print ''; +print ''; +print ''; +$langs->load('compta'); +print ''; +print ''; +print ''; +// Address +print ''; - print '
' . $langs->trans("ThirdPartyName") . ''; +$object->next_prev_filter = "te.fournisseur = 1"; +print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', ''); +print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans("CustomerCode") . ''; +print $object->code_client; +if ($object->check_codeclient() != 0) + print ' (' . $langs->trans("WrongCustomerCode") . ')'; +print '
'; +print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); +print ''; +print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); +print '
' . $langs->trans("Address") . ''; +dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); +print '
'; - print ''; +// Zip / Town +print ''; +print ''; - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } +// Country +print ''; +print '
'.$langs->trans("ThirdPartyName").''; - $object->next_prev_filter="te.fournisseur = 1"; - print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); - print '
' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
' . $langs->trans("Country") . ''; +// $img=picto_from_langcode($object->country_code); +$img = ''; +if ($object->isInEEC()) + print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0); +else + print ($img ? $img . ' ' : '') . $object->country; +print '
'; - print ''; - print ''.$langs->trans("CustomerCode"). ''; - print $object->code_client; - if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; - print ''; - print ''; +$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 .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; +$sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )"; - $langs->load('compta'); - print ''; - print ''; - print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); - print ''; - print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); - print ''; - print ''; +if (dol_strlen($search_year)) { + $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); - // Address - print ''.$langs->trans("Address").''; - dol_print_address($object->address,'gmap','thirdparty',$object->id); - print ''; +$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); - // Zip / Town - print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.''; +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 '
'; + print ''; + + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit); + + print ""; + print ''; + 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 ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; - // Country - print ''; + $var = false; + $solde = 0; + $tmp = ''; + while ( $obj = $db->fetch_object($resql) ) { - print '
 '; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'.$langs->trans("Country").''; - //$img=picto_from_langcode($object->country_code); - $img=''; - if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); - else print ($img?$img.' ':'').$object->country; - print '
'; + if ($tmp != $obj->lettering_code || empty($tmp)) + $tmp = $obj->lettering_code; + if ($tmp != $obj->lettering_code || empty($obj->lettering_code)) + $var = ! $var; + $solde += ($obj->credit - $obj->debit); + print ""; + if (empty($obj->lettering_code)) { + print ''; + print img_edit(); + print ' ' . $obj->doc_type . '' . "\n"; + } else + print '' . $obj->doc_type . '' . "\n"; - $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 .= " WHERE (bk.code_tiers = '" . $object->code_compta . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER. "' )" ; + print '' . dol_print_date($db->jdate($obj->doc_date), 'day') . ''; + print '' . $obj->doc_ref . ''; + print '' . $obj->label_compte . ''; + print '' . price($obj->debit) . ''; + print '' . price($obj->credit) . ''; + print '' . price($obj->montant) . ''; + print '' . $obj->sens . ''; + print '' . $obj->code_journal . ''; + print '' . round($solde, 2) . ''; + if (empty($obj->lettering_code)) { + print ''; + } else + print '' . $obj->lettering_code . ''; - - if (dol_strlen ( $search_year )) { - $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; - } - - - $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 ''; - print ''; - print ''; - - print ""; - print ''; - print ''; - 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 ''; - print ''; print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = false; - - $debit = 0; - $credit = 0; - $solde = 0; - $tmp = ''; - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - - if($tmp !=$obj->lettering_code || empty($tmp) ) - $tmp =$obj->lettering_code; - - if($tmp !=$obj->lettering_code || empty($obj->lettering_code)) - $var = ! $var; - - - $debit+= $obj->debit; - $credit+= $obj->credit; - - $solde+=($obj->credit-$obj->debit); - print ""; - - print ''; - if(empty($obj->lettering_code)){ - print '' . "\n"; - } - else - print '' . "\n"; - - - - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - - if(empty($obj->lettering_code)){ - print ''; - } - else - print ''; - - print "\n"; - - $i ++; - - - - - } - - print ''; - - print '' . "\n"; - print ''; - // print ''; - // print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print ""; - print '' . "\n"; - // print ''; - // print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print "
     '; - print ''; - print '   
' . $obj->rowid . ''; - print img_edit (); - print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering_code . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; - - print ''; - print 'auto lettering'; - print ""; - $db->free($resql); - } else { - dol_print_error($db); } + print ''; + + print 'Mouvement totaux' . "\n"; + print '' . price($debit) . ''; + print '' . price($credit) . ''; + print ''; + print "\n"; + + print ""; + print 'Solde Comptable' . "\n"; + print '' . price($credit - $debit) . ''; + print ''; + print "\n"; + + print ""; + + print ''; + print '' . $langs->trans('AccountancyAutoLettering') . ''; + print ""; + $db->free($resql); +} else { + dol_print_error($db); +} // End of page llxFooter(); diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php index 623e54f71fb..5ac224673aa 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php @@ -21,9 +21,9 @@ */ /** - * \file accounting/bookkeeping/thirdparty_lettrage.php + * \file accounting/bookkeeping/thirdparty_lettrage.php * \ingroup Advanced accountancy - * \brief Tab to setup lettering + * \brief Tab to setup lettering */ // Dolibarr environment @@ -35,300 +35,304 @@ 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 . '/core/lib/company.lib.php'; - -$action=GETPOST('action','aZ09'); -$massaction=GETPOST('massaction','alpha'); -$show_files=GETPOST('show_files','int'); -$confirm=GETPOST('confirm','alpha'); +$action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); +$show_files = GETPOST('show_files', 'int'); +$confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if (empty($page) || $page == - 1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if ($sortorder == "") $sortorder = "ASC"; -if ($sortfield == "") $sortfield = "bk.rowid"; +if ($sortorder == "") + $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 -$socid = GETPOST("socid",'int'); +$socid = GETPOST("socid", 'int'); // if ($user->societe_id) $socid=$user->societe_id; $object = new Societe($db); $object->id = $socid; -$object->fetch($socid); +$result = $object->fetch($socid); +if ($result<0) { + setEventMessage($object->error,'errors'); +} $form = new Form($db); $BookKeeping = new lettering($db); $formaccounting = new FormAccounting($db); - /* * Action */ if ($action == 'lettering') { - $result = $BookKeeping->updatelettrage($_POST['ids']); - -// var_dump($result); - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; + $result = $BookKeeping->updateLettrage($toselect); + // var_dump($result); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; } } if ($action == 'autolettrage') { - $result = $BookKeeping->LettrageTiers($socid); - - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; - - } + $result = $BookKeeping->lettrageTiers($socid); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; + } } +$title = 'AccountancyLettrage'; -llxHeader ( '', 'Compta - Grand Livre' ); +llxHeader('', $title); - /* - * Affichage onglets - */ - $head = societe_prepare_head($object); +$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; - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); - - dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); - - - - - print ''; - print ''; - - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } - - - print ''; - print ''; - print ''; - - $langs->load('compta'); - print ''; - print ''; - print ''; - - - // Address - print ''; - - // Zip / Town - print ''; - print ''; - - // Country - print ''; - - print '
'.$langs->trans("ThirdPartyName").''; - $object->next_prev_filter="te.fournisseur = 1"; - print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); - print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans("SupplierCode"). ''; - print $object->code_fournisseur; - if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; - print '
'; - print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); - print ''; - print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); - print '
'.$langs->trans("Address").''; - dol_print_address($object->address,'gmap','thirdparty',$object->id); - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'
'.$langs->trans("Country").''; - //$img=picto_from_langcode($object->country_code); - $img=''; - if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); - else print ($img?$img.' ':'').$object->country; - print '
'; - -// print_r($soc); -// exit; -// [code_compta] => 411DOUA -// [code_compta_fournisseur] => 401SUPPCODE /* - * Mode Liste - * - * - * + * Affichage onglets */ +$head = societe_prepare_head($object); - $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 .= " WHERE (bk.code_tiers = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER. "' )" ; +dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); +dol_fiche_head($head, 'accounting_supplier', $langs->trans("ThirdParty"), 0, 'company'); +print ''; +print ''; - if (dol_strlen ( $search_year )) { - $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; - } +if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field +{ + print ''; +} +print ''; +print ''; +print ''; - $sql .= " ORDER BY bk.lettering ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); +$langs->load('compta'); +print ''; +print ''; +print ''; -// echo $sql; -// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); - $resql = $db->query ( $sql ); - if ($resql) { - $num = $db->num_rows ( $resql ); - $i = 0; +// Address +print ''; +// Zip / Town +print ''; +print ''; - print ''; - print ''; - print ''; +// Country +print ''; + +print '
' . $langs->trans("ThirdPartyName") . ''; +$object->next_prev_filter = "te.fournisseur = 1"; +print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', ''); +print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans("SupplierCode") . ''; +print $object->code_fournisseur; +if ($object->check_codefournisseur() != 0) + print ' (' . $langs->trans("WrongSupplierCode") . ')'; +print '
'; +print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer); +print ''; +print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer); +print '
' . $langs->trans("Address") . ''; +dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); +print '
' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '
' . $langs->trans("Country") . ''; +// $img=picto_from_langcode($object->country_code); +$img = ''; +if ($object->isInEEC()) + print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0); +else + print ($img ? $img . ' ' : '') . $object->country; +print '
'; + +$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 .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; +$sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )"; + +if (dol_strlen($search_year)) { + $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); + +$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); + +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_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); +if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + print ''; + print ''; + + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit); + + print ""; + print ''; + 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 ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var = false; + $solde = 0; + $tmp = ''; + while ($obj = $db->fetch_object($resql)) { + + if ($tmp != $obj->lettering_code || empty($tmp)) + $tmp = $obj->lettering_code; + + if ($tmp != $obj->lettering_code || empty($obj->lettering_code)) + $var = ! $var; + + $solde += ($obj->credit - $obj->debit); + + print ""; + + if (empty($obj->lettering_code)) { + print '' . "\n"; + } else + print '' . "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if (empty($obj->lettering_code)) { + print ''; + } else + print ''; - print "
 '; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
'; + print img_edit(); + print ' ' . $obj->doc_type . '' . $obj->doc_type . '' . dol_print_date($db->jdate($obj->doc_date), 'day') . '' . $obj->doc_ref . '' . $obj->label_compte . '' . price($obj->debit) . '' . price($obj->credit) . '' . price($obj->montant) . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering_code . '
"; - print ''; - print ''; - 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 ''; - print ''; print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = false; - - $debit = 0; - $credit = 0; - $solde = 0; - $tmp = ''; - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - - if($tmp !=$obj->lettering || empty($tmp) ) - $tmp =$obj->lettering; - - if($tmp !=$obj->lettering || empty($obj->lettering)) - $var = ! $var; - - - $debit+= $obj->debit; - $credit+= $obj->credit; - - $solde+=($obj->credit-$obj->debit); - print ""; - - print ''; - if(empty($obj->lettering)){ - print '' . "\n"; - } - else - print '' . "\n"; - - - - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if(empty($obj->lettering)){ - print ''; - } - else - print ''; - - print "\n"; - - $i ++; - } - - print ''; - - print '' . "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print ""; - print '' . "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print "
     '; - print ''; - print '   
' . $obj->rowid . ''; - print img_edit (); - print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; - - print ''; - print 'auto lettering'; - print ""; - $db->free ( $resql ); - } else { - dol_print_error ( $db ); } + print ''; + + print 'Mouvement totaux' . "\n"; + print '' . price($debit) . ''; + print '' . price($credit) . ''; + print ''; + print "\n"; + + print ""; + print 'Solde Comptable' . "\n"; + print '' . price($credit - $debit) . ''; + print ''; + print "\n"; + + print ""; + + print ''; + print ''.$langs->trans('AccountancyAutoLettering').''; + print ""; + $db->free($resql); +} else { + dol_print_error($db); +} // End of page llxFooter(); diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 97721669f91..e94c33d69e5 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -18,313 +18,349 @@ */ /** - * \file accountancy/class/bookkeeping.class.php - * \ingroup Advanced accountancy - * \brief File of class for lettering + * \file accountancy/class/bookkeeping.class.php + * \ingroup Advanced accountancy + * \brief File of class for lettering */ - -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."/core/lib/date.lib.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 . "/core/lib/date.lib.php"; /** * Class lettering */ class lettering extends BookKeeping { - /** - * lettrageTiers - * - * @param int $socid Thirdparty id - * @return void - */ + /** + * lettrageTiers + * + * @param int $socid Thirdparty id + * @return void + */ public function lettrageTiers($socid) { - $db = $this->db; $object = new Societe($this->db); $object->id = $socid; $object->fetch($socid); - - if( $object->code_compta == '411CUSTCODE') + if ($object->code_compta == '411CUSTCODE') { $object->code_compta = ''; + } - if( $object->code_compta_fournisseur == '401SUPPCODE') + if ($object->code_compta_fournisseur == '401SUPPCODE') { $object->code_compta_fournisseur = ''; + } - - - $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 = "SELECT DISTINCT bk.rowid, bk.lettering_code"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE code_journal = 'BQ' AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) 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.code_tiers = '" . $object->code_compta_fournisseur . "' "; + if (! empty($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 .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; + $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; - $sql .= " GROUP BY bk.lettering_code "; - - - $resql = $db->query ( $sql ); + $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows ( $resql ); + $num = $db->num_rows($resql); $i = 0; while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - $i++; + $obj = $db->fetch_object($resql); + $i ++; - $sql = "SELECT bk.rowid "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE bk.lettering_code = '".$obj->lettering_code."' "; - $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 "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; -// echo $sql; - $resql2 = $db->query ( $sql ); - if ($resql2) { - $num2 = $db->num_rows ( $resql2 ); - $i2 = 0; - $ids = array(); - while ( $i2 < $num2 ) { - $obj2 = $db->fetch_object ( $resql2 ); - $i2++; - $ids[] = $obj2->rowid; - } - - - if(count($ids) > 1 ){ - $result = $this->updatelettrage($ids); - - // var_dump($result); -// if( $result < 0 ){ -// setEventMessages('', $BookKeeping->errors, 'errors' ); -// $error++; -// -// } - } + $sql = "SELECT bk.rowid "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE bk.lettering_code = '" . $obj->lettering_code . "' "; + $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 .= " ) "; + // echo $sql; + $resql2 = $db->query($sql); + if ($resql2) { + $num2 = $db->num_rows($resql2); + $i2 = 0; + $ids = array(); + while ( $obj2 = $db->fetch_object($resql2) ) { + $ids[] = $obj2->rowid; } - } - } + if (count($ids) > 1) { + $result = $this->updatelettrage($ids); + } + } + } + } else { + setEventMessage($this->db->lasterror,'errors'); + return -1; + }*/ /** - 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 "; + * Prise en charge des lettering complexe avec prelevment , virement + */ + $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 .= " 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 ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " WHERE ( "; + 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.code_tiers = '" . $object->code_compta_fournisseur . "' "; + if (! empty($object->code_compta_fournisseur)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) AND date_lettering ='' "; - $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) "; + $sql.= $db->order('bk.doc_date','DESC'); -// echo $sql; -// - $resql = $db->query ( $sql ); + // echo $sql; + // + $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows ( $resql ); - $i = 0; + $num = $db->num_rows($resql); - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); + while ( $obj = $db->fetch_object($resql)) { $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.= " 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 as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.ref) "; - // $sqlmid.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid=facf.fk_soc"; - // $sqlmid.= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement as payc ON payc.id=payf.fk_paiement"; - $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 ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $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; + $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 .= " 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 . "accounting_bookkeeping as bk ON (bk.fk_doc = payf.fk_bank AND bk.code_journal='".$obj->code_journal."')"; + $sql .= " WHERE payfacf.fk_paiementfourn = '" . $obj->url_id . "' "; + $sql .= " AND 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 . "' "; } - elseif($obj->type =='payment' ){ - $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 "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; - - // echo $sql; + 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 ); + $resql2 = $db->query($sql); if ($resql2) { - $num2 = $db->num_rows ( $resql2 ); - $i2 = 0; - - while ( $i2 < $num2 ) { - $obj2 = $db->fetch_object ( $resql2 ); - $i2++; - $ids[] = $obj2->rowid; + while ($obj2 = $db->fetch_object($resql2)) { + $ids[$obj2->rowid] = $obj2->rowid; + $ids_fact[] = $obj2->fact_id; } - // print_r($ids); - // exit; - if(count($ids) > 1 ){ - $result = $this->updatelettrage($ids); - - // var_dump($result); -// if( $result < 0 ){ -// setEventMessages('', $BookKeeping->errors, 'errors' ); -// $error++; -// -// } - } - - // exit; + } else { + $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; + } + } + } + + if (count($ids) > 1) { + $result = $this->updatelettrage($ids); + } + } } - - + 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; + } } - - public function updatelettrage($ids, $notrigger=false){ + /** + * + * @param array $ids + * @param string $notrigger + * @return number + */ + public function updateLettrage($ids = array(), $notrigger = false) { $error = 0; - $sql = "SELECT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; - $sql .= " lettering_code != '' GROUP BY lettering_code ORDER BY lettering_code DESC limit 1; "; -// echo $sql; - $result = $this->db->query ( $sql ); + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); + + $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); if ($result) { - $obj = $this->db->fetch_object ( $result ); - $lettre = (empty($obj->lettering_code)? 'AAA' : $obj->lettering_code ); - if(!empty($obj->lettering_code)) - $lettre++; + $obj = $this->db->fetch_object($result); + $lettre = (empty($obj->lettering_code) ? 'AAA' : $obj->lettering_code); + if (! empty($obj->lettering_code)) + $lettre ++; + } else { + $this->errors[] = 'Error' . $this->db->lasterror(); + ; + $error ++; } - else{ - $this->errors[] = 'Error'.$this->db->lasterror();; - $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 .= " rowid IN (".implode(',', $ids).") "; - $result = $this->db->query ( $sql ); + $sql .= " rowid IN (" . implode(',', $ids) . ") "; + $result = $this->db->query($sql); if ($result) { - $obj = $this->db->fetch_object ( $result ); -// print_r($obj); - 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); - $error++; + $obj = $this->db->fetch_object($result); + if (! (round(abs($obj->deb), 2) === round(abs($obj->cred), 2))) { + $this->errors[] = 'Total not exacts ' . round(abs($obj->deb), 2) . ' vs ' . round(abs($obj->cred), 2); + $error ++; } + } else { + $this->errors[] = 'Erreur sql' . $this->db->lasterror(); + ; + $error ++; } - else{ - $this->errors[] = 'Erreur sql'.$this->db->lasterror();; - $error++; - } - // Update request $now = dol_now(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; - $sql.= " lettering_code='".$lettre."'"; - $sql.= " , date_lettering = " .$now ; // todo correct date it's false - $sql.= " WHERE rowid IN (".implode(',', $ids).") "; -// echo $sql ; -// -// var_dump(__line__, $error); -// print_r($this->errors); -// exit; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET"; + $sql .= " lettering_code='" . $lettre . "'"; + $sql .= " , date_lettering = '" . $this->db->idate($now)."'"; // todo correct date it's false + $sql .= " WHERE rowid IN (" . implode(',', $ids) . ") "; $this->db->begin(); - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = "Error " . $this->db->lasterror(); + } - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. + if (! $error) { + if (! $notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } + // // Call triggers + // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + // $interface=new Interfaces($this->db); + // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + // if ($result < 0) { $error++; $this->errors=$interface->errors; } + // // End call triggers } -// var_dump(__line__, $error); - // Commit or rollback - if ($error) - { -// foreach($this->errors as $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->commit(); - return 1; + } + // Commit or rollback + if ($error) { + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); } + $this->db->rollback(); + return - 1 * $error; + } else { + $this->db->commit(); + return 1; + } } - } diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index bfa0c342245..5a0c76e3c1a 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -432,6 +432,7 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; + $bookkeeping->date_lim_reglement = $now; // No subledger_account value for the bank line if ($tabtype[$key] == 'payment') { @@ -493,6 +494,7 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $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 $bookkeeping->label_operation = ''; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 159e7a6435a..6a5f6e34a62 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -123,6 +123,24 @@ function societe_prepare_head(Societe $object) $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 if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled)) {