Plugins  LAST
 All Data Structures Files Functions Variables Pages
show_transfer.php
Go to the documentation of this file.
1 <?php
2 //This file is part of NOALYSS and is under GPL
3 //see licence.txt
4 ?>
5 <?php
7 $cn->start();
9 switch ($sep_field->selected)
10 {
11  case '1':
12  $sp=',';
13  break;
14  case '2':
15  $sp=';';
16  break;
17  default :
18  echo _("Séparateur de champs inconnu");
19  exit();
20 }
21 
23 
24 
25 $id=$cn->get_value('insert into importbank.import(format_bank_id) values ($1) returning id',
26  array($format_bank->id));
27 ob_start();
28 $skip_row=$imported_row=0;
29 echo '<table>';
30 while( ($row=fgetcsv($fbank,0,$sp)) !== false)
31 {
32  $row_count++;
33 
34  $array_row=$row;
35  $count_col=count($array_row);
36  if ($row_count<=$_POST['skip'])
37  continue;
38 
39  if ($count_col==$_POST['nb_col'])
40  {
41  echo '<tr style="border:solid 1px black">';
42  echo td($row_count);
43 
44  $tp_date=$amount=$libelle=$operation_nb=$third=$extra=null;
45  $status='N';
46  for ($i=0; $i<$count_col; $i++)
47  {
48  switch ($_POST['header'][$i])
49  {
50  case 0:
51  $tp_date=$array_row[$i];
52 
53  break;
54  case 1:
55 
56  $amount=$array_row[$i];
57  break;
58  case 2:
59  $libelle=utf8_encode($array_row[$i]);
60  break;
61  case 3:
62  $operation_nb=preg_replace('/[^[:print:]]/', '',
63  $array_row[$i]);
64  break;
65  case 4:
66  $third=utf8_encode($array_row[$i]);
67  break;
68  case 5:
69  $extra=utf8_encode(preg_replace('/[^[:print:]]/', '',
70  $array_row[$i]));
71  break;
72  }
73  if ($_POST['header'][$i]!='-1')
74  {
75  echo td(utf8_encode($array_row[$i]),
76  'style="border:solid 1px black;color:green"');
77  }
78  }
79  /* insert into importbank.temp_bank
80  Check for duplicate, valid date, amount ....
81  */
82  // replace + sign
83  $amount=str_replace('+', '', $amount);
84 
85  // remove space
86  $amount=str_replace(' ', '', $amount);
87 
88  if ($format_bank->sep_thousand!='')
89  $amount=str_replace($athousand[$format_bank->sep_thousand]['label'],
90  '', $amount);
91  if ($adecimal[$format_bank->sep_decimal]<>'.')
92  $amount=str_replace($adecimal[$format_bank->sep_decimal]['label'],
93  '.', $amount);
94  try
95  {
96  /**
97  * if amount not valid we don't insert
98  */
99  if (isNumber($amount) == 0 ) {
100  throw new Exception(_('Montant invalide'),10);
101  }
102  /**
103  * if date not valid we don't insert
104  */
105  $test = DateTime::createFromFormat($aformat_date[$format_bank->format_date-1]['format'], trim($tp_date));
106  if ( $test === false )
107  {
108  throw new Exception (_('Date invalide').' '.$str_date,20);
109  }
110  $cn->exec_Sql('insert into importbank.temp_bank(tp_date,jrn_def_id,libelle,amount,ref_operation,status,import_id,tp_third,tp_extra)'.
111  ' values (to_date($1,\''.$str_date.'\'),$2,$3,$4,$5,$6,$7,$8,$9)',
112  array($tp_date, $format_bank->jrn_def_id, $libelle, $amount,
113  $operation_nb, $status, $id, $third, $extra));
114  $imported_row++;
115  echo '<td>'.$g_succeed.'</td>';
116  }
117  catch (Exception $ex)
118  {
119  $skip_row++;
120  $exc_code=$ex->getCode();
121  if ( $exc_code = 10 || $exc_code == 20 ) {
122  // date or amount is invalid
123  echo '<td>'.$g_failed.$ex->getMessage().'</td>';
124  }else {
125  echo _("Echec import");
126  alert($ex->getMessage());
127  if ( DEBUG ) {
128  var_dump($ex->getTraceAsString());
129  }
130  $cn->rollback();
131  }
132  }
133  } // end if
134 
135 
136  echo '</tr>';
137 }
138 
139 echo '</table>';
140 $table=ob_get_contents();
141 ob_end_clean();
142 $cn->commit();
143 $nb_col->value=($nb_col->value=='')?$max:$nb_col->value;
144 ?>
145 
146 <h2><?php echo _("Etape 4/4 : les données sont sauvegardées")?></h2>
147 <form method="POST" enctype="multipart/form-data">
148 <table>
149 <tr>
150  <td>
151  <?php echo _("Nom du format")?>
152  </td>
153  <td>
154  <?php echo $format->input()?>
155  </td>
156 </tr>
157 <tr>
158  <td>
159  <?php echo _("A importer dans le journal de banque")?>
160  </td>
161  <td>
162  <?php echo $jrn_def->input()?>
163  </td>
164 </tr>
165 <tr>
166  <td>
167 <?php echo _("Format de date")?>
168  </td>
169  <td>
170  <?php echo $format_date->input()?>
171  </td>
172 </tr>
173 
174 <tr>
175  <td>
176  <?php echo _("Séparateur de champs")?>
177  </td>
178  <td>
179  <?php echo $sep_field->input()?>
180  </td>
181 </tr>
182 
183 <tr>
184  <td>
185  <?php echo _("Séparateur de millier")?>
186  </td>
187  <td>
188  <?php echo $sep_thousand->input()?>
189  </td>
190 </tr>
191 
192 <tr>
193  <td>
194  <?php echo _("Séparateur décimal")?>
195  </td>
196  <td>
197  <?php echo $sep_decimal->input()?>
198  </td>
199 </tr>
200 <tr>
201  <td>
202  <?php echo _("Ligne d'en-tête à ne pas prendre en considération")?>
203  </td>
204  <td>
205  <?php echo $skip->input()?>
206  </td>
207 </tr>
208 
209 <tr>
210  <td>
211  <?php echo _("Les lignes ayant ce nombre de colonnes sont valides")?>
212  </td>
213  <td>
214  <?php echo $nb_col->input()?>
215  </td>
216 </tr>
217 
218 
219 
220 
221 
222 </table>
223 
224 <table>
225 <tr>
226 <?php
227 $header=new ISelect('header[]');
228 $header->value=$aheader;
229 
230 echo th(_('Ligne n°'));
231 echo th(_('Nbre de colonnes'));
232 for ( $i=0;$i<$max;$i++)
233 {
234  $header->selected=-1;
235  switch ($i)
236  {
237  case $pos_date:
238  $header->selected=0;
239  break;
240 
241  case $pos_amount:
242  $header->selected=1;
243  break;
244 
245  case $pos_lib:
246  $header->selected=2;
247  break;
248 
249  case $pos_operation_nb:
250  $header->selected=3;
251  break;
252  case 4:
253  $third=utf8_encode($array_row[$i]);
254  break;
255  case 5:
256  $extra=utf8_encode($array_row[$i]);
257  break;
258 
259  }
260  echo '<th>'.$header->input()."</th>";
261 
262 }
263 echo '</tr>';
264 
265 ?>
266 </table>
267 <?php echo $table?>
268  <ul style="list-style: none">
269  <li><?php echo _('Importés')," ",$imported_row?></li>
270  <li><?php echo _('Echec')," ",$skip_row?></li>
271  </ul>
272 
273 </form>
global $g_failed
global $aformat_date
$note style
for($i=0;$i< Database::num_row($ret);$i++) $row
$format_date
Definition: import_bank.php:57
$sep_field
Definition: import_bank.php:52
$extra
Definition: ajax.php:33
$row_count
$skip_row
global $adecimal
$categorie_appel table
global $g_succeed
global $athousand
switch($sep_field->selected) $str_date
global $cn
$max