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#6zB™# %1홪#}\nt/,zDz. inrƳ[42 ,5ZBb(~k@*,K`礰îND%A=e~&ћlD*;MN2kl>VRs7n)4VƙvQͲz>&R"l]&R%aG ,D-8lO)ȰOOl`)Le9JvWըRl4W\c&Z[D)rY>ZV1*3>! +E 77Wr Ȅ  zT!^Xo&(^ !sWllxM{,9g'? l$${!P{~w&l:UF3tܼܵ _i[d!T#&Bc|urn-$qty_stock==0){ mysql_query("update item set qty=0,uprice=0 where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); }else{ $uprice=(($qty_stock*$uprice_stock)-($qty_saleReturn*$uprice_purchase))/($qty_stock-$qty_saleReturn); mysql_query("update item set uprice=$uprice where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); } updateQty($itemid); return 0; } if(isset($_POST['btnSave'])){ $invno = $_POST['invno']; $amt = $_POST['amt']; $paid = $_POST['paid']==""? 0: $_POST['paid']; $transport = $_POST['transport']==""? 0: $_POST['transport']; $Discount = $_POST['Discount']==""? 0: $_POST['Discount']; $date_ = date('Y-m-d',strtotime($_POST['date_'])); $actype = $_POST['actype']; $actypeold=""; if (getName("select 1 from purchaseReturn2 where invno='$invno' and LabID='".$_SESSION['LabID']."'")=="") { echo "Add Item First"; }else{ $qry="update purchaseReturn2 set actype='$actype',date_='$date_',paid=$paid,discount='$Discount',transport='$transport' where invno='$invno' and LabID='".$_SESSION['LabID']."'"; //echo $qry; mysql_query($qry); $actypeold=getName("select actype from purchaseReturn2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); } $amt=$amt-$Discount; mysql_query("delete from ledger where purchaseReturnNo='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid = getName("select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,purchaseReturnNo,actid,debit,credit,LabID) values('$autoid','purchaseReturn #:$invno','$date_',$invno,$actid,$amt,$paid,$LabID)"; //echo $qry; mysql_query($qry); mysql_query("update purchaseReturn set date_='$date_' where invno='$invno' and LabID='".$_SESSION['LabID']."' "); //mysql_query("update accounts set balance=(select ifnull(sum(debit),0)-ifnull(sum(credit),0) from ledger where actid='$actid') where id='$actid' "); calculateBalance($actid); if($paid>0 and $actype!=""){ $autoid = getName("select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,purchaseReturnNo,actid,debit,credit,LabID) values('$autoid','purchaseReturn #:$invno','$date_',$invno,$actype,$paid,0,$LabID)"; //echo $qry; mysql_query($qry); calculateBalance($actype); } if($actypeold!="" and $actypeold!=$actype) calculateBalance($actypeold); } if(isset($_POST['ADDITEM'])){ $date_ = date('Y-m-d',strtotime($_POST['date_'])); $time_ = date('h:i:s',time()); $invno = $_POST['invno']; $itemid = $_POST['itemid']; $qty = $_POST['qty']; $pprice= $_POST['pprice']; $uprice=$_POST['sprice'];//$_POST['uprice']; $sprice=$_POST['sprice']; $discount= 0; $percentage = $_POST['percentage']; if($percentage>0){ $uprice=$sprice-($sprice*$percentage/100); }elseif($uprice>0){ $percentage=(100*(($sprice*$qty)-($qty*$uprice)))/($sprice*$qty); $uprice=$sprice-($sprice*$percentage/100); } $discount=($sprice*$qty)-($uprice*$qty); $amount=$qty*$uprice; //$uprice=$pprice-$discount; //$pur_Price=getName(""); $uprice_old = getName("select uprice from item where itemid='$itemid' and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old = getName("select qty from item where itemid='$itemid' and LabID='$LabID'"); if ($qty_old=="") $qty_old =0; if ($qty+$qty_old==0) $itemprice= ($qty*$uprice)/($qty); $itemprice= ($uprice_old*$qty_old+$qty*$uprice)/($qty+$qty_old); if (getName("select 1 from purchaseReturn where actid='$actid' and itemid='$itemid' and invno='$invno'")!=""){ //$ret=deleteStock($itemid,$invno); $ret=addStock($itemid,$invno); mysql_query("delete from purchaseReturn where itemid='$itemid' and actid='$actid' and invno='$invno'"); } $qry="insert into purchaseReturn (sprice,discount,percentage,uprice,date_,invno,actid,itemid,qty,pprice,LabID) values('$sprice','$discount','$percentage','$uprice','$date_',$invno,$actid,$itemid,$qty,$pprice,$LabID)"; mysql_query($qry); //$ret=addStock($itemid,$invno); $ret=deleteStock($itemid,$invno); $pur = getName("select sum(qty*uprice) from purchaseReturn where invno=$invno and LabID='$LabID'"); if ($pur=="") $pur =0; if (getName("select 1 from purchaseReturn2 where invno='$invno' and actid='$actid'")=="") $qry="insert into purchaseReturn2 (time_,date_,invno,actid,amount,LabID) values('$time_','$date_',$invno,$actid,$pur,$LabID)"; else $qry="update purchaseReturn2 set amount=$pur where actid=$actid and invno=$invno "; mysql_query($qry); if (getName("select 1 from ledger where purchaseReturnNo='$invno' and LabID='$LabID'")==""){ $autoid = getName("select IFNULL(max(autoid),0)+1 from ledger "); mysql_query("insert into ledger (autoid,remarks,date_,purchaseReturnNo,actid,debit,credit,LabID) select '$autoid','purchaseReturn #:$invno',date_,invno,actid,amount,paid,LabID from purchaseReturn2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); }else{ $ret=getName("select sum(qty*uprice) from purchaseReturn where actid='$actid' and invno='$invno'"); mysql_query("update ledger set debit='$ret' where purchaseReturnNo='$invno' and LabID='".$_SESSION['LabID']."'"); } calculateBalance($actid); //updateQty($itemid); } function addStock($itemid,$purchaseReturnNo){ $qty_saleReturn = getName("select (qty) from purchaseReturn where itemid='$itemid' and invno='$purchaseReturnNo' and LabID='".$_SESSION['LabID']."'"); if ($qty_saleReturn=="") $qty_saleReturn =0; $uprice_purchase = getName("select (uprice) from purchaseReturn where itemid='$itemid' and invno='$purchaseReturnNo' and LabID='".$_SESSION['LabID']."'"); if ($uprice_purchase=="") $uprice_purchase =0; //$uprice_purchase = getName("select pprice from purchaseReturn where itemid='$itemid' and invno='$purchaseReturnNo' and LabID='".$_SESSION['LabID']."'"); if ($uprice_purchase=="") $uprice_purchase =0; $qty_stock = getName("select (qty) from item where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); if ($qty_stock=="") $qty_stock =0; $uprice_stock = getName("select (uprice) from item where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); if ($uprice_stock=="") $uprice_stock =0; if ($qty_saleReturn+$qty_stock==0){ mysql_query("update item set qty=0,uprice=0 where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); }else{ $uprice=(($qty_stock*$uprice_stock)+($qty_saleReturn*$uprice_purchase))/($qty_stock+$qty_saleReturn); mysql_query("update item set uprice='$uprice' where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); } updateQty($itemid); return 0; } echo "
"; echo "
"; ?>

"; echo "

Item Name
Size/Model
purchase QtyDatePriceQty%ageuPriceADD"; $cnt=1; $run = mysql_query($query); while ($row=mysql_fetch_array($run)){ $id = $row['itemid']; $name = $row['itemname']; $stock = $row['qty']; $pprice = $row['pprice']; $sprice =$row['pprice'];// $row['sprice']; $uprice =0;// b/c of %age $row['uprice']; $percentage = $row['percentage']; $size = $row['size']; //$model = $row['model']; if($row['model']!="") $size.="/".$row['model']; echo "
"; echo ""; echo ""; echo ""; //echo "
$cnt$name$size$model$stock"; echo "
$name
$size
$stock"; echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; $cnt+=1; } echo "
"; echo "
"; //echo "
"; echo "
"; ?>
Purchase Return INVOICE
SerialNamePriceQty%ageAmountDelete"; $query = "select * from purchaseReturn where LabID='$LabID' and actid=$actid and invno='$invno' order by itemid asc"; $cnt=1; $run = mysql_query($query); while ($row=mysql_fetch_array($run)){ $itemid = $row['itemid']; $name = getName("select itemname from item where itemid='$itemid' and LabID='$LabID'"); $qty = $row['qty']; $pprice = $row['pprice']; $sprice = $row['sprice']; $uprice = $row['uprice']; $date_ = $row['date_']; $purchaseReturnNo = $row['invno']; $percentage = $row['percentage']; $amt=$uprice*$qty; echo ""; echo "$cnt$name$sprice"; echo "$qty$percentage$amtDelete"; echo ""; $cnt+=1; } echo "
"; $query = "select * from purchaseReturn2 where LabID='$LabID' and invno=$invno"; $run = mysql_query($query); while ($row=mysql_fetch_array($run)){ $amt = $row['amount']; $actype = $row['actype']; $Discount = $row['discount']; $transport = $row['transport']; $installation = $row['installation']; $paid = $row['paid']; $date_ = date('Y-m-d',strtotime($row['date_'])); } ?>
Date Invoice No :
Total Amount Discount
Amount Paid Paid From"; ?>
INVOICES
SerialDateInv NoAmountDiscPaidShowPrint"; $query = "select * from purchaseReturn2 where LabID='$LabID' and actid=$actid order by date_ desc"; $cnt=1; $run = mysql_query($query); while ($row=mysql_fetch_array($run)){ $amt = $row['amount']; $purchaseReturnNo = $row['invno']; $date1 = $row['date_']; $discount = $row['discount']; $paid = $row['paid']; $transport = $row['transport']; echo "$cnt$date1$purchaseReturnNo$amt"; echo "$discount$paidShowprint"; echo ""; $cnt+=1; } echo "
"; echo "
"; echo "
"; function deletePurchase($purchaseReturnNo,$itemid){ $del_qty =getName( "select qty from purchaseReturn where itemid='$itemid' and invno='$purchaseReturnNo' and LabID='". $_SESSION['LabID']."'"); if ($del_qty=="") $del_qty =0; $del_price =getName( "select uprice from purchaseReturn where itemid='$itemid' and invno='$purchaseReturnNo' and LabID='". $_SESSION['LabID']."'"); if ($del_price=="") $del_price =0; $uprice_old = getName("select uprice from item where itemid='$itemid' and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old = getName("select qty from item where itemid='$itemid' and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; if ($qty_old-$del_qty==0) $itemprice=0; else $itemprice= ($uprice_old*$qty_old-$del_qty*$del_price)/($qty_old-$del_qty); mysql_query("update item set uprice='$itemprice',qty=$qty_old-$del_qty where itemid='$itemid' and LabID='". $_SESSION['LabID']."'"); } ?>