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ޥۤ^p-OP@v'&tKK_ݢ'ȵ+; >^Xcq_bWA== 5+?ƈ#$YE>_m/V!FoЃC&P;|Їw!Br<9Ỷ-5!v,*sJXc<#Y$=50Er1&v vԪ-0CA = '!aSyIq5 ]eMebBJȸR3 D y K'< z*& $anyvalue=""; if($invno=="NEW") $invno = getName($con,"select ifnull(max(invno),0)+1 from sale2 where LabID='$LabID'"); //$actid = $_POST['actid']; if ($qty<=$stock){ $percentage =0;// $_POST['percentage']; $ret=getName($con,"select sprice,uprice from item where itemid='$itemid'"); $uprice=$sprice=$ret[0]; $pprice=$ret[1]; if($_POST['price']>0){ $uprice=$sprice=$_POST['price']; } //$unitPrice = $_POST['unitPrice']; $discount=0; $date_ = date('Y-m-d',strtotime($_POST['date_'])); $time_ = date('H:i:s',time()); $sno=getName($con,"select sno from sale where round(meter,5)=round('$meter',5) and actid='$actid' and itemid='$itemid' and invno='$invno'"); if ($sno>0) { $qry="update sale set uprice='$uprice',percentage='$percentage',discount='$discount',qty=qty+$qty,pprice=$pprice,sprice=$sprice where actid=$actid and itemid=$itemid and invno='$invno'"; }else{ $qry=getName($con,"select ifnull(max(sno),0)+1 from sale where invno='$invno' and LabID='$LabID' "); $qry="insert into sale (sno,uprice,percentage,discount,date_,invno,actid,itemid,qty,pprice,sprice,LabID) values('$qry','$uprice',$percentage,$discount,'$date_',$invno,$actid,$itemid,$qty,$pprice,$sprice,$LabID)"; } //echo $qry; mysqli_query($con,$qry); $sno=getName($con,"select 1 from sale2 where invno='$invno' and actid='$actid'") ; if ($sno==""){ $pur = getName($con,"select ifnull(sum(qty*uprice*meter),0) from sale where invno=$invno and LabID='$LabID'"); $qry="insert into sale2 (discount,time_,date_,invno,actid,amount,LabID) values(0,'$time_','$date_',$invno,'$actid','$pur',$LabID)"; }else{ $pur ="select ifnull(sum(qty*uprice*meter),0) from sale where invno=$invno and LabID='$LabID'"; $qry="update sale2 set amount=($pur) where actid='$actid' and invno='$invno' "; } mysqli_query($con,$qry); mysqli_query($con,"update item set sprice='$sprice' where sprice<'$sprice' and itemid='$itemid' and LabID='".$_SESSION['LabID']."' "); //ledger if (getName($con,"select 1 from ledger where actid='$actid' and LabID='$LabID' and saleno='$invno'")==""){ $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); mysqli_query($con,"insert into ledger (autoid,remarks,date_,saleno,actid,debit,credit,LabID) select '$autoid','sale #:$invno',date_,invno,actid,amount,paid,LabID from sale2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); }else{ $pur ="select ifnull(sum(qty*uprice*meter),0) from sale where invno=$invno and LabID='$LabID'"; mysqli_query($con,"update ledger set debit=($pur) where actid='$actid' and saleno='$invno' and LabID='".$_SESSION['LabID']."'"); } calculateBalance($con,$actid); updateQtyHafiz($con,$itemid,$meter); if($imei!="" and getName($con,"select 1 from imeitbl where invtype='saleno' and imei='$imei' and invno='$invno' and labid='$LabID'")==""){ $maxno=getName($con,"select IFNULL(max(autoid),0)+1 from imeitbl"); $query="insert into imeitbl (itemid,autoid,date_,invno,invtype,imei,labid)"; $query.=" values('$itemid','$maxno',NOW(),'$invno','saleno','$imei','".$_SESSION['LabID']."')"; $run = mysqli_query($con,$query); } }else { echo "

Sorry! Quantity Exceeded

