dolibarr  7.0.0-beta
importaccounts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
4  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 require '../../main.inc.php';
26 
27 // Class
28 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
29 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
31 
32 // langs
33 $langs->load("compta");
34 $langs->load("bills");
35 $langs->load("main");
36 $langs->load("accountancy");
37 
38 // Security check
39 if (! $user->admin)
41 
42 $limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
43 $sortfield = GETPOST("sortfield",'alpha');
44 $sortorder = GETPOST("sortorder",'alpha');
45 $page = GETPOST("page",'int');
46 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
47 $offset = $limit * $page;
48 $pageprev = $page - 1;
49 $pagenext = $page + 1;
50 
51 
52 
53 
54 /*
55  * View
56  */
57 
58 llxHeader('', $langs->trans("ImportAccount"));
59 
60 $to_import = GETPOST("mesCasesCochees");
61 
62 if ($_POST["action"] == 'import') {
63  print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
64  if (is_array($to_import) && count($to_import) > 0) {
65  print '<div><font color="red">' . count($to_import) . ' ' . $langs->trans("SelectedLines") . '</font></div>';
66  $sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
67 
68  $result = $db->query($sql);
69  if ($result && ($db->num_rows($result) > 0)) {
70 
71  $obj = $db->fetch_object($result);
72 
73  $cpt = 0;
74  foreach ( $to_import as $maLigneCochee ) {
75 
76  $accounting = new AccountingAccount($db);
77 
78  $monLabel = GETPOST('label' . $maLigneCochee);
79  $monParentAccount = GETPOST('AccountParent' . $maLigneCochee);
80  $monType = GETPOST('pcgType' . $maLigneCochee);
81  $monSubType = GETPOST('pcgSubType' . $maLigneCochee);
82 
83  $accounting->fk_pcg_version = $obj->pcg_version;
84  $accounting->account_number = $maLigneCochee;
85  $accounting->label = $monLabel;
86  $accounting->account_parent = $monParentAccount;
87  $accounting->pcg_type = $monType;
88  $accounting->pcg_subtype = $monSubType;
89  $accounting->active = 1;
90 
91  $result = $accounting->create($user);
92  if ($result > 0) {
93  setEventMessages($langs->trans("AccountingAccountAdd"), null, 'mesgs');
94  } else {
95  setEventMessages($accounting->error, $accounting->errors, 'errors');
96  }
97  $cpt ++;
98  }
99  } else {
100  setEventMessages($langs->trans('AccountPlanNotFoundCheckSetting'), null, 'errors');
101  }
102  } else {
103  print '<div><font color="red">' . $langs->trans("AnyLineImport") . '</font></div>';
104  }
105  print '<div><font color="red">' . $langs->trans("EndProcessing") . '</font></div>';
106 }
107 
108 // list accounting account from product
109 
110 $sql = "(SELECT p.rowid as product_id, p.accountancy_code_sell as accounting ";
111 $sql .= " FROM " . MAIN_DB_PREFIX . "product as p ";
112 $sql .= " WHERE p.accountancy_code_sell >=0";
113 $sql .= " GROUP BY accounting ";
114 $sql .= ")";
115 $sql .= "UNION ALL(SELECT p.rowid as product_id, p.accountancy_code_buy as accounting ";
116 $sql .= " FROM " . MAIN_DB_PREFIX . "product as p ";
117 $sql .= " WHERE p.accountancy_code_buy >=0";
118 $sql .= " GROUP BY accounting ";
119 $sql .= ") ";
120 $sql .= " ORDER BY accounting DESC " . $db->plimit($limit + 1, $offset);
121 
122 dol_syslog('accountancy/admin/importaccounts.php:: $sql=' . $sql);
123 $result = $db->query($sql);
124 if ($result) {
125  $num_lines = $db->num_rows($result);
126  $i = 0;
127  print_barre_liste($langs->trans("ImportAccount"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num_lines);
128 
129  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
130  print '<input type="hidden" name="action" value="import">';
131 
132  print '<table class="noborder" width="100%">';
133  print '<tr class="liste_titre"><td>' . $langs->trans("AccountAccouting") . '</td>';
134  print '<td>' . $langs->trans("label") . '</td>';
135  print '<td>' . $langs->trans("Accountparent") . '</td>';
136  print '<td>' . $langs->trans("Pcgtype") . '</td>';
137  print '<td>' . $langs->trans("Pcgsubtype") . '</td>';
138  print '<td align="center">' . $langs->trans("Import") . '</td>';
139  print '</tr>';
140 
141  $form = new Form($db);
142  $formaccounting = new FormAccounting($db);
143 
144  $var = true;
145  while ( $i < min($num_lines, $limit) ) {
146  $objp = $db->fetch_object($result);
147  print '<tr class="oddeven">';
148 
149  print '<td align="left">';
150  print $objp->accounting;
151  print '</td>';
152 
153  print '<td align="left">';
154  print '<input name="label" size="30" value="">';
155  print '</td>';
156 
157  // Colonne choix du compte
158  print '<td>';
159  print $formaccounting->select_account($accounting->account_parent, 'AccountParent');
160  print '</td>';
161 
162  print '<td>';
163  print '<input type="text" name="pcgType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_type).'">';
164  print '</td>';
165 
166  print '<td>';
167  print '<input type="text" name="pcgSubType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_subtype).'">';
168  print '</td>';
169 
170  // Colonne choix ligne a ventiler
171  $checked = ('label' == 'O') ? ' checked' : '';
172 
173  print '<td align="center">';
174  print '<input type="checkbox" name="mesCasesCochees[]" ' . $checked . ' value="' . $objp->accounting . '"/>';
175  print '</td>';
176 
177  print '</tr>';
178  $i ++;
179  }
180 
181  print '<tr><td colspan="8">&nbsp;</td></tr><tr><td colspan="8" align="center"><input type="submit" class="butAction" value="' . $langs->trans("Import") . '"></td></tr>';
182 
183  print '</table>';
184  print '</form>';
185 } else {
186  print $db->error();
187 }
188 
189 llxFooter();
190 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
Class to manage generation of HTML components for accounting management.
Class to manage accounting accounts.