<?
$time=time();
include_once '../inc/start_sess.php';
$x=mysql_query("SELECT * FROM `kolhoz_user` WHERE `worker3` = '3' AND `worker3_time` = '$time' ");
while($ku=mysql_fetch_array($x))
{
include_once '../inc/functions.php';
include_once '../inc/tehnika.php';
/////вскопать//////
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `fish` = '0'  AND `id_plant` != '$ku[last_food]'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `fish` = '0'  AND `id_plant` != '$ku[last_food]'");
$cm=0;
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
$m=floor(($plant['money']/$plant['count'])*$post['count']);
$cm=$cm+$m;
}
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm)."' WHERE `id` = '$ku[id]'");
mysql_query("DELETE FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `umoney` = '$cm' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog']>0)
{
$nmoney=floor(($cm/100)*$mc['nalog']);
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm-$nmoney)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nmoney', `type` = 'money', `time` = '$time'");
mysql_query("UPDATE `kolhoz_collective` SET `money` = '".($mc['money']+$nmoney)."' WHERE `id` = '$mc[id]'");
}
}


if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `fish` = '1'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `fish`='1'");
$cm=0;
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_fish` WHERE `id` = '$post[id_plant]'"));
$m=floor(($plant['money']/$plant['count'])*$post['count']);
$cm=$cm+$m;
}
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm)."' WHERE `id` = '$ku[id]'");
mysql_query("DELETE FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `fish`='1'");
mysql_query("UPDATE `kolhoz_user` SET `umoney` = '$cm' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog']>0)
{
$nmoney=floor(($cm/100)*$mc['nalog']);
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm-$nmoney)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nmoney', `type` = 'money', `time` = '$time'");
mysql_query("UPDATE `kolhoz_collective` SET `money` = '".($mc['money']+$nmoney)."' WHERE `id` = '$mc[id]'");
}
}
}
?>