function calculate_fees($lot, $price, $shipping, $a_shipping) { $ebay = 0.09; $ebay_ship = 0.09; $paypal = 0.029; if ($price > 0) { $paypal_stnd = 0.3; } else { $paypal_stnd = 0; } $ebay_fee = $price * $ebay; if ($ebay_fee > 100) { $ebay_fee = 100.0; } $ebay_ship_fee = $shipping * $ebay_ship; $paypal_fee = ($price + $shipping) * $paypal + $paypal_stnd; $crd_db = $shipping - $a_shipping; if ($crd_db >= 0) { $vls = "(" . $lot . "," . $crd_db . ",0.00,'Handling fee')"; } else { $vls = "(" . $lot . ",0.00," . $crd_db * -1 . ",'Handling loss')"; } $values = "(lot,credit, debit,cd_note) value(" . $lot . ",0.00," . $ebay_fee . ",'Ebay fee'),\n\t(" . $lot . ",0.00," . $ebay_ship_fee . ",'Ebay shipping fee'),(" . $lot . ",0.00," . $paypal_fee . ",'Paypal fee')," . $vls; if (insertinto('cre_deb', $values)) { return true; } else { return false; } }
function GivingItem() { $giver = $_POST['give']; $receiver = $_POST['receive']; if ($_POST['quanity'] >= 1) { $select = "((a.cost+a.c_shipping)/a.quanity)*" . $_POST['quanity'] . "-IFNULL(e.total,0) as totals "; $from = "item a left outer join (select sum(credit-debit) as total, lot from cre_deb where lot in('193') and locate('Giving lot(193) to lot(', cd_note)=0 group by lot)e on(a.lot=e.lot)"; updatetable('item', 'set sold_quanity=sold_quanity+' . $_POST['quanity']); } else { $select = "a.cost+a.c_shipping-IFNULL(e.total,0) as totals"; $from = "item a left outer join (select sum(credit-debit) as total, lot \n\t\t\tfrom cre_deb where lot in('" . $giver . "') group by lot) e on(a.lot=e.lot)"; } $item_cost_g = GetOneRow($select, $from, "where a.lot in('" . $giver . "')"); //echo $item_cost_g['totals']."<br />"; if ($item_cost_g['totals'] > 0) { $credit1 = $debit2 = 0; $debit1 = $credit2 = $item_cost_g['totals']; } elseif ($item_cost_g['totals'] < 0) { $debit1 = $credit2 = 0; $credit1 = $debit2 = -1 * $item_cost_b['totals']; } else { //=0 $credit1 = $debit1 = $credit2 = $debit2 = 0; } $value = "(lot, credit,debit,cd_note) values('" . $receiver . "',\n\t" . $credit1 . "," . $debit1 . ",'Receiveed lot to(" . $receiver . ") from lot(" . $giver . ")'),\n\t('" . $giver . "'," . $credit2 . "," . $debit2 . ",'Giving lot(" . $giver . ") to lot(" . $receiver . ")')"; echo $value . "<br />"; if (insertinto('cre_deb', $value)) { echo "Success!"; } //$values2=set i_state= }