Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_impacc_csv_bank.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * Copyright (C) 2016 Dany De Bontridder <dany@alchimerys.be>
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 
20 
21 /*!
22  * @file
23  * @brief Filter for the Financial format
24  *
25  */
26 require_once DIR_IMPORT_ACCOUNT."/include/class_impacc_csv.php";
27 
28 ///Filter for the Financial format
30 {
31  /*!
32  * \brief insert file into the table import_detail
33  */
34  function record(Impacc_Csv $p_csv, Impacc_File $p_file)
35  {
36  global $aseparator;
37  // Open the CSV file
38  $hFile=fopen($p_file->import_file->i_tmpname, "r");
39  $cn=Dossier::connect();
40  $delimiter=$aseparator[$p_csv->detail->s_delimiter-1]['label'];
41  $surrount=($p_csv->detail->s_surround=="")?'"':$p_csv->detail->s_surround;
42  //---- For each row ---
43  while ($row=fgetcsv($hFile, 0,$delimiter ,$surrount ))
44  {
45  $insert=new Impacc_Import_detail_SQL($cn);
46  $insert->import_id=$p_file->import_file->id;
47  $nb_row=count($row);
48  if ($nb_row<5)
49  {
50  $insert->id_status=-1;
51  $insert->id_message=join($row,$delimiter );
52  }
53  else
54  {
55  $insert->id_date=$row[0];
56  $insert->id_code_group=$row[1];
57  $insert->id_acc=$row[2];
58  $insert->id_pj=$row[3];
59  $insert->id_label=$row[4];
60  $insert->id_amount_novat=$row[5];
61  }
62  $insert->insert();
63  }
64 
65  }
66  /// Transform a group of rows to an array and set $jr_date_paid
67  /// useable by Acc_Ledger_Sold::insert
68  function adapt( $p_row)
69  {
70  bcscale(4);
71  $cn=Dossier::connect();
72 
73  // Get the code_group
74  $code_group=$p_row;
75 
76  // get all rows from this group
78  $all_row=$t->collect_objects("where import_id=$1 and id_code_group=$2",
79  array($p_row['import_id'],$p_row['id_code_group']));
80 
81  // No block due to analytic
82  global $g_parameter;
83  $g_parameter->MY_ANALYTIC="N";
84 
85  // Initialise the array
86  $array=array();
87  // The first row gives all the information , the others of the group
88  // add services
89  $array['nb_item']=count($all_row); // must == 1
90  $array['chdate']=2; // must == 1
91  $array['e_other0']=$all_row[0]->id_acc;
92  $array['e_concerned0']="";
93  $array['e_other0_comment']=$all_row[0]->id_label;
94  // Must be transformed into DD.MM.YYYY
95  $array['dateop0']=$all_row[0]->id_date_conv;
96  $array['e_pj']=$all_row[0]->id_pj;
97 
98  $array['mt']=microtime();
99  $array['jrn_type']='FIN';
100  $array["e_other0_amount"]=$all_row[0]->id_amount_novat;
101  return $array;
102  }
103  /// Transfer operation with the status correct to the
104  /// accountancy . Change the status of the row (id_status to 1) after
105  /// because it can transferred several rows in one operation
106  function insert($a_group, Acc_Ledger_Fin $p_ledger)
107  {
108  $cn=Dossier::connect();
109  $nb_group=count($a_group);
110  for ( $i=0;$i< $nb_group;$i++)
111  {
112  $array=$this->adapt($a_group[$i]);
113 
114  //Complete the array
115  $array["p_jrn"]=$p_ledger->id;
116 
117  //Receipt
118  if (trim($array['e_pj'])=="") $array["e_pj"]=$p_ledger->guess_pj();
119  $array['e_pj_suggest']=$p_ledger->guess_pj();
120 
121  // Because of a bug in Acc_Ledger_Fin we have to unset this
122  // global variable
123  unset($_FILES);
124 
125  // Insert
126  $p_ledger->insert($array);
127 
128  // Update this group , status = 2 , jr_id
129  // and date_payment
130  $cn->exec_sql("update impacc.import_detail set id_status=2 where id_code_group=$1",
131  array($a_group[$i]['id_code_group']));
132 
133  }
134 
135  }
136 }
record(Impacc_Csv $p_csv, Impacc_File $p_file)
insert file into the table import_detail
adapt($p_row)
Transform a group of rows to an array and set $jr_date_paid.
while(($row=fgetcsv($fbank, 0, $sp))!==false)
for($i=0;$i< Database::num_row($ret);$i++) $row
global $aseparator
$nb_row
Definition: search_view.php:6
insert($a_group, Acc_Ledger_Fin $p_ledger)
Transfer operation with the status correct to the accountancy .
global $g_parameter
Definition: ajax.php:27
if(isset($_POST['remove'])) $array
Filter for the Financial format.
global $cn