function AddOverhead($user_id, $arr)
{
    global $error;
    $prop = GetCompanyProperties();
    $object_id = $arr['o_obj'];
    $car_object_id = $arr['auto_number'];
    $type = $arr['o_type'];
    $result = mysql_query("INSERT INTO `overhead`\n\t\t\t\t\t\t\t(`user_id`, `type`, `waybill_number`, `activate_date`, `local_par_id`) \n\t\t\t\t\t\t   VALUES\n\t\t\t\t\t\t\t({$user_id}, {$type}, '{$arr['o_number']}', '{$arr['actation_data']}', '{$arr['local_par_id']}')");
    $id = mysql_insert_id();
    $full_amount = GetFullAmount($id);
    $begin_date = date("Y-m-d H:i:s");
    if (!$result) {
        $error = 'Invalid query: ' . mysql_error() . '\\n';
    } else {
        //Transport
        if ($type != 3 && $type != 6) {
            //3 is Without Transportation, 6 is Sub Overhead
            $result = mysql_query("UPDATE\n\t\t\t\t\t    \t\t\t\t`overhead`\n\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t    `user_id`\t\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t    `trans_id`\t\t\t= {$arr['transport_type']},\n\t\t\t\t\t\t\t\t\t    `driver_tin`\t\t= '{$arr['driver_id']}',\n\t\t\t\t\t\t\t\t\t    `driver_name`\t\t= '{$arr['driver_name']}',\n\t\t\t\t\t\t\t\t\t    `car_number`\t\t= {$car_object_id},\n\t\t\t\t\t\t\t\t\t    `trans_txt`\t\t\t= '{$arr['auto_trailer']}',\n\t\t\t\t\t\t\t\t\t    `transport_coast`\t= '{$arr['auto_expence_n']}',\n\t\t\t\t\t\t\t\t\t    `tran_cost_payer`\t= {$arr['auto_expence']}\n\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t`id` = {$id}");
            if (!$result) {
                $error .= 'Invalid query: ' . mysql_error() . '\\n';
            }
        }
        //Saller
        $result = mysql_query("UPDATE\n\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t`user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t    `seller_tin`\t= '{$prop['tin']}',\n\t\t\t\t\t\t\t\t    `seller_name`\t= '{$prop['name']}',\n\t\t\t\t\t\t\t\t    `start_address`\t= '{$prop['address']}',\n\t\t\t\t\t\t\t\t    `seller_un_id`\t= '{$prop['un_id']}',\n\t\t\t\t\t\t\t\t    `s_user_id`\t\t= '{$prop['s_user_id']}',\n\t\t\t\t\t\t\t\t    `full_amount`\t= '{$full_amount}',\n\t\t\t\t\t\t\t\t    `begin_date`\t= '{$begin_date}'\n\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t`id` = {$id}");
        if (!$result) {
            $error .= 'Invalid query: ' . mysql_error() . '\\n';
        }
        //Buyer
        if ($type != 1 && $type != 4) {
            //1 is Domestic Traffic, 4 is Distribution
            $result = mysql_query("UPDATE\n\t\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t    `user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t    `buyer_tin`\t\t= '{$arr['buyer_tin']}',\n\t\t\t\t\t\t\t\t\t    `buyer_name`\t= '{$arr['buyer_name']}',\n\t\t\t\t\t\t\t\t\t    `end_address`\t= '{$arr['buyer_addree']}'\n\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t`id` = {$id}");
            if (!$result) {
                $error .= 'Invalid query: ' . mysql_error() . '\\n';
            }
        }
        //Sub Overhead
        if ($type == 6) {
            //6 is Sub Overhead
            $rs_id = GetRSID($arr['local_par_id']);
            $result = mysql_query("UPDATE\n\t\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t    `user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t    `par_id`\t\t= '{$rs_id}'\n\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t`id` = {$id}");
            $req = mysql_query("SELECT `goods_id`, `quantity_f`\n\t\t\t\t\t\t\t\tFROM `overhead_detail`\n\t\t\t\t\t\t\t\tWHERE `overhead_id` = {$id}");
            while ($res = mysql_fetch_assoc($req)) {
                $result = mysql_query("UPDATE\n\t\t\t\t\t\t\t    \t\t\t`overhead_detail`\n\t\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t    \t`user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t\t    `quantity`\t\t= {$res['quantity_f']},\n\t\t\t\t\t\t\t\t\t\t    `quantity_f`\t= {$res['quantity_f']}\n\t\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t\t`overhead_id` = '{$arr['local_par_id']}' && `goods_id` = {$res['goods_id']}");
            }
            if (!$result) {
                $error .= 'Invalid query: ' . mysql_error() . '\\n';
            }
        }
        //Calculate on reserves
        if ($type == 4) {
            //4 is Distribution
            $req = mysql_query("SELECT `goods_id`,\n\t\t\t\t\t\t\t\t\t   `quantity`\n\t\t\t\t\t\t\t\tFROM `overhead_detail`\n\t\t\t\t\t\t\t\tWHERE `overhead_id` = {$id}");
            while ($res = mysql_fetch_assoc($req)) {
                $self_cost = GetPrice($res['goods_id']);
                $c_date = date('Y-m-d H:i:s');
                mysql_query("INSERT INTO `reserve`\n\t\t\t\t\t\t\t\t(`user_id`, `object_id`, `overhead_id`, `production_id`, `quantity`, `price`, `create_date`)\n\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t({$user_id}, {$car_object_id}, {$id}, {$res['goods_id']}, {$res['quantity']}, {$self_cost}, '{$c_date}')");
                OverheadTakeOff($res['goods_id'], $res['quantity'], $object_id);
            }
        } else {
            if ($type == 6) {
                //6 is Sub Overhead
                $car_object_id = GetCarNumber($arr['local_par_id']);
                $req = mysql_query("SELECT `goods_id`,\n\t\t\t\t\t\t\t\t\t   `quantity`\n\t\t\t\t\t\t\t\tFROM `overhead_detail`\n\t\t\t\t\t\t\t\tWHERE `overhead_id` = {$id}");
                mysql_query("INSERT INTO `sale_transaction`\r\n\t\t\t\t\t\t\t(`user_id`, `object_id`, `start_date`, `status`)\r\n\t\t\t\t\t\t VALUES\r\n\t\t\t\t\t\t\t({$user_id}, {$car_object_id}, '{$begin_date}', 5)");
                $transaction_id = mysql_insert_id();
                while ($res = mysql_fetch_assoc($req)) {
                    OverheadTakeOff($res['goods_id'], $res['quantity'], $car_object_id);
                    OverheadSale($transaction_id, $res['goods_id'], $res['quantity']);
                }
                $sum_cost = GetSumPrice($car_object_id);
                $sum_self_cost = GetSumSelfPrice($car_object_id);
                OverheadSaleDone($car_object_id, $sum_cost, $sum_self_cost);
            }
        }
        return $id;
    }
}
Example #2
0
function AddOverhead($user_id, $arr)
{
    global $error;
    $prop = GetCompanyProperties();
    $object_id = $arr['o_obj'];
    $car_object_id = $arr['auto_number'];
    $type = $arr['o_type'];
    $trans_type = $arr['transport_type'];
    $result = mysql_query("INSERT INTO `overhead`\n\t\t\t\t\t\t\t(`user_id`, `type`, `waybill_number`, `activate_date`, `local_par_id`, `comment`) \n\t\t\t\t\t\t   VALUES\n\t\t\t\t\t\t\t({$user_id}, {$type}, '{$arr['o_number']}', '{$arr['actation_data']}', '{$arr['local_par_id']}', '{$_REQUEST['comment_text']}')");
    $id = mysql_insert_id();
    $full_amount = GetFullAmount($id);
    //echo $full_amount;
    mysql_query("INSERT INTO `cash_flow`\n\t       (`date`,`partner_id`,       `doc_type_id`, `doc_id`, `opertaion_type`,  `cash` , `amount`,\n\t        `balans`) \n\tVALUES (NOW(), '{$arr['buyer_tin']}', 'ზედნადების გაცემა',     '{$id}',    'რეალიზაცია',    '{$_REQUEST['payed']}' , '{$full_amount}',\n\t       IFNULL((SELECT balans FROM cash_flow as cash_flow1 WHERE cash_flow1.partner_id='{$arr['buyer_tin']}' ORDER BY cash_flow1.id DESC  limit 1),0.00)+{$full_amount}-{$_REQUEST['payed']}\n\t       )");
    $req = mysql_query("SELECT `goods_id`,\n        `quantity`\n        FROM `overhead_detail`\n        WHERE `overhead_id` = {$id}");
    while ($res = mysql_fetch_assoc($req)) {
        $self_cost = GetPrice($res['goods_id']);
        $c_date = date('Y-m-d H:i:s');
        mysql_query("INSERT INTO `reserve`\n        (`user_id`, `object_id`, `overhead_id`, `production_id`, `quantity`, `price`, `create_date`)\n        VALUES\n        ({$user_id}, {$car_object_id}, {$id}, {$res['goods_id']}, {$res['quantity']}, {$self_cost}, '{$c_date}')");
        OverheadTakeOff($res['goods_id'], $res['quantity'], $object_id);
    }
    //  OverheadTakeOff($prod_id, $quantity, '131')
    //	$begin_date		= date("Y-m-d H:i:s");
    if (!$result) {
        $error = 'Invalid query1: ' . mysql_error() . '\\n';
    } else {
        //Transport
        if ($type != 3 && $type != 6) {
            //3 is Without Transportation, 6 is Sub Overhead
            if ($trans_type == 4) {
                $result = mysql_query("UPDATE     `overhead`\n                    \t\t            SET       `user_id`\t\t\t= {$user_id},\n                            \t\t              `trans_id`\t\t= {$arr['transport_type']},\n                            \t\t              `trans_txt`\t\t= '{$arr['ttxt']}'\n                    \t\t            WHERE     `id` = {$id}");
            } else {
                $result = mysql_query("UPDATE     `overhead`\n                    \t\t            SET       `user_id`\t\t\t= {$user_id},\n                            \t\t              `trans_id`\t\t= {$arr['transport_type']},\n                            \t\t              `driver_tin`\t\t= '{$arr['driver_id']}',\n                            \t\t              `driver_name`\t\t= '{$arr['driver_name']}',\n                            \t\t              `car_number`\t\t= '{$car_object_id}',\n                            \t\t              `trans_txt`\t\t= '{$arr['auto_trailer']}',\n                            \t\t              `transport_coast`\t= '{$arr['auto_expence_n']}',\n                            \t\t              `tran_cost_payer`\t= {$arr['auto_expence']}\n                    \t\t            WHERE     `id` = {$id}");
            }
            if (!$result) {
                $error .= 'Invalid query2222: ' . mysql_error() . '\\n';
            }
        }
        //Saller
        $result = mysql_query("UPDATE\n\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t`user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t    `seller_tin`\t= '{$prop['tin']}',\n\t\t\t\t\t\t\t\t    `seller_name`\t= '{$prop['name']}',\n\t\t\t\t\t\t\t\t    `start_address`\t= '{$prop['address']}',\n\t\t\t\t\t\t\t\t    `seller_un_id`\t= '{$prop['un_id']}',\n\t\t\t\t\t\t\t\t    `s_user_id`\t\t= '{$prop['s_user_id']}',\n\t\t\t\t\t\t\t\t    `full_amount`\t= '{$full_amount}',\n\t\t\t\t\t\t\t\t    `create_date`\t=  NOW()\n\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t`id` = {$id}");
        if (!$result) {
            $error .= 'Invalid query3: ' . mysql_error() . '\\n';
        }
        //Buyer
        if ($type != 1 && $type != 4) {
            //1 is Domestic Traffic, 4 is Distribution
            $result = mysql_query("UPDATE\n\t\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t    `user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t    `buyer_tin`\t\t= '{$arr['buyer_tin']}',\n\t\t\t\t\t\t\t\t\t    `buyer_name`\t= '{$arr['buyer_name']}',\n\t\t\t\t\t\t\t\t\t    `end_address`\t= '{$arr['buyer_addree']}'\n\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t`id` = {$id}");
            if (!$result) {
                $error .= 'Invalid query4: ' . mysql_error() . '\\n';
            }
        }
        //Sub Overhead
        if ($type == 6) {
            //6 is Sub Overhead
            $rs_id = GetRSID($arr['local_par_id']);
            $result = mysql_query("UPDATE\n\t\t\t\t\t\t    \t\t\t`overhead`\n\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t    `user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t    `par_id`\t\t= '{$rs_id}'\n\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t`id` = {$id}");
            $req = mysql_query("SELECT `goods_id`, `quantity_f`\n\t\t\t\t\t\t\t\tFROM `overhead_detail`\n\t\t\t\t\t\t\t\tWHERE `overhead_id` = {$id}");
            while ($res = mysql_fetch_assoc($req)) {
                $result = mysql_query("UPDATE\n\t\t\t\t\t\t\t    \t\t\t`overhead_detail`\n\t\t\t\t\t\t\t\t\t   SET\n\t\t\t\t\t\t\t\t\t    \t`user_id`\t\t= {$user_id},\n\t\t\t\t\t\t\t\t\t\t    `quantity`\t\t= {$res['quantity_f']},\n\t\t\t\t\t\t\t\t\t\t    `quantity_f`\t= {$res['quantity_f']}\n\t\t\t\t\t\t\t\t\t   WHERE\n\t\t\t\t\t\t\t\t\t\t\t`overhead_id` = '{$arr['local_par_id']}' && `goods_id` = {$res['goods_id']}");
            }
            if (!$result) {
                $error .= 'Invalid query: ' . mysql_error() . '\\n';
            }
        }
        //Calculate on reserves
        if ($type == 4) {
            //4 is Distribution
        } else {
            if ($type == 6) {
                //6 is Sub Overhead
                $car_object_id = GetCarNumber($arr['local_par_id']);
                $req = mysql_query("SELECT `goods_id`,\n\t\t\t\t\t\t\t\t\t   `quantity`\n\t\t\t\t\t\t\t\tFROM `overhead_detail`\n\t\t\t\t\t\t\t\tWHERE `overhead_id` = {$id}");
                mysql_query("INSERT INTO `sale_transaction`\n\t\t\t\t\t\t\t(`user_id`, `object_id`, `start_date`, `status`)\n\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t({$user_id}, {$car_object_id}, '{$begin_date}', 5)");
                $transaction_id = mysql_insert_id();
                while ($res = mysql_fetch_assoc($req)) {
                    OverheadTakeOff($res['goods_id'], $res['quantity'], $car_object_id);
                    OverheadSale($transaction_id, $res['goods_id'], $res['quantity']);
                }
                $sum_cost = GetSumPrice($car_object_id);
                $sum_self_cost = GetSumSelfPrice($car_object_id);
                OverheadSaleDone($car_object_id, $sum_cost, $sum_self_cost);
            }
        }
        return $id;
    }
}