21 require_once
'class_impacc_csv_bank.php';
22 require_once
'class_impacc_csv_sale.php';
23 require_once
'class_impacc_csv_purchase.php';
24 require_once
'class_impacc_csv_misc_operation.php';
25 require_once
'class_impacc_tool.php';
26 require_once DIR_IMPORT_ACCOUNT.
"/database/class_impacc_import_detail_sql.php";
37 $cn=Dossier::connect();
39 $this->detail->s_delimiter=
"2";
40 $this->detail->s_surround=
'"';
41 $this->detail->jrn_def_id=3;
42 $this->detail->s_encoding=
"utf-8";
43 $this->detail->s_decimal=
'1';
44 $this->detail->s_thousand=
'0';
45 $this->detail->s_date_format=1;
47 "CK_FORMAT_DATE"=>_(
"Format de date incorrect"),
48 "CK_PERIODE_CLOSED"=>_(
"Période non trouvée"),
49 "CK_INVALID_PERIODE"=>_(
"Période non trouvée"),
50 "CK_INVALID_AMOUNT"=>_(
"Montant invalide"),
51 "CK_INVALID_ACCOUNTING"=>_(
"Poste comptable ou Fiche non existante"),
52 "CK_TVA_INVALID"=>_(
"Code TVA Invalide"),
53 "CK_CARD_LEDGER"=>_(
"Fiche non disponible pour journal"),
54 "CK_BALANCE"=>_(
"Balance incorrecte"),
55 "CK_ERROR_DEBIT"=>_(
"Erreur D/C")
63 $in_delimiter=
new ISelect(
'in_delimiter');
65 $in_delimiter->selected=$this->detail->s_delimiter;
66 $in_delimiter->size=1;
68 $in_surround=
new IText(
'in_surround', $this->detail->s_surround);
71 $ledger=
new Acc_Ledger($cn, $this->detail->jrn_def_id);
72 $in_ledger=
$ledger->select_ledger(
'ALL', 3);
73 $in_ledger->name=
'in_ledger';
75 $in_encoding=
new ISelect(
'in_encoding');
76 $in_encoding->value=array(
77 array(
'value'=>
"utf-8",
'label'=>_(
'Unicode')),
78 array(
'value'=>
"latin1",
'label'=>_(
'Latin'))
80 $in_encoding->selected=$this->detail->s_encoding;
82 $in_decimal=
new ISelect(
'in_decimal');
84 $in_decimal->selected=$this->detail->s_decimal;
87 $in_thousand=
new ISelect(
'in_thousand');
88 $in_thousand->selected=$this->detail->s_thousand;
92 $in_date_format=
new ISelect(
"in_date_format");
94 $in_date_format->selected=$this->detail->s_date_format;
96 require_once DIR_IMPORT_ACCOUNT.
'/template/upload_operation.php';
101 $this->detail->import_id=$p_file_id;
110 $this->detail->s_delimiter=HtmlInput::default_value_post(
"in_delimiter",
112 $this->detail->s_surround=HtmlInput::default_value_post(
"in_surround",
114 $this->detail->jrn_def_id=HtmlInput::default_value_post(
"in_ledger",
"");
115 $this->detail->s_encoding=HtmlInput::default_value_post(
"in_encoding",
117 $this->detail->s_decimal=HtmlInput::default_value_post(
"in_decimal",
"");
118 $this->detail->s_thousand=HtmlInput::default_value_post(
"in_thousand",
120 $this->detail->s_date_format=HtmlInput::default_value_post(
"in_date_format",
128 if ($this->detail->s_thousand==$this->detail->s_decimal)
129 throw new Exception(_(
"Séparateur de décimal et milliers doivent être différent"));
141 $cn=Dossier::connect();
142 $ledger=
new Acc_Ledger(
$cn, $this->detail->jrn_def_id);
143 $ledger_type=
$ledger->get_type();
146 $cn=Dossier::connect();
150 $array=$t1->collect_objects(
" where import_id = $1 and coalesce(id_status,0) <> -1 ",
151 array($p_file->impid));
154 $date_format=$aformat_date[$this->detail->s_date_format-1][
'format'];
155 $date_format_sql=$aformat_date[$this->detail->s_date_format-1][
'label'];
157 for ($i=0; $i<$nb_array; $i++)
159 $and=(
$array[$i]->id_message==
"")?
"":
",";
161 if (trim(
$array[$i]->id_code_group)==
"")
164 $array[$i]->id_message .= $and.
"CK_CODE_GROUP";
174 $array[$i]->id_message .= $and.
"CK_FORMAT_DATE";
179 $array[$i]->id_date_conv=$test->format(
'd.m.Y');
180 $array[$i]->id_date_format_conv=$test->format(
'Ymd');
182 $sql=sprintf(
"select p_id from parm_periode where p_start <= to_date($1,'%s') and p_end >= to_date($1,'%s') ",
183 $date_format_sql, $date_format_sql);
184 $periode_id=
$cn->get_value(
$sql, array(
$array[$i]->id_date));
187 $array[$i]->id_message.=$and.
"CK_INVALID_PERIODE";
193 $per=
new Periode(
$cn, $periode_id);
194 $per->jrn_def_id=$this->detail->jrn_def_id;
195 if (
$per->is_open()==0)
197 $array[$i]->id_message.=$and.
"CK_PERIODE_CLOSED";
207 if ($ledger_type==
'ODS'&&$card==
false)
210 $poste=
new Acc_Account_Ledger(
$cn,
$array[$i]->id_acc);
211 if ($poste->do_exist()==0)
213 $array[$i]->id_message.=$and.
"CK_INVALID_ACCOUNTING";
217 if ($ledger_type!=
'ODS'&&$card==
false)
219 $array[$i]->id_message.=$and.
"CK_INVALID_ACCOUNTING";
223 if ($card instanceof Fiche)
225 if ($card->belong_ledger($this->detail->jrn_def_id)!=1)
227 $array[$i]->id_message.=$and.
"CK_CARD_LEDGER";
236 $this->detail->s_thousand, $this->detail->s_decimal);
237 if (isNumber(
$array[$i]->id_amount_novat_conv)==0)
239 $array[$i]->id_message.=$and.
"CK_INVALID_AMOUNT";
246 switch ($ledger_type)
255 $array[$i]->id_message=$and.
"CK_INVALID_ACCOUNTING";
258 if ($card instanceof Fiche&&$card->belong_ledger($this->detail->jrn_def_id)!=1)
260 $array[$i]->id_message.=$and.
"CK_CARD_LEDGER";
264 $this->detail->s_thousand, $this->detail->s_decimal);
273 $array[$i]->id_message=$and.
"CK_INVALID_ACCOUNTING";
276 if ($card instanceof Fiche&&$card->belong_ledger($this->detail->jrn_def_id)!=1)
278 $array[$i]->id_message.=$and.
"CK_CARD_LEDGER";
282 $this->detail->s_thousand, $this->detail->s_decimal);
286 if (
$array[$i]->id_debit!=
"D"&&
$array[$i]->id_debit!=
"C")
288 $array[$i]->id_message.=$and.
"CK_ERROR_DEBIT";
296 throw new Exception(_(
'type journal inconnu'));
301 if ($ledger_type==
"ODS")
306 select sum(coalesce(id_amount_novat_conv::numeric,0)) as sum_debit,
313 group by id_code_group
315 select sum(coalesce(id_amount_novat_conv::numeric,0)) as sum_credit,
322 group by id_code_group)
323 select id_code_group,sum_debit-sum_credit
325 deb join cred using(id_code_group)
327 sum_debit <> sum_credit
328 ", array($p_file->impid));
330 for ($e=0; $e<$nb_array; $e++)
332 $cn->exec_sql(
"update impacc.import_detail set id_message = id_message||',CK_BALANCE' where id_code_group=$1 ",
333 array(
$array[$e][
'id_code_group']));
341 $this->detail->save();
351 $cn=Dossier::connect();
352 $id=
$cn->get_value(
'select id from impacc.import_csv where import_id=$1',
353 array($p_import_id));
355 $this->detail->load();
359 echo $e->getMessage();
369 $cn=Dossier::connect();
370 $ledger=
new Acc_Ledger(
$cn, $this->detail->jrn_def_id);
387 throw new Exception(_(
'type journal inconnu'));
401 $csv_class->record($this, $p_file);
403 catch (Exception $ex)
405 error_log($ex->getTraceAsString());
406 echo _(
"Echec dans record").
" ".$ex->getMessage();
419 catch (Exception $ex)
421 error_log($ex->getTraceAsString());
422 echo _(
"Echec dans result");
425 $cn=Dossier::connect();
427 $ret=$display->seek(
" where import_id = $1 order by id",
428 array($importfile->impid));
429 $nb=Database::num_row(
$ret);
430 require DIR_IMPORT_ACCOUNT.
"/template/operation_result.php";
436 $cn=Dossier::connect();
447 with rejected as ( SELECT distinct id_code_group
448 FROM impacc.import_detail a
451 and (id_status != 0 or trim(COALESCE(id_message,'')) !='')
453 select distinct id_code_group ,id_date_format_conv, import_id
458 and id_code_group not in (select coalesce(id_code_group,'') from rejected)
460 order by id_date_format_conv asc
463 $array=
$cn->get_array(
$sql, array($this->detail->import_id));
467 catch (Exception $ex)
469 error_log($ex->getTraceAsString());
470 echo _(
"Echec dans transfer").
" ".$ex->getMessage();
$errcode
Array of error code will be recorded in import_detail.id_message.
result(Impacc_File $importfile)
Display result from the table import_detail for CSV import.
Used by all Import CSV Operation , contains the setting (delimiter,thousand ...)
if(isset($_POST['remove'])) $array
record(Impacc_File $p_file)
Record the given csv file into impacc.import_detail , depending of the ledger type a different filter...
make_csv_class($p_import_id)
Create the right object for the import id and throw and exception if the ledger type can not be found...
transfer()
Transfer the operation to the right ledger.
check(Impacc_File $p_file)
Check that upload file is correct.
save_setting()
Save the Impacc_Import_csv_SQL object into db.
switch($sep_field->selected) $date_format
retrieve the format
static check(Impacc_Import_detail_SQL $row, $p_format_date, $p_thousand, $p_decimal)
Check if Data are valid for one row.
Filter for the Financial format.
For Ledger of style SALE.
load_import($p_import_id)
Thank the import_file.id we find the corresponding record from import_csv and we load id...
For Ledger of style SALE.
input_format()
Display a form to upload a CSV file with operation.
set_setting()
Get value from post , fill up the Impacc_Import_csv_SQL object.
$detail
Object Impacc_Import_csv_SQL.
static check_card($p_account)
Check that a card exist and use a valid accounting.