<?php 
/*
 * Import danych z ecmpayments2_ecminvoiceouts do ecmtransactions_rel
 * przy wdrażaniu nowych rozrachunków
 * 
 * MZ
 * 2014-08-29
 * 
 */
$db = $GLOBALS['db'];

$res = $db->query("SELECT pi.*, t.value FROM ecmpayments2_ecminvoiceouts as pi 
		INNER JOIN ecmtransactions as t ON t.id = pi.ecminvoiceout_id WHERE pi.deleted='0'");

while ($r = $db->fetchByAssoc($res)) {
	if (is_null($r['ecmpayment_id']) || $r[ecmpayment_id]=='' || is_null($r['ecminvoiceout_id']) || $r['ecminvoiceout_id']=='') {
		continue;
	}
	global $current_user;
	$q="INSERT INTO ecmtransactions_rel VALUES ('".create_guid()."','".date('Y-m-d H:i:s')."',
		'".$current_user->id."', '".$r['ecmpayment_id']."', '".$r['ecminvoiceout_id']."', '".$r['value']."')";
	
	$db->query($q);
}

?>