Passed
Push — master ( 0f9140...c4489d )
by Alxarafe
22:27
created

bookkeeping/thirdparty_lettering_supplier.php (1 issue)

1
<?php
2
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2005      Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2013      Olivier Geffroy      <[email protected]>
5
 * Copyright (C) 2013      Florian Henry	    <[email protected]>
6
 * Copyright (C) 2013-2018 Alexandre Spangaro      <[email protected]>
7
 * Copyright (C) 2018      Frédéric France         <[email protected]>
8
 * Copyright (C) 2019       Alxarafe            <[email protected]>
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
/**
26
 * \file    	htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php
27
 * \ingroup 	Advanced accountancy
28
 * \brief 		Tab to setup lettering
29
 */
30
31
// Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
32
defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
33
require DOL_BASE_PATH . '/main.inc.php';
34
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
35
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
36
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
37
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
38
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
39
40
// Load translation files required by the page
41
$langs->loadLangs(array("compta","accountancy"));
42
43
$action = GETPOST('action', 'aZ09');
44
$massaction = GETPOST('massaction', 'alpha');
45
$show_files = GETPOST('show_files', 'int');
46
$confirm = GETPOST('confirm', 'alpha');
47
$toselect = GETPOST('toselect', 'array');
48
49
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
50
$sortfield = GETPOST("sortfield", 'alpha');
51
$sortorder = GETPOST("sortorder", 'alpha');
52
$page = GETPOST("page", 'int');
53
if (empty($page) || $page == - 1) {
54
	$page = 0;
55
} // If $page is not defined, or '' or -1
56
$offset = $limit * $page;
57
$pageprev = $page - 1;
58
$pagenext = $page + 1;
59
if ($sortorder == "")
60
	$sortorder = "DESC";
61
if ($sortfield == "")
62
	$sortfield = "bk.doc_date";
63
64
$search_year = GETPOST("search_year",'int');
65
$search_doc_type = GETPOST("search_doc_type",'alpha');
66
$search_doc_ref = GETPOST("search_doc_ref",'alpha');
67
68
$lettering = GETPOST('lettering', 'alpha');
69
if (!empty($lettering)) {
70
	$action=$lettering;
71
}
72
73
// Did we click on purge search criteria ?
74
// All tests are required to be compatible with all browsers
75
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha'))
76
{
77
	$search_year='';
78
	$search_doc_type='';
79
	$search_doc_ref='';
80
}
81
82
83
// Security check
84
$socid = GETPOST("socid", 'int');
85
// if ($user->societe_id) $socid=$user->societe_id;
86
87
$lettering = new Lettering($db);
88
$object = new Societe($db);
89
$object->id = $socid;
0 ignored issues
show
Documentation Bug introduced by
It seems like $socid of type string or string[] is incompatible with the declared type integer of property $id.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
90
$result = $object->fetch($socid);
91
if ($result<0)
92
{
93
	setEventMessages($object->error, $object->errors, 'errors');
94
}
95
96
97
/*
98
 * Action
99
 */
100
if ($action == 'lettering') {
101
102
	$result = $lettering->updateLettering($toselect);
103
104
	if ($result < 0) {
105
		setEventMessages('', $lettering->errors, 'errors');
106
		$error++;
107
	}
108
}
109
110
if ($action == 'autolettrage') {
111
112
	$result = $lettering->letteringThirdparty($socid);
113
114
	if ($result < 0) {
115
		setEventMessages('', $lettering->errors, 'errors');
116
		$error++;
117
	}
118
}
119
120
121
/*
122
 * View
123
 */
