Files
crm.e5.pl/modules/EcmPaymentStates/importDBF.php

85 lines
3.5 KiB
PHP
Raw Normal View History

2024-04-27 09:23:34 +02:00
<?php
if($_REQUEST['type']=="save"){
require_once('include/Upload.php');
include_once("modules/EcmPayments/EcmPayment.php");
$_POST['file']=upload_file("file","modules/EcmPaymentStates/files/");
chmod("modules/EcmPaymentStates/files/".$_POST['file'],0777);
include_once("modules/EcmStockStates/class.dbf.php");
$dbf = new dbf_class("modules/EcmPaymentStates/files/".$_POST['file']);
$num_rec=$dbf->dbf_num_rec;
for($i=0;$i<$num_rec;$i++){
$row=$dbf->getRowAssoc($i);
for($j=2;$j<=20;$j++){
if($row['N'.$j]){
$nn='N'.$j;
break;
}
}
if($row['N1']=="" || $row[$nn]=="")continue;
$name=trim($row['N1']);
$name=str_replace(" ","",$name);
$name=substr($name,2);
$value=trim($row[$nn]);
$value=str_replace(" ","",$value);
//$value=substr($value,2);
$value=str_replace(",",".",$value);
$value=floatval($value);
$p=new EcmPayment();
$p->name=$name;
$p->parent_id=$_POST['account_id'];
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ems_system_id from accounts where id='".$_POST['account_id']."'"));
$p->parent_name=$_POST['account_name'];
$p->ems_system_id=$r['ems_system_id'];
$p->value=$value;
$p->payment_date=$_REQUEST['date'];
//echo $name."#######".$value."<br>";
$id=$p->save();
$GLOBALS['db']->query("update ecmpayments set value='".$value."' where id='".$id."'");
}
header("Location: index.php?module=EcmPaymentStates&action=index&account_id=".$_POST['account_id']);
}
?>
<h2>Payments States: Import DBF</h2>
<br>
<form action="index.php?module=EcmPaymentStates&action=importDBF&type=save" method="post" name="importCSV" enctype="multipart/form-data">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-top: 0px none; margin-bottom: 4px;" class="tabForm">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">Kontrahent</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="account_name" tabindex="" id="account_name" size="" value="<?php echo $_REQUEST['account_name'];?>" title="" type="text">
<input name="account_id" id="account_id" value="<?php echo $_REQUEST['account_id'];?>" type="hidden">
<input name="btn_account_name" tabindex="" title="Select [Alt+T]" accesskey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"importCSV","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);' type="button"> </td>
<td class="dataLabel" width="10%" nowrap="nowrap">Plik</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="file" type="file" /> </td>
</tr>
<tr>
<td class="dataLabel" nowrap="nowrap">Data płatności</td>
<td class="dataField" nowrap="nowrap">
<input autocomplete="off" name="date" id="date" value="<?php echo $_REQUEST['date'];?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" nowrap="nowrap">&nbsp;</td>
<td class="dataField" nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<input class='button' type='submit' name='button' value='Importuj' />
</form>