"; } } } function addStock($con,$itemid,$saleno,$meter){ if(getName($con,"select 1 from itemlink where round(meter,5)=round('$meter',5) and itemid='$itemid' and LabID='".$_SESSION['LabID']."'")==""){ mysqli_query($con,"insert into itemlink(pprice,sprice,itemid,meter,qty,LabID) select pprice,sprice,'$itemid','$meter',0,LabID from item where itemid='$itemid' and LabID='".$_SESSION['LabID']."' "); } $qry=getName($con,"select ifnull(sum(qty),0),ifnull(sum(pprice),0) from sale where round(meter,5)=round('$meter',5) and itemid='$itemid' and invno='$saleno' and LabID='".$_SESSION['LabID']."'"); $qty_sale=$qry[0];$uprice_sale=$qry[1]; $qry=getName($con,"select ifnull(sum(qty),0),ifnull(sum(uprice),0) from itemlink where meter='$meter' and itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); $qty_stock=$qry[0];$uprice_stock=$qry[1]; if ($qty_stock==0){ mysqli_query($con,"update itemlink set qty='$qty_sale',uprice='$uprice_sale' where round(meter,5)=round('$meter',5) and itemid='$itemid' and LabID='".$_SESSION['LabID']."'"); }else{ $uprice=(($qty_stock*$uprice_stock)+($qty_sale*$uprice_sale))/($qty_stock+$qty_sale); mysqli_query($con,"update itemlink set qty=".$qty_stock+$qty_sale.",uprice='$uprice' where round(meter,5)=round('$meter',5) and itemid=$itemid and LabID='".$_SESSION['LabID']."'"); } updateQtyHafiz($con,$itemid,$meter); return 0; } if(isset($_POST['btnSave'])){ $invno = $_POST['invno']; $actid = $_POST['actid']; $amt = $_POST['amt']; $remarks = $_POST['remarks']; $paid = $_POST['paid']==""? 0: $_POST['paid']; $paidextra = $_POST['paidextra']; $actype = $_POST['actype']; $receiverName =protect($con,$_POST['receiverName']); $receiverCell =protect($con,$_POST['receiverCell']); $discount = $_POST['discount']==""? 0: $_POST['discount']; if($paidextra>=$amt) $paid =$amt-$discount; else $paidextra=$paid; for ($i=1; $i<$_POST['cnt']; $i++) { $itemid = "itemid$i"; $itemid = $_POST[$itemid]; $uprice = "uprice$i"; $uprice = $_POST[$uprice]; $qty = "qty$i"; $qty = $_POST[$qty]; $sno = "sno$i"; $sno = $_POST[$sno]; $qtyold = "qtyold$i"; $qtyold = $_POST[$qtyold]; $upriceold = "upriceold$i"; $upriceold = $_POST[$upriceold]; if($qty!=$qtyold or $uprice!=$upriceold or $sno!=$i){ //$qry="update sale set uprice='$uprice',qty='$qty',sno='$i' where round(meter,5)=round('$meter',5) and actid='$actid' and itemid='$itemid' and invno='$invno'"; //echo "
".$qry; //mysqli_query($con,$qry); //updateQtyHafiz($con,$itemid,$meter); $qry="update sale set sno='$i' where sno='$sno' and actid='$actid' and itemid='$itemid' and invno='$invno'"; mysqli_query($con,$qry); } } $amt=getName($con,"select sum(meter*uprice*qty) from sale where invno='$invno' and LabID='".$_SESSION['LabID']."' "); $date_ = date('Y-m-d',strtotime($_POST['date_'])); if (getName($con,"select 1 from sale where invno='$invno' and LabID='".$_SESSION['LabID']."' limit 1")!="") { if (getName($con,"select 1 from sale2 where invno='$invno' and LabID='".$_SESSION['LabID']."'")=="") { echo "Add Item First"; }else{ $qry="update sale2 set remarks='$remarks',paidextra='$paidextra',actype='$actype',amount='$amt',receiverName='$receiverName',receiverCell='$receiverCell',date_='$date_',paid=$paid,discount='$discount',transport='$transport' where invno='$invno' and LabID='".$_SESSION['LabID']."'"; //echo $qry; mysqli_query($con,$qry); mysqli_query($con,"update sale set date_='$date_' where date_<>'$date_' and invno='$invno' and LabID='".$_SESSION['LabID']."' "); //$actypeold=getName($con,"select actype from sale2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); } $amt=$amt-$discount; mysqli_query($con,"delete from ledger where saleno='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,saleno,actid,debit,credit,LabID) values('$autoid','sale #:$invno','$date_',$invno,$actid,$amt,$paid,$LabID)"; //echo $qry; mysqli_query($con,$qry); //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($con,$actid); if($paid>0 and $actype!=""){ $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); $qry="insert into ledger (autoid,remarks,date_,saleno,actid,debit,credit,LabID) values('$autoid','sale #:$invno','$date_',$invno,$actype,$paid,0,$LabID)"; mysqli_query($con,$qry); calculateBalance($con,$actype); } if($_SESSION['LabID']==43) sendSMS($con,$invno); //if($actypeold!="" and $actypeold!=$actype) calculateBalance($actypeold); } } if(isset($_POST['ADDITEM'])){ //(+) $invno =$_POST['invno']; if($invno=="NEW") $invno = getName($con,"select ifnull(max(invno),0)+1 from sale2 where LabID='$LabID'"); $actid = $_POST['actid']; $itemid = $_POST['itemid']; $stock = $_POST['stock']; $qty = $_POST['qty']; $meter = $_POST['meter']; $metersold = $_POST['metersold']; if ($qty<=$stock){ $percentage = $_POST['percentage']; $uprice=$sprice= $_POST['sprice']; $pprice=getName($con,"select uprice from itemlink where round(meter,5)=round('$meter',5) and itemid='$itemid'"); $unitPrice = $_POST['unitPrice']; $discount=0; $date_ = date('Y-m-d',strtotime($_POST['date_'])); $time_ = date('H:i:s',time()); if($percentage>0){ $uprice=$sprice-($sprice*$percentage/100); }elseif($unitPrice>0){ $percentage=(100*(($sprice*$qty)-($qty*$unitPrice)))/($sprice*$qty); $uprice=$sprice-($sprice*$percentage/100); } $discount=($sprice*$qty)-($uprice*$qty); //$sno=getName($con,"select sno from sale where round(meter,5)=round('$meter',5) and actid='$actid' and itemid='$itemid' and invno='$invno'"); $sno=getName($con,"select sno from sale where round(fromMeter,5)=round('$meter',5) and LabID='$LabID' and itemid='$itemid' and invno='$invno'"); if ($sno>0) { $qry="update sale set meter='$metersold',uprice='$uprice',percentage='$percentage',discount='$discount',qty='$qty',pprice='$pprice',sprice=$sprice where round(fromMeter,5)=round('$meter',5) and actid=$actid and itemid=$itemid and invno='$invno'"; }else{ $sno=getName($con,"select ifnull(max(sno),0)+1 from sale where invno='$invno' and LabID='$LabID' "); $qry="insert into sale (fromMeter,meter,sno,uprice,percentage,discount,date_,invno,actid,itemid,qty,pprice,sprice,LabID) values('$meter','$metersold','$sno','$uprice',$percentage,$discount,'$date_',$invno,$actid,$itemid,$qty,$pprice,$sprice,$LabID)"; } //echo $qry; mysqli_query($con,$qry); $pur = getName($con,"select ifnull(sum(qty*uprice*meter),0) from sale where invno=$invno and LabID='$LabID'"); if (getName($con,"select 1 from sale2 where invno='$invno' and actid='$actid'")=="") $qry="insert into sale2 (time_,date_,invno,actid,amount,LabID) values('$time_','$date_',$invno,$actid,$pur,$LabID)"; else $qry="update sale2 set amount='$pur' where LabID='$LabID' and invno=$invno "; //echo $qry; mysqli_query($con,$qry); //$pur = "select ifnull(sum(qty),0) from purchase where itemid='$itemid' and LabID='$LabID'"; //$sale = "select ifnull(sum(qty),0) from sale where itemid='$itemid' and LabID='$LabID'"; //mysqli_query($con,"update item set qty=($pur)-($sale),sprice='$sprice' where itemid='$itemid' and LabID='".$_SESSION['LabID']."' "); if (getName($con,"select 1 from ledger where LabID='$LabID' and saleno='$invno'")==""){ mysqli_query($con,"delete from ledger where saleno='$invno' and LabID='".$_SESSION['LabID']."'"); $autoid = getName($con,"select IFNULL(max(autoid),0)+1 from ledger "); mysqli_query($con,"insert into ledger (autoid,remarks,date_,saleno,actid,debit,credit,LabID) select '$autoid','sale #:$invno',date_,invno,actid,amount,paid,LabID from sale2 where invno='$invno' and LabID='".$_SESSION['LabID']."'"); }else{ mysqli_query($con,"update ledger set debit=(select sum(qty*uprice*meter) from sale where invno='$invno' and LabID='".$_SESSION['LabID']."') where actid='$actid' and saleno='$invno' and LabID='".$_SESSION['LabID']."'"); calculateBalance($con,$actid); } if($meter-$metersold>0){ $netMeter=$meter-$metersold; $qry="insert into salecutting(fromMeter,invno,type_,itemid,qty,meter,labid,userid) values('$meter','$invno','sale','$itemid','$qty','$metersold','".$_SESSION['LabID']."','".$_SESSION['UserID']."')"; mysqli_query($con,$qry); updateQtyHafiz($con,$itemid,$netMeter); } //after cutting updateQtyHafiz($con,$itemid,$meter); //$anyvalue=getName($con,"select itemname from item where itemid='$itemid' and LabID='$LabID' "); $anyvalue=$_POST['itemname']; // for search again }else { echo "

Sorry! Quantity Exceeded

"; } //$i=1000; } $company=getName($con,"select CONCAT(name,' (Balance=', balance,')') from accounts where id='$actid' and LabID='$LabID'"); //if($invno>0) $date_=date('Y-m-d',strtotime(getName($con,"select date_ from sale2 where invno='$invno' and LabID='$LabID' "))); if($invno>0){ $date2=getName($con,"select date_ from sale2 where invno='$invno' and LabID='$LabID' "); if($date2!="") $date_=date('Y-m-d',strtotime($date2)); } ?> <?php echo $company;?>
"; echo "
"; ?>

"; echo fillList($con,"select concat(itemname) as itemname from item where qty>0 and LabID='$LabID' order by itemname"); echo ""; ?>
"; echo "
NamePriceMeterQty%ageuPriceAdd"; if ($anyvalue=="") $query = "select il.itemid,i.itemname,il.qty,il.uprice,il.sprice,il.meter from item i,itemlink il where il.itemid=i.itemid and il.qty>0 and i.LabID='$LabID' order by il.itemid desc limit 10"; else //$query = "select itemid,itemname,qty,uprice,sprice,model,size,company from item where qty>0 and LabID='$LabID' and status=0 and (itemname like '%$anyvalue%' or model like '%$anyvalue%' or size like '%$anyvalue%') order by itemname asc"; $query = "select i.itemid,i.itemname,il.qty,il.uprice,il.sprice,il.meter from item i,itemlink il where il.itemid=i.itemid and il.qty>0 and i.LabID='$LabID' and (i.itemname like '%$anyvalue%') order by il.itemid desc,il.meter desc "; //echo $query; $run = mysqli_query($con,$query); $cnt=1; while ($row=mysqli_fetch_array($run)){ //$id = $row['itemid']; //$name = $row['itemname']; $stock = $row['qty']; $uprice = $row['uprice']; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; //echo ""; echo "
".$row['itemname']; echo ""; echo "".$row['meter']." x ".$row['qty']; echo " x "; echo ""; echo ""; echo ""; echo ""; //$cnt+=1; } //echo "
"; echo "
"; echo ""; //bulkSave Form echo "
"; //panel body closed echo "
"; echo "
"; if($invno!="NEW"){ echo "
"; echo "
"; ?>
SALE INVOICE
#NameMeterPriceMeterQtytMeterAmtDel"; $query = "select s.itemid,s.qty,s.uprice,s.invno,s.percentage,s.sno,i.itemname,s.meter,s.fromMeter from sale s,item i where s.itemid=i.itemid and s.LabID='$LabID' and s.actid=$actid and s.invno='$invno' order by s.sno desc"; $cnt=1;$preItem=""; $qtyTotal=$mTotal=$itemCnt=$amtTotal=0; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $itemid = $row['itemid']; $qty = $row['qty']; $meter = $row['meter']; $fromMeter = $row['fromMeter']; $uprice = $row['uprice']; $saleno = $row['invno']; $amt=$uprice*$qty*$meter; if($preItem!=$itemid and $itemCnt>1){ echo "".$qtyTotal."".$mTotal."".($amtTotal); $qtyTotal=$mTotal=$itemCnt=$amtTotal=0; }elseif($preItem!=$itemid){ $qtyTotal=$mTotal=$itemCnt=$amtTotal=0; } $preItem=$itemid; $itemCnt++; $qtyTotal+=$qty; $mTotal+=($row['meter']*$row['qty']); $amtTotal+=($row['meter']*$row['qty']*$row['uprice']); echo ""; echo ""; echo ""; echo ""; echo ""; echo "".$row['sno']."".$row['itemname']; //$sprice$qty".$row['uprice'].""; echo "".$row['fromMeter']; echo ""; echo ""; echo ""; echo "".$row['meter']*$row['qty'].""; echo "$amt"; //echo ""; $cnt+=1; } if($itemCnt>1){ echo "".$qtyTotal."".$mTotal."".($amtTotal); } echo ""; echo "
"; if($invno!="NEW"){ $query = "select amount,discount,paid,receiverName,receiverCell,date_,actype,extracharges,paidextra,remarks from sale2 where LabID='$LabID' and invno='$invno'"; $run = mysqli_query($con,$query); while ($row=mysqli_fetch_array($run)){ $amt = $row['amount']; $discount = $row['discount']; $net=$amt-$discount; $paid = $row['paid']; $receiverName = $row['receiverName']; $receiverCell = $row['receiverCell']; $date_ = date('Y-m-d',strtotime($row['date_'])); $actype = $row['actype']; $extracharges = $row['extracharges']; $paidextra = $row['paidextra']; $remarks = $row['remarks']; } } $profit=getName($con,"select IFNULL(sum(qty*uprice*meter),0)-IFNULL(sum(qty*pprice*meter),0) from sale where LabID='$LabID' and invno='$invno' "); ?>
Inv No. Date:
Total Amount Discount
NetAmount Paid
Name
Remarks Paid To"; ?>
INVOICES
#DateInvAmountDiscNetPaidPrint"; $query = "select amount,invno,date_,discount,paid,transport from sale2 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)){ $saleno = $row['invno']; $date1 = date('d-m-Y',strtotime($row['date_'])); $paid = $row['paid']; $net=round($row['amount']-$row['discount']); echo "$cnt$date1 $saleno".round($row['amount']); echo "".$row['discount']."$net$paid"; echo ""; //$cnt+=1; } echo "
"; echo "
"; echo "
"; echo "
"; function sendSMS($con,$invno){ //Hafiz Fabrics SMS $id ="WAHCloth"; $password ="AH786"; $sender = "A-H Cloth"; $amt=getName($con,"select paid,remarks,actid,amount from sale2 where LabID='". $_SESSION['LabID'] ."' and invno='".$invno."' "); $actname=getName($con,"select name,contacts,balance from accounts where LabID='". $_SESSION['LabID'] ."' and id='".$amt[2]."' "); $sms="محترم "; $sms.=" ".$actname[0]."\n"; $sms.="خریداری کا شکریہ"."\n"; $sms.=" انوائس رقم=".$amt[3]."\n"; $sms.="وصولی=".$amt[0]."\n"; $bal=$amt[3]-$amt[0]; $sms.="انوائس بقایہ=".$bal."\n"; $sms.="ٹوٹل بقایہ=".$actname[2]; $mobile =$actname[1];// "923018859522";///Recepient Mobile Number if(substr($mobile,0,2)=="03") $mobile="923".substr($mobile,2,12); $UniCode ="1"; //echo "
MobileNo=".$mobile."
"; $url = 'http://api.m4sms.com/api/sendsms?id='.$id.'&pass='.$password.'&mobile='.urlencode($mobile).'&brandname='.urlencode($sender).'&msg='.urlencode($sms).'&language=Urdu'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $output=curl_exec($ch); if(curl_errno($ch)) { echo 'error:' . curl_error($ch); } else { echo $output; } curl_close($ch); //to Owner $mobile="923232211155"; $url = 'http://api.m4sms.com/api/sendsms?id='.$id.'&pass='.$password.'&mobile='.urlencode($mobile).'&brandname='.urlencode($sender).'&msg='.urlencode($sms).'&language=Urdu'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $output=curl_exec($ch); if(curl_errno($ch)) { echo 'error:' . curl_error($ch); } else { echo $output; } curl_close($ch); } mysqli_close($con); //echo "

Admin Panel

"; ?>