124
125
$form = new Form($db);
126
$formaccounting = new FormAccounting($db);
127
128
$title=$object->name." - ".$langs->trans('TabLetteringSupplier');
129
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
130
llxHeader('',$title,$help_url);
131
132
$head = societe_prepare_head($object);
133
134
dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
135
136
dol_fiche_head($head, 'lettering_supplier', $langs->trans("ThirdParty"), 0, 'company');
137
138
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
139
140
dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
141
142
dol_fiche_end();
143
144
$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
145
$sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
146
$sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
147
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
148
$sql .= " WHERE (bk.subledger_account =  '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )";
149
150
if (dol_strlen($search_year)) {
151
	$date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
152
	$date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
153
	$sql .= " AND ( bk.doc_date BETWEEN  '".$db->idate($date_start)."' AND  '".$db->idate($date_end)."' )";
154
}
155
156
$sql.= $db->order($sortfield,$sortorder);
157
158
$debit = 0;
159
$credit = 0;
160
$solde = 0;
161
// Count total nb of records and calc total sum
162
$nbtotalofrecords = '';
163
$resql = $db->query($sql);
164
if (! $resql)
165
{
166
	dol_print_error($db);
167
	exit;
168
}
169
$nbtotalofrecords = $db->num_rows($resql);
170
171
while ($obj = $db->fetch_object($resql)) {
172
	$debit += $obj->debit;
173
	$credit += $obj->credit;
174
175
	$solde += ($obj->credit - $obj->debit);
176
}
177
178
$sql.= $db->plimit($limit+1, $offset);
179
180
dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
181
$resql = $db->query($sql);
182
if (! $resql)
183
{
184
		dol_print_error($db);
185
		exit;
186
}
187
188
$num = $db->num_rows($resql);
189
190
dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
191
$resql = $db->query($sql);
192
if ($resql) {
193
	$num = $db->num_rows($resql);
194
	$i = 0;
195
196
	// print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '" method="POST">';
197
    print '<form name="add" action="?controler=accountancy/bookkeeping&method=thirdparty_lettrage_supplier&socid=' . $object->id . '" method="POST">';
198
    print '<input type="hidden" name="socid" value="' . $object->id . '">';
199
200
	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
201
202
	print "<table class=\"noborder\" width=\"100%\">";
203
	print '<tr class="liste_titre">';
204
	print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type","",$param,"",$sortfield,$sortorder);
205
	print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date","",$param,"",$sortfield,$sortorder);
206
	print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref","",$param,"",$sortfield,$sortorder);
207
	print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte","",$param,"",$sortfield,$sortorder);
208
	print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit","",$param,"",$sortfield,$sortorder);
209
	print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit","",$param,"",$sortfield,$sortorder);
210
	print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder);
211
	print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal","",$param,"",$sortfield,$sortorder);
212
	print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder);
213
	print "</tr>\n";
214
215
	print '<tr class="liste_titre">';
216
	print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
217
	print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
218
	print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
219
	print '<td colspan="6">&nbsp;</td>';
220
	print '<td align="right">';
221
	$searchpicto=$form->showFilterButtons();
222
	print $searchpicto;
223
	print '</td>';
224
	print '</tr>';
225
226
	$solde = 0;
227
	$tmp = '';
228
	while ($obj = $db->fetch_object($resql)) {
229
230
		if ($tmp != $obj->lettering_code || empty($tmp))						$tmp = $obj->lettering_code;
231
		/*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/	$solde += ($obj->credit - $obj->debit);
232
233
		print '<tr class="oddeven">';
234
235
		if (empty($obj->lettering_code)) {
236
			print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
237
			print img_edit();
238
			print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
239
		} else {
240
			print '<td>' . $obj->doc_type . '</td>' . "\n";
241
		}
242
243
		print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
244
		print '<td>' . $obj->doc_ref . '</td>';
245
		print '<td>' . $obj->label_compte . '</td>';
246
		print '<td align="right">' . price($obj->debit) . '</td>';
247
		print '<td align="right">' . price($obj->credit) . '</td>';
248
		print '<td align="right">' . price(round($solde, 2)) . '</td>';
249
		print '<td align="center">' . $obj->code_journal . '</td>';
250
251
		if (empty($obj->lettering_code)) {
252
			print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
253
		} else
254
			print '<td align="center">' . $obj->lettering_code . '</td>';
255
256
		print "</tr>\n";
257
	}
258
259
	print '<tr class="oddeven">';
260
	print '<td align="right" colspan="4">'.$langs->trans("Total").':</td>' . "\n";
261
	print '<td align="right"><strong>' . price($debit) . '</strong></td>';
262
	print '<td align="right"><strong>' . price($credit) . '</strong></td>';
263
	print '<td colspan="5"></td>';
264
	print "</tr>\n";
265
266
	print '<tr class="oddeven">';
267
	print '<td align="right" colspan="4">'.$langs->trans("Balancing").':</td>' . "\n";
268
	print '<td colspan="2">&nbsp;</td>';
269
	print '<td align="right"><strong>' . price($credit - $debit) . '</strong></td>';
270
	print '<td colspan="3"></td>';
271
	print "</tr>\n";
272
273
	print "</table>";
274
275
	print '<input class="butAction" type="submit" value="' . $langs->trans('AccountancyLettering') . '" name="lettering" id="lettering">';
276
	//print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '&action=autolettrage">'.$langs->trans('AccountancyAutoLettering').'</a>';
277
	print "</form>";
278
	$db->free($resql);
279
} else {
280
	dol_print_error($db);
281
}
282
283
// End of page
284
llxFooter();
285
$db->close();
286