Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_impacc_csv_misc_operation.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
24  *
25  */
26 require_once DIR_IMPORT_ACCOUNT."/include/class_impacc_csv.php";
27 
29 {
30 
31  //----------------------------------------------
32  ///insert file into the table import_detail
33  //!\param Impacc_Csv $p_csv CSV setting
34  //!\param Impacc_File $p_file File information
35  function record(Impacc_Csv $p_csv, Impacc_File $p_file)
36  {
37  global $aseparator;
38  // Open the CSV file
39  $hFile=fopen($p_file->import_file->i_tmpname, "r");
40  $error=0;
41  $cn=Dossier::connect();
42  $delimiter=$aseparator[$p_csv->detail->s_delimiter-1]['label'];
43  $surround=($p_csv->detail->s_surround=="")?'"':$p_csv->detail->s_surround;
44  //---- For each row ---
45  while ($row=fgetcsv($hFile, 0, $delimiter, $surround))
46  {
47  $insert=new Impacc_Import_detail_SQL($cn);
48  $insert->import_id=$p_file->import_file->id;
49  $nb_row=count($row);
50  if ($nb_row<6)
51  {
52  $insert->id_status=-1;
53  $insert->id_message=join($row,$delimiter);
54  }
55  else
56  {
57  $insert->id_date=$row[0];
58  $insert->id_code_group=$row[1];
59  $insert->id_acc=$row[2];
60  $insert->id_pj=$row[3];
61  $insert->id_label=$row[4];
62  $insert->id_amount_novat=$row[5];
63  $insert->id_debit=$row[6];
64  }
65  $insert->insert();
66  }
67  }
68  /// Check if Data are valid for one row
69  //!@param $row is an Impacc_Import_detail_SQL object
71  {
72 
73  }
74  /// Transform a group of rows to an array and set $jr_date_paid
75  /// useable by Acc_Ledger_Sold::insert
76  function adapt( $p_row)
77  {
78  bcscale(4);
79  $cn=Dossier::connect();
80 
81  // Get the code_group
82  $code_group=$p_row;
83 
84  // get all rows from this group
85  $sql_row= "
86  select id,
87  id_amount_novat_conv,
88  id_date_conv,
89  (select f_id from fiche_detail where ad_value=id_acc and ad_id=23) as f_id ,
90  id_acc ,
91  id_label,
92  id_debit,
93  id_acc,
94  id_pj
95  from
96  impacc.import_detail
97  where
98  import_id=$1
99  and id_code_group=$2";
100  $all_row=$cn->get_array($sql_row,
101  array($p_row['import_id'],$p_row['id_code_group']));
102  // No block due to analytic
103  global $g_parameter;
104  $g_parameter->MY_ANALYTIC="N";
105 
106  // Initialise the array
107  $array=array();
108  // The first row gives all the information , the others of the group
109  // add services
110  $array['nb_item']=count($all_row);
111  $array['e_comm']=$all_row[0]['id_label'];
112  $array['desc']=$all_row[0]['id_label'];
113  $array['jrn_concerned']="";
114  // Must be transformed into DD.MM.YYYY
115  $array['e_pj']=$all_row[0]['id_pj'];
116  $array['e_date']=$all_row[0]['id_date_conv'];
117 
118  $array['mt']=microtime();
119  $array['jrn_type']='ODS';
120  $nb_row=count($all_row);
121  for ( $i=0;$i<$nb_row;$i++)
122  {
123  $price=$all_row[$i]['id_amount_novat_conv'];
124  if ( $all_row[$i]['id_debit'] == "D") {
125  $array["ck".$i]="";
126  }
127  if ($all_row[$i]['f_id']=="")
128  {
129  $array["poste".$i]=$all_row[$i]["id_acc"];
130  }else {
131  $array["qc_".$i]=$all_row[$i]["id_acc"];
132  }
133  $array["amount".$i]=$price;
134  $array["ld".$i]=$all_row[$i]["id_label"];
135  }
136  return $array;
137  }
138  /// Transfer operation with the status correct to the
139  /// accountancy . Change the status of the row (id_status to 1) after
140  /// because it can transferred several rows in one operation
141  function insert($a_group, Acc_Ledger $p_ledger)
142  {
143  $cn=Dossier::connect();
144  $nb_group=count($a_group);
145  for ( $i=0;$i< $nb_group;$i++)
146  {
147  $array=$this->adapt($a_group[$i]);
148 
149  //Complete the array
150  $array["p_jrn"]=$p_ledger->id;
151 
152  //Receipt
153  if (trim($array['e_pj'])=="") $array["e_pj"]=$p_ledger->guess_pj();
154  $array['e_pj_suggest']=$p_ledger->guess_pj();
155 
156  // Insert
157  $p_ledger->save($array);
158 
159  // Update this group , status = 2 , jr_id
160  // and date_payment
161  $cn->exec_sql("update impacc.import_detail set jr_id=$1 , id_status=2 where id_code_group=$2",
162  array($p_ledger->jr_id,$a_group[$i]['id_code_group']));
163 
164  }
165 
166  }
167 }
168 
check(Impacc_Import_detail_SQL $row)
Check if Data are valid for one row.
while(($row=fgetcsv($fbank, 0, $sp))!==false)
for($i=0;$i< Database::num_row($ret);$i++) $row
record(Impacc_Csv $p_csv, Impacc_File $p_file)
insert file into the table import_detail
global $aseparator
$nb_row
Definition: search_view.php:6
global $g_parameter
Definition: ajax.php:27
if(isset($_POST['remove'])) $array
adapt($p_row)
Transform a group of rows to an array and set $jr_date_paid.
$error
global $cn
insert($a_group, Acc_Ledger $p_ledger)
Transfer operation with the status correct to the accountancy .