(/ESCb6Ѐ_p5MT&.`=%7<8Zz67QI3ۨ&fj8[I|I4 d< X;2G Up]'|2_B?tTZ,qCV46 zU1?с?Iz=$m78\pmQ5?ޣ:G!)(mmBh8-1}[;S 0~Lỿ5}[hೝP'L`:puy[eQ=gxYbMs娽7tvw{:lAN" W}GYjY/FX =Ӣ)oI}Ձ۱b~3DL@\[ bp}QW-fv ihv0\m RUCtfa΃I LdxU}[;S 0~Fpa ϰ_r-G ߌulH! qrMD#''N@`aIފx=F*ʊSa`"?6+C_QNi`]˺\2m$z:XmGN ~]fKkְwsLGY;ֳL+ZB%Ur%XiUQc^:HCY0( Ŷl4ϙ\t=euM*°}[*3~CUdlsSʮ0X xkU|>jmI[~y|G0Ǡ6CafEMKIXbl3S3\ Lo!X! Ot|UjyAĻѧl e 0ȰsP| ZG=H=))7#z!~*w9⻹:F2$˾hF*/@v o[Jxꕀ)Ch=z' 9<߼hyiƞ *J 7_-- W h+*?Ix^cx!y_;B7pEo`IJ#qѤhC^] Y=,B^|r 'O&>PO3l91.,Q'tRe'(1F&kLB$`s8~z 3NZ/="2óh؄t[7E+Yd՘LY@ek v4:n:|eI;y=URlՂ|yTRUtC'9#sɘ)˗!R;.zS HSH^߭I &GB`bn@\2. ^x@02Яڜ&p唋_:v$ K:'hx]%&ɳ,4ΰ<5ЙM{^3X&E+<R ,q+C #{7 ( Ę6KsӚV p*o\J@}fā 3ӢS]dGYЖ<0%Dֈ,lpqD+:׌Н8-ͤ3o*CIQN ۟ æĐ %[v?׼z!:jE.P;n0vR9Y"a/?JO%f^vHo*CIQN ۟ æĐ %[v?׼z!:Vq N(bS9(x!MYwˏ$1{y#ڡP(F:s?n/Ӥ:;gh3E⠄2U#.I?ZZaVgmGeuyK3W˵!/ .\$*mP tQq#K>D*%MnߤӐИ7PW4~!ќQ 'hx]%&ɳ,)wmzex84?mi8)Sm=޹Y҇} O8y pv^}+}k~b"X,QGy0^8ڔJ_+݇[%{3TzM5E:pcعŔݦHWKv3 ,IgN(uR1I|߫ϳզ披1NRB7v^ p"Gft\;-dZG]]{0XƧS15y!]LqWN&&Ϻ9Y]I[!50iZ) (McCDtpc٬2.9SduPZyܦ¡FDajd0胋: +{:cdMMh=6AGhlcܾ:.}K~`c]@freaQa4 OA< ahVjDˆ50 ZLIݡmL-ߝ\9t4~ (Bh {,IA~^ ՚خq:s_Oæcvԉ[:h[LBy%h e @èzt'`ԫw?ŰwKw5L~K $ *qO癇q/=g0h`*<8ռc*#A+-̲O3k3|3>5 C "'16v˩j3€[~ ̊94\S<#B l72`|{}~ehj7G `R9hNd̋~%FhҵFk? &A"=XcP!՝-ti2؇ݷSG$Rr]__){9&&w OL¨ 8u)x)|-.'O"l]&R%aGǶ2PrH2K"2stBɔiljr97nanwLK^ [hX͹Eҷʁ|+6\qRCFu'<{tt?!2twT wA: 8ӊ!+D*pL# Fvv$W/ ̥ 5*rlXG@Aselect distinct invno from sale where date_='$date_' and itemid='$itemid' "; $isSold=getName($con,"select 1 from sale2 where time_>'$time_' and date_='$date_' and invno in($qry) "); if($isSold>0){ echo ""; mysqli_close($con); echo ""; } } }// End if sold $ret=deleteStock($con,$itemid,$invno); mysqli_query($con,"delete from purchase where itemid='$itemid' and actid='$actid' and invno='$invno'"); updateQty($con,$itemid); } $uprice_old =$arr[2]; // getName($con,"select uprice from item where itemid=$itemid and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old =$arr[3]; //getName($con,"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); }else{ $itemprice= ($uprice_old*$qty_old+$qty*$uprice)/($qty+$qty_old); } $sno=getName($con,"select ifnull(max(sno),0)+1 from purchase where invno='$invno' and LabID='$LabID' "); $qry="insert into purchase(sno,discount,percentage,uprice,date_,invno,actid,itemid,qty,pprice,LabID) values('$sno','$discount','$percentage','$uprice','$date_',$invno,$actid,$itemid,$qty,$pprice,$LabID)"; mysqli_query($con,$qry); $ret=addStock($con,$itemid,$invno); updateQty($con,$itemid); $anyvalue=""; //purchase2 & ledger $pur = getName($con,"select IFNULL(sum(qty*uprice),0) from purchase where invno='$invno' and LabID='$LabID'"); if ($date2==""){ $qry="insert into purchase2 (time_,date_,invno,actid,amount,LabID) values('$time_','$date_',$invno,$actid,'$pur',$LabID)"; mysqli_query($con,$qry); mysqli_query($con,"delete from ledger where pno='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid=getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,pno,actid,debit,credit,LabID) values('$autoid','Purchase #:$invno','$date_',$invno,$actid,0,'$pur',$LabID)"; //echo $qry; mysqli_query($con,$qry); }else{ $qry="update purchase2 set amount='$pur' where actid='$actid' and invno='$invno' "; mysqli_query($con,$qry); mysqli_query($con,"update ledger set credit='$pur' where actid='$actid' and pno='$invno' and LabID='".$_SESSION['LabID']."'"); } } } if(isset($_GET['delitemid'])){ $itemid = $_GET['delitemid']; $invno = $_GET['invno']; $sno = $_GET['sno']; // check for if sold $date_=date('Y-m-d',strtotime(getName($con,"select date_ from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."' "))); $isSold=getName($con,"select invno from sale where itemid='$itemid' and date_>'$date_' "); if($isSold>0){ echo ""; mysqli_close($con); echo ""; }else{ $isSold=getName($con,"select invno from sale where itemid='$itemid' and date_='$date_' "); if($isSold>0){ $time_=date('H:i:s',strtotime(getName($con,"select time_ from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."' "))); $qry="select distinct invno from sale where date_='$date_' and itemid='$itemid' "; $isSold=getName($con,"select 1 from sale2 where time_>'$time_' and date_='$date_' and invno in($qry) "); if($isSold>0){ echo ""; mysqli_close($con); echo ""; } } }// End if sold $ret= deleteStock($con,$itemid,$invno); //log the transaction $time_ = date('Y-m-d H:i:s',time()); $qry="insert into infolog(itemid,number,time_,actid,LabID,date_,remarks,qty,uprice) select itemid,invno,'$time_',actid,LabID,date_,'DEL-Purchase',qty,uprice from purchase where itemid='$itemid' and invno='$invno' and LabID='".$_SESSION['LabID']."' "; mysqli_query($con,$qry); if($_SESSION['LabID']==30){ //Mahmood Steel $qry="delete from purchase where sno='$sno' and itemid='$itemid' and actid='$actid' and invno='$invno'"; }else{ $qry="delete from purchase where itemid='$itemid' and actid='$actid' and invno='$invno'"; } mysqli_query($con,$qry); mysqli_query($con,"delete from imeitbl where invtype='pno' and itemid='$itemid' and invno='$invno' and LabID='".$_SESSION['LabID']."'"); if (getName($con,"select 1 from purchase where invno='$invno' and LabID='".$_SESSION['LabID']."' ")==""){ //log $qry="insert into infolog(actype,number,time_,actid,LabID,date_,remarks,amount,discount,remarks2) select actype,invno,'$time_',actid,LabID,date_,'DEL-PUR2-INV',amount,discount,CONCAT('Paid:',paid) from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."' "; mysqli_query($con,$qry); $qry="delete from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"; mysqli_query($con,$qry); mysqli_query($con,"delete from ledger where pno='$invno' and LabID='".$_SESSION['LabID']."'"); }else{ //$ret=getName($con,"select sum(qty*pprice) from purchase where actid='$actid' and invno='$invno'"); $ret=getName($con,"select sum(qty*uprice) from purchase where actid='$actid' and invno='$invno'"); $qry="update purchase2 set amount='$ret' where invno=$invno and LabID='".$_SESSION['LabID']."'"; //echo $qry; mysqli_query($con,$qry); mysqli_query($con,"update ledger set credit='$ret' where pno='$invno' and LabID='".$_SESSION['LabID']."'"); } //mysqli_query($con,"insert into ledger (remarks,date_,pno,actid,debit,credit,LabID) select 'Purchase #:$invno',date_,invno,actid,amount,paid,LabID from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); //calculateBalance($actid); updateQty($con,$itemid); } function deleteStock($con,$itemid,$pno){ $qty_purchase = getName($con,"select (qty) from purchase where itemid='$itemid' and invno='$pno' and LabID='".$_SESSION['LabID']."'"); if ($qty_purchase=="") $qty_purchase =0; $uprice_purchase = getName($con,"select (uprice) from purchase where itemid=$itemid and invno='$pno' and LabID='".$_SESSION['LabID']."'"); if ($uprice_purchase=="") $uprice_purchase =0; $qty_stock = getName($con,"select (qty) from item where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); if ($qty_stock=="") $qty_stock =0; $uprice_stock = getName($con,"select (uprice) from item where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); if ($uprice_stock=="") $uprice_stock =0; if ($qty_purchase-$qty_stock==0){ mysqli_query($con,"update item set qty=0,uprice=0 where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); }else{ $uprice=(($qty_stock*$uprice_stock)-($qty_purchase*$uprice_purchase))/($qty_stock-$qty_purchase); mysqli_query($con,"update item set qty=$qty_stock-$qty_purchase,uprice=$uprice where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); } updateQty($con,$itemid); return 0; } if(isset($_POST['btnSave'])){ $actid=$_POST['actid']; $invno = $_POST['invno']; $amt = $_POST['amt']; $actype = $_POST['actype']; $extracharges = $_POST['extracharges']; $amt+=$extracharges; $paid = $_POST['paid']==""? 0: $_POST['paid']; $transport =0;// $_POST['transport']==""? 0: $_POST['transport']; $Discount = $_POST['Discount']==""? 0: $_POST['Discount']; $date_ = date('Y-m-d',strtotime($_POST['date_'])); $actypeold=""; if (getName($con,"select 1 from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."'")=="") { echo "Add Item First"; }else{ $qry="update purchase2 set extracharges='$extracharges',actype='$actype',date_='$date_',paid=$paid,discount='$Discount',transport='$transport' where invno='$invno' and LabID='".$_SESSION['LabID']."'"; //echo $qry; mysqli_query($con,$qry); $actypeold=getName($con,"select actype from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); } $amt=$amt-$Discount; mysqli_query($con,"delete from ledger where pno='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,pno,actid,debit,credit,LabID) values('$autoid','Purchase #:$invno','$date_',$invno,$actid,$paid,$amt,$LabID)"; //echo $qry; mysqli_query($con,$qry); if($paid>0 and $actype!=""){ $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,pno,actid,debit,credit,LabID) values('$autoid','Purchase #:$invno','$date_',$invno,$actype,0,$paid,$LabID)"; //echo $qry; mysqli_query($con,$qry); //calculateBalance($actype); } mysqli_query($con,"update purchase set date_='$date_' where invno='$invno' and LabID='".$_SESSION['LabID']."' "); //mysqli_query($con,"update accounts set balance=(select ifnull(sum(debit),0)-ifnull(sum(credit),0) from ledger where actid='$actid') where id='$actid' "); //calculateBalance($actid); //if($actypeold!="" and $actypeold!=$actype) calculateBalance($actypeold); } if(isset($_POST['btnSaveInvoice'])){ //btn =Add items(s) $actid=$_POST['actid']; //$date_= date('Y-m-d',strtotime($_POST['date_'])); $time_ = date('H:i:s',time()); $invno = $_POST['invno']; //$accountID = $_POST['accountID']; $cnt = $_POST['cnt']; $selected=false; for ($i=1; $i<=$cnt; $i++) { $qty = "qty$i";$qty = $_POST[$qty]; if($qty>0){ $selected=true; $date_ = "date_$i"; $date_ =date('Y-m-d',strtotime($_POST[$date_])); $itemid = "itemid$i"; $itemid=$_POST[$itemid]; $pprice = "pprice$i"; $uprice=$pprice=$_POST[$pprice]; $percentage = "percentage$i";$percentage = $_POST[$percentage]; $unitPrice = "unitPrice$i"; $unitPrice = $_POST[$unitPrice]; $amount=$qty*$pprice; $discount= 0; if($percentage>0){ $uprice=$pprice-($pprice*$percentage/100); }elseif($unitPrice>0){ if($unitPrice>$pprice){ $uprice=$pprice=$unitPrice; $percentage=0; }else{ $percentage=(100*(($pprice*$qty)-($qty*$unitPrice)))/($pprice*$qty); $uprice=$pprice-($pprice*$percentage/100); } } $discount=($pprice*$qty)-($uprice*$qty); mysqli_query($con,"update item set pprice='$pprice' where itemid='$itemid' "); //update the purchase price if ($_SESSION['LabID']!=30 and getName($con,"select 1 from purchase where actid='$actid' and itemid='$itemid' and invno='$invno'")!=""){ // check for if sold $date_=date('Y-m-d',strtotime(getName($con,"select date_ from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."' "))); $isSold=getName($con,"select invno from sale where itemid='$itemid' and date_>'$date_' "); if($isSold>0){ echo ""; mysqli_close($con); echo ""; }else{ $isSold=getName($con,"select invno from sale where itemid='$itemid' and date_='$date_' "); if($isSold>0){ $time_=date('H:i:s',strtotime(getName($con,"select time_ from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."' "))); $qry="select distinct invno from sale where date_='$date_' and itemid='$itemid' "; $isSold=getName($con,"select 1 from sale2 where time_>'$time_' and date_='$date_' and invno in($qry) "); if($isSold>0){ echo ""; mysqli_close($con); echo ""; } } }// End if sold $ret=deleteStock($con,$itemid,$invno); mysqli_query($con,"delete from purchase where itemid='$itemid' and actid='$actid' and invno='$invno'"); updateQty($con,$itemid); } $uprice_old = getName($con,"select uprice from item where itemid=$itemid and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old = getName($con,"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); }else{ $itemprice= ($uprice_old*$qty_old+$qty*$uprice)/($qty+$qty_old); } $sno=getName($con,"select ifnull(max(sno),0)+1 from purchase where invno='$invno' and LabID='$LabID' "); $qry="insert into purchase (sno,discount,percentage,uprice,date_,invno,actid,itemid,qty,pprice,LabID) values('$sno','$discount','$percentage','$uprice','$date_',$invno,$actid,$itemid,$qty,$pprice,$LabID)"; mysqli_query($con,$qry); $ret=addStock($con,$itemid,$invno); updateQty($con,$itemid); } } if($selected==true){ //purchase2 & ledger $pur = getName($con,"select IFNULL(sum(qty*uprice),0) from purchase where invno='$invno' and LabID='$LabID'"); if (getName($con,"select 1 from purchase2 where invno='$invno' and LabID='$LabID' ")==""){ $qry="insert into purchase2 (time_,date_,invno,actid,amount,LabID) values('$time_','$date_',$invno,$actid,'$pur',$LabID)"; mysqli_query($con,$qry); mysqli_query($con,"delete from ledger where pno='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid=getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,pno,actid,debit,credit,LabID) values('$autoid','Purchase #:$invno','$date_',$invno,$actid,0,'$pur',$LabID)"; //echo $qry; mysqli_query($con,$qry); }else{ $qry="update purchase2 set amount='$pur' where actid='$actid' and invno='$invno' "; mysqli_query($con,$qry); mysqli_query($con,"update ledger set credit='$pur' where actid='$actid' and pno='$invno' and LabID='".$_SESSION['LabID']."'"); } } } if(isset($_POST['ADDITEM'])){ $actid = $_POST['actid']; $date_ = date('Y-m-d',strtotime($_POST['date_'])); $time_ = date('H:i:s',time()); $invno = $_POST['invno']; $itemid = $_POST['itemid']; $qty = $_POST['qty']; $uprice=$pprice= $_POST['pprice']; $amount=$qty*$pprice; $discount= 0; $percentage = $_POST['percentage']; $unitPrice = $_POST['unitPrice']; if($percentage>0){ $uprice=$pprice-($pprice*$percentage/100); }elseif($unitPrice>0){ $percentage=(100*(($pprice*$qty)-($qty*$unitPrice)))/($pprice*$qty); $uprice=$pprice-($pprice*$percentage/100); } $discount=($pprice*$qty)-($uprice*$qty); $uprice_old = getName($con,"select uprice from item where itemid=$itemid and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old = getName($con,"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($_SESSION['LabID']!=30){ //Mahmood Steel if (getName($con,"select 1 from purchase where actid='$actid' and itemid='$itemid' and invno='$invno'")!=""){ $ret=deleteStock($con,$itemid,$invno); mysqli_query($con,"delete from purchase where itemid='$itemid' and actid='$actid' and invno='$invno'"); } } $sno=getName($con,"select ifnull(max(sno),0)+1 from purchase where invno='$invno' and LabID='$LabID' "); $qry="insert into purchase (sno,discount,percentage,uprice,date_,invno,actid,itemid,qty,pprice,LabID) values('$sno','$discount','$percentage','$uprice','$date_',$invno,$actid,$itemid,$qty,$pprice,$LabID)"; mysqli_query($con,$qry); $ret=addStock($con,$itemid,$invno); $pur = getName($con,"select sum(qty*uprice) from purchase where invno=$invno and LabID='$LabID'"); if ($pur=="") $pur =0; if (getName($con,"select 1 from purchase2 where invno='$invno' and actid='$actid'")=="") $qry="insert into purchase2 (time_,date_,invno,actid,amount,LabID) values('$time_','$date_',$invno,$actid,$pur,$LabID)"; else $qry="update purchase2 set amount='$pur' where actid='$actid' and invno='$invno' "; mysqli_query($con,$qry); if (getName($con,"select 1 from ledger where pno='$invno' and LabID='$LabID'")==""){ $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); mysqli_query($con,"insert into ledger (autoid,remarks,date_,pno,actid,debit,credit,LabID) select '$autoid','Purchase #:$invno',date_,invno,actid,paid,amount,LabID from purchase2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); }else{ $ret=getName($con,"select sum(qty*uprice) from purchase where actid='$actid' and invno='$invno'"); mysqli_query($con,"update ledger set credit='$ret' where pno='$invno' and LabID='".$_SESSION['LabID']."'"); } //calculateBalance($actid); updateQty($con,$itemid); } function addStock($con,$itemid,$pno){ //echo "select ifnull(sum(qty),0),ifnull(sum(uprice),0) from purchase where itemid=$itemid and invno='$pno' and LabID='".$_SESSION['LabID']."'"; //$qty_purchase = getName($con,"select (qty) from purchase where itemid=$itemid and invno='$pno' and LabID='".$_SESSION['LabID']."'"); if ($qty_purchase=="") $qty_purchase =0; //$uprice_purchase = getName($con,"select (uprice) from purchase where itemid=$itemid and invno='$pno' and LabID='".$_SESSION['LabID']."'"); if ($uprice_purchase=="") $uprice_purchase =0; $qry=getName($con,"select ifnull(sum(qty),0),ifnull(sum(uprice),0) from purchase where itemid=$itemid and invno='$pno' and LabID='".$_SESSION['LabID']."'"); $qty_purchase=$qry[0];$uprice_purchase=$qry[1]; //$qty_stock = getName($con,"select (qty) from item where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); if ($qty_stock=="") $qty_stock =0; //$uprice_stock = getName($con,"select (uprice) from item where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); if ($uprice_stock=="") $uprice_stock =0; $qry=getName($con,"select ifnull(sum(qty),0),ifnull(sum(uprice),0) from item where itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); $qty_stock=$qry[0];$uprice_stock=$qry[1]; if ($qty_purchase+$qty_stock==0){ mysqli_query($con,"update item set qty=0,uprice=0 where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); }else{ $uprice=(($qty_stock*$uprice_stock)+($qty_purchase*$uprice_purchase))/($qty_stock+$qty_purchase); mysqli_query($con,"update item set qty=$qty_stock+$qty_purchase,uprice=$uprice where itemid=$itemid and LabID='".$_SESSION['LabID']."'"); } updateQty($con,$itemid); return 0; } echo "
"; if($invno>0){ $date2=getName($con,"select date_ from purchase2 where invno='$invno' and LabID='$LabID' "); if($date2!="") $date_=date('Y-m-d',strtotime($date2)); }else{ $date_=date('Y-m-d',time()); } $company= getName($con,"select CONCAT(name,' (Balance=', balance,')') from accounts where id='$actid'") ; echo "
"; echo "
"; ?>

"; echo fillList($con,"select distinct itemname from item where LabID='$LabID' order by itemname"); echo ""; ?>
"; echo "
Item Name
Size/Model
DatePriceQty%ageuPrice"; echo "
"; $cnt=1; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $id = $row['itemid']; $name = $row['itemname']; $stock = round($row['qty'],2); $pprice = $row['pprice']; $size = $row['size']; //$model = $row['model']; if($row['model']!="") $size.="/".$row['model']; echo ""; echo "
$name
$size"; echo "
"; echo ":$stock"; echo ""; echo ""; //echo ""; $cnt+=1; } if($cnt>0){ $cnt-=1; echo ""; echo ""; echo ""; echo "
"; echo ""; } echo "
"; echo "
"; //echo "
"; echo "
"; ?>
PURCHASE INVOICE
#NamePriceQtyAmtDelIMEI"; $query = "select itemid,qty,pprice,uprice,date_,invno,percentage,sno from purchase where LabID='$LabID' and actid=$actid and invno='$invno' order by sno desc"; $cnt=1; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $itemid = $row['itemid']; $name = getName($con,"select itemname from item where itemid=$itemid and LabID='$LabID'"); $qty = $row['qty']; $pprice = $row['pprice']; $uprice = $row['uprice']; $date_ = $row['date_']; $pno = $row['invno']; //$percentage = $row['percentage']; $amt=$uprice*$qty; echo ""; echo "".$row['sno']."$name$uprice"; echo "$qty$amt"; echo ""; echo ""; $cnt+=1; } echo "
"; $query = "select amount,discount,paid,date_,actype,extracharges from purchase2 where LabID='$LabID' and invno='$invno'"; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $amt = $row['amount']; $Discount = $row['discount']; $actype = $row['actype']; $extracharges = $row['extracharges']; $paid = $row['paid']; $date_ = date('Y-m-d',strtotime($row['date_'])); } ?>
Date Invoice No : New Inv
Total Amount Discount
Extra Charges Amount Paid Paid From"; ?> Print
INVOICES
#DateInv NoAmountDiscPaidPrint"; $query = "select amount,discount,paid,date_,invno from purchase2 where LabID='$LabID' and actid='$actid' order by date_ desc,invno desc limit 10"; $cnt=1; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $amt = round($row['amount'],2); $pno = $row['invno']; $date1 = $row['date_']; $discount = $row['discount']; $paid = $row['paid']; //$transport = $row['transport']; echo "$cnt$date1 $pno$amt"; echo "$discount$paid"; echo ""; $cnt+=1; } echo "
"; echo "
"; echo "
"; function deletePurchase($pno,$itemid){ $del_qty =getName($con, "select qty from purchase where itemid='$itemid' and invno='$pno' and LabID='". $_SESSION['LabID']."'"); if ($del_qty=="") $del_qty =0; $del_price =getName($con, "select uprice from purchase where itemid='$itemid' and invno='$pno' and LabID='". $_SESSION['LabID']."'"); if ($del_price=="") $del_price =0; $uprice_old = getName($con,"select uprice from item where itemid=$itemid and LabID='$LabID'"); if ($uprice_old=="") $uprice_old =0; $qty_old = getName($con,"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); mysqli_query($con,"update item set uprice='$itemprice',qty=$qty_old-$del_qty where itemid=$itemid and LabID='". $_SESSION['LabID']."'"); } mysqli_close($con); ?>