query("SELECT * FROM accounts WHERE deleted='0' AND ".$not_in." order by date_entered"); $accounts = array(); while ($a = $db->fetchByAssoc($acc)) { $docs = false; $doc = $db->query("SELECT id FROM ecminvoiceouts where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $docs = true; //echo $a['name'].' FV
'; } else $no_inv = true; $doc = $db->query("SELECT id FROM ecmpurchaseorders where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $docs = true; //echo $a['name'].' PO
'; } $doc = $db->query("SELECT id FROM documents where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $docs = true; //echo $a['name'].' DMS
'; } $doc = $db->query("SELECT id FROM ecmsales where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $so = true; //echo $a['name'].' ZS
'; } $doc = $db->query("SELECT id FROM ecmstockdocouts where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $docs = true; //echo $a['name'].' WZ
'; } else $no_wz = true; $doc = $db->query("SELECT id FROM ecmstockdocins where parent_id='".$a['id']."'"); if ($doc->num_rows>0) { $docs = true; //echo $a['name'].' PZ
'; } if ($docs) { continue; } if ($no_inv && $no_wz && $so) { echo $a['name'].'
'; $accounts[] = $a['id']; } } echo sizeof($accounts); return; foreach ($accounts as $id) { // copyAccount($id); /* $res = $db->query("SELECT * FROM ecmaccountcategories_bean WHERE bean_id='$id'"); if ($res->num_rows > 0) { $a = new Account(); $a->retrieve($id); echo $a->name.'
'; unset($a); } */ } return; function copyAccount($id) { $db=$GLOBALS['db']; $_GET['record'] = $id; if($_GET['record']!=''){ // id nie jest puste? jedziemy i szukamy leadsa ... $r=$db->query("select contact_id,id,date_modified,deleted from accounts_contacts where account_id='".$_GET['record']."' and deleted='0'"); if($r->num_rows>0){ while($row=$db->fetchByAssoc($r)){ $ct=$db->query("select * from contacts where id='".$row['contact_id']."' and deleted='0'"); while($row2=$db->fetchByAssoc($ct)){ $db->query("update accounts_contacts set deleted='1' where id='".$row2['id']."' and deleted='0'"); $mail=$db->query("select * from email_addr_bean_rel where bean_id='".$row2['id']."' and deleted='0'"); if($mail->num_rows>0){ while($mu=$db->fetchByAssoc($mail)){ $db->query("update email_addr_bean_rel set bean_module='Contacts' where id='".$mu['id']."' and deleted='0'"); } } } } } $l=$db->query("select * from accounts where id='".$_GET['record']."' and deleted='0'"); $l2=$db->query("describe leads"); $pola2=array(); while($daj2=$db->fetchByAssoc($l2)){ $pola2[]=$daj2['Field']; } $pola=array(); $wartosci=array(); while($daj=$db->fetchByAssoc($l)){ foreach ($daj as $pole=>$wartosc){ if($pole=='account_type')$pole='lead_type'; if(in_array($pole,$pola2)==false)continue; if($pole=='ecmprice_id')continue; if($pole=='website_update')continue; if($pole=='document_recipient_code')continue; if($pole=='document_parent_order_no')continue; if($pole=='document_delivery_address')continue; if($pole=='invoice_to_ownership')continue; if($pole=='shop_number')continue; if($pole=='krs')continue; if($pole=='regon')continue; if($pole=='document_parent_iln' || $pole=='document_shipping_iln' || $pole=='document_bank_account' || $pole=='document_parent_code' || $pole=='document_ean')continue; $pola[]=$pole; $wartosci[]=$wartosc; } $db->query("INSERT INTO `leads` (".implode(",",$pola).") VALUES ('".implode("','",$wartosci)."')"); $db->query("update accounts set deleted='1' where id='".$daj['id']."'"); } // notatki $n1=$db->query("select * from notes where parent_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update notes set parent_type='Leads' where id='".$nt['id']."'"); } } //oferty $n1=$db->query("select * from ecmquotes where parent_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update ecmquotes set parent_type='Leads' where id='".$nt['id']."'"); } } //calls $n1=$db->query("select * from calls where parent_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update calls set parent_type='Leads' where id='".$nt['id']."'"); } } //tasks $n1=$db->query("select * from tasks where parent_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update tasks set parent_type='Leads' where id='".$nt['id']."'"); } } //meetings $n1=$db->query("select * from meetings where parent_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update meetings set parent_type='Leads' where id='".$nt['id']."'"); } } //kategorie kontaktów $n1=$db->query("select * from ecmaccountcategories_bean where bean_id='".$_GET['record']."' and deleted='0'"); if($n1->num_rows>0){ while($nt=$db->fetchByAssoc($n1)){ $db->query("update ecmaccountcategories_bean set bean_name='Leads' where id='".$nt['id']."'"); } } // przenoszenie emaila $mail=$db->query("select * from email_addr_bean_rel where bean_id='".$_GET['record']."' and deleted='0'"); if($mail->num_rows>0){ // o jest email! while($mu=$db->fetchByAssoc($mail)){ // podmianka relacji na kontrahenta $db->query("update email_addr_bean_rel set bean_module='Leads' where bean_id='".$_GET['record']."'"); } } // relacja kontrahent kontakt $rr=$db->query("SELECT * FROM accounts_contacts where account_id='".$_GET['record']."' and deleted='0'"); if($rr->num_rows>0){ // o jest email! while($re=$db->fetchByAssoc($rr)){ // podmianka relacji na kontrahenta $db->query("INSERT INTO `leads_contactleads` VALUES('".implode("','",$re)."')"); $db->query("update accounts_contacts set deleted='1' where lead_id='".$_GET['record']."'"); } } // relacja adresy $ad=$db->query("SELECT * FROM account_addresses where account_id='".$_GET['record']."' and deleted='0'"); if($ad->num_rows>0){ // o jest email! while($re=$db->fetchByAssoc($ad)){ // podmianka relacji na kontrahenta $db->query("INSERT INTO `lead_addresses` VALUES('".implode("','",$re)."')"); $db->query("update account_addresses set deleted='1' where account_id='".$_GET['record']."'"); } } } } ?>