Files
crm.twinpol.com/modules/EcmPaymentStates/importCSV.php
2025-05-12 15:44:39 +00:00

74 lines
3.2 KiB
PHP
Executable File

<?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);
$content=file_get_contents("modules/EcmPaymentStates/files/".$_POST['file']);
$content=str_replace(" ","",$content);
$content=explode("
",$content);
$count=count($content);
for($i=0;$i<$count;$i++){
$d=explode(".",$_REQUEST['date']);
$v=explode(";",$content[$i]);
if($v[0]=="" || $v[1]=="")continue;
//echo trim($v[0])." ".$v[1]."<br>";
$p=new EcmPayment();
$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->name=trim($v[0]);
$v[1]=str_replace(",",".",$v[1]);
$v[1]=str_replace("&nbsp;","",$v[1]);
$v[1]=substr($v[1],2,strlen($v[1]));
$p->value=$v[1];
$p->payment_date=$_REQUEST['date'];
$id=$p->save();
$GLOBALS['db']->query("update ecmpayments set value='".$v[1]."' where id='".$id."'");
}
}
?>
<h2>Payments States: Import CSV</h2>
<br>
<form action="index.php?module=EcmPaymentStates&action=importCSV&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">Account</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">File</td>
<td class="dataField" width="90%" nowrap="nowrap">
<input name="file" type="file" /> </td>
</tr>
<tr>
<td class="dataLabel" nowrap="nowrap">Payment Date</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='Import' />
</form>