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9^ 9Xn mk*>BnG %'?3~PYo%Λ."sGDZ/)>ϖ:G8"nY uͺ̓\?o̓vZ߯d@+쇋rpsrDg!Ra&imX[0,>*QzG#Ь{m&m~O$<)] wr %55n>YYŪ~2ŕ&\b[r=%|UdBg4ˉ\C)^zLv 7wƈ3w-ĖD@8rՊw3+]d3UDMu=iYČѦKwZ$p)w QD)Bl]QQk θ92iδF* 9"ϾA zICNPbL`+ 9&δ˙{8?s0i9 ͱoJGK29~4'/%㺊C2b],e=e>b㝢 K@}m^E-/Eqh߲\ttx]=Sc WCg·S],t Fλtf_lq'xS++0DB6e)J:J?e/#/SDxgwQ䣥%A3 3%C CA!Ҙ/ /+EaHý#DD~lⷑ&9jrRSsU~wGr}9}Sd6d]_ nnЕ+wfCsZ-F "g5ԤCJ`%׻dA%̔]G,pAJ;HBGofj`tZM(gӖ,hfX>Î9x- Hԣ2cBt}R[rC#%DO=$]vuŒce՝Wo;@ =-H\- KM&~~H#_Dlz;^3ܟW 4tU95PڮcWFZl|8-`bCkj/2[*.ZR ɧrZ~3R )QIбu5GuS/e@dB; v\4K4׊E): d@2q17R ɧrZ~3R )QIбu5GuS/e@dB; v\4K4׊E):hfb7]%t6zZU9bp0+Gbhn,"update itemInOut set batchNo='0' where batchNo is null "); $cur= odbc_exec( $conn,"update itemInOut set batchNo='0' where ltrim(rtrim(batchNo))='' "); $cur= odbc_exec( $conn,"update itemInOut set batchNo='0' where ltrim(rtrim(batchNo))=' ' "); $cur= odbc_exec( $conn,"update itemTable set qty=0 "); $cur= odbc_exec( $conn, "select distinct itemID,batchNo from itemInOut where itemID>0 and pNo>0" ); while( odbc_fetch_row( $cur ) ) { $qty1=getName($conn,"select isnull(sum(qty),0) from itemInOut where itemID='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."' and pNo>0"); $qty1+=getName($conn,"select isnull(sum(qty),0) from itemInOut where itemID='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."' and saleRNo>0"); $qty1-=getName($conn,"select isnull(sum(qty),0) from itemInOut where itemID='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."' and saleNo>0"); $qty1-=getName($conn,"select isnull(sum(qty),0) from itemInOut where itemID='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."' and pRNo>0"); if(""==getName($conn,"select 1 from itemTable where itemID2='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."'")){ //$query="insert into itemTable(rPrice,itemName,itemID,tPrice,percentage,barCode) select tPrice,','$itemName','$itemID','$tPrice','$percentage','$barCode')"; $qry="insert into itemTable (itemID2,qty,uPrice,batchNo,expiry) select top 1 itemID,'$qty1',uPrice,batchNo,expiry from itemInOut where pNo>0 and itemID='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."'"; $cur2= odbc_exec( $conn, $qry); }else{ $qry="update itemTable set qty=$qty1 where itemID2='".odbc_result( $cur,'itemID')."' and batchNo='".odbc_result( $cur,'batchNo')."' "; $cur2= odbc_exec( $conn, $qry); } $qry="update itemTable set qty=(select sum(qty) from itemTable where itemID2='".odbc_result( $cur,'itemID')."') where itemID='".odbc_result( $cur,'itemID')."'"; $cur2= odbc_exec( $conn, $qry); } } if(isset($_POST['btnShow'])){ $anyvalue= $_POST['anyvalue']; } if(isset($_POST['btnSave'])){ $itemName= $_POST['itemName']; $new=$itemID= $_POST['itemID']; $rPrice= $_POST['rPrice']; $percentage= $_POST['percentage']; $tPrice= $_POST['tPrice']; $packing=$_POST['packing']; $packNos=$packing>0?$packing:1; $limit= $_POST['limit']; $itemType= $_POST['itemType']; $barCode= substr($_POST['barCode'],0,100); if($percentage>0) { $tPrice=$rPrice-($rPrice*$percentage/100); }elseif($tPrice>0) { //($rPrice*$percentage/100)=$rPrice-$tPrice; //$rPrice*$percentage=($rPrice-$tPrice)*100; $percentage=($rPrice-$tPrice)*100/$rPrice; }else { $tPrice=$rPrice; } $itemID= getName( $conn, "select itemID from itemTable where itemname='$itemName'" ); if ($itemID=="") { $itemID= getName( $conn, "select isnull(max(itemID),0)+1 from itemTable" ); $query="insert into itemTable (packNos,itemType,rPrice,itemName,itemID,tPrice,percentage,barCode,packing,limit) values('$packNos','$itemType','$rPrice','$itemName','$itemID','$tPrice','$percentage','$barCode','$packing','$limit')"; }else { $query="update itemTable set packNos='$packNos',itemType='$itemType',packing='$packing',limit='$limit',rPrice='$rPrice',itemName='$itemName',tPrice='$tPrice',percentage='$percentage',barCode='$barCode' where itemID='$itemID'"; } //echo $query; $cur= odbc_exec( $conn, $query ); if($barCode!=""){ $query="update itemTable set barCode='$barCode' where itemID2='$itemID'"; $cur= odbc_exec( $conn, $query); } $cur= odbc_exec( $conn,"update itemTable set packNos=1 where packNos is null "); //Check if Opening //if($new=="" and $_POST['qty']>0 and $_POST['pNo']>0 ){ if($_POST['qty']>0 and $_POST['pNo']>0 ){ $date_=getName($conn,"select date_ from itemInOut where pNo='".$_POST['pNo']."'"); $date_ = date('Y-m-d',strtotime($date_)); $accountID=getName($conn,"select accountID from itemInOut where pNo='".$_POST['pNo']."'"); //$pPrice=getName($conn,"select date_ from itemInOut where pNo='".$_POST['pNo']."'"); $qty=$_POST['qty']; $percentage=$_POST['percentage2']; $uPrice=$_POST['uPrice']; if($percentage>0) { $uPrice=$tPrice-($tPrice*$percentage/100); $discount=($tPrice*$qty)-($uPrice*$qty); }elseif($uPrice>0) { $percentage=($tPrice-$uPrice)*100/$tPrice; $discount=($tPrice*$qty)-($uPrice*$qty); }else { $uPrice=$tPrice; $discount=0; } $pPrice=$uPrice; $pNo=$_POST['pNo']; $batchNo=$_POST['batchNo']; if($batchNo=="") $batchNo="0"; $query="insert itemInOut(userID,expiry,pPrice,date_,pNo,accountID,itemID,qty,tPrice,percentage,discount,uPrice,batchNo)"; $query.=" values ('".$_SESSION['userID']."','".$_POST['expiry']."','$pPrice','$date_','".$_POST['pNo']."','$accountID','$itemID','".$_POST['qty']."','$tPrice','$percentage','$discount','$uPrice','$batchNo')"; $cur= odbc_exec( $conn, $query ); //update stock and uPrice $cur= addInvoice($conn,$itemID,$batchNo,'pNo',$_POST['pNo'],$_POST['expiry']); $query="update itemInOutSummary set amount=(select sum(uPrice*qty) from itemInOut where pNo='$pNo' and accountID='$accountID') "; $query.=" where pNo='$pNo' and accountID='$accountID'" ; $cur= odbc_exec( $conn, $query); $remarks="Purchase Invoice:".$pNo; $query="update ledger set credit=(select sum(uPrice*qty) from itemInOut where pNo='$pNo' and accountID='$accountID')"; $query.=" where accountID='$accountID' and remarks='$remarks' "; $cur= odbc_exec( $conn, $query); $cur=calculateBalance($conn,$accountID); echo ""; }else{ echo ""; } } function addInvoice($conn,$itemID,$batchNo,$invType,$invNo,$expiry) { $uPrice=0;$qty=0; if(""==getName($conn,"select 1 from itemTable where itemID2='$itemID' and batchNo='$batchNo'")){ $qry="insert into itemTable (itemID2,qty,uPrice,batchNo,expiry) values('$itemID','$qty','$uPrice','$batchNo','$expiry')"; $cur2= odbc_exec( $conn, $qry); } $query= "select qty,uPrice,pPrice,tPrice from itemInOut where $invType='$invNo' and itemID='$itemID' and batchNo='$batchNo'"; //echo "
$query"; $cur= odbc_exec( $conn, $query ); while( odbc_fetch_row( $cur ) ) { $qty= odbc_result( $cur, 'qty' ); $uPrice= round(odbc_result( $cur,'uPrice')); $pPrice= round(odbc_result( $cur,'pPrice')); } if($invType=="pNo"){ //$uPrice=(($qtyTotal*$uPriceTotal)+($qty*$uPrice))/($qtyTotal+$qty); $qry="update itemTable set uPrice='$uPrice',expiry='$expiry',tPrice='".odbc_result($cur,'tPrice')."' where itemID2='$itemID' and batchNo='$batchNo'"; $cur2= odbc_exec( $conn, $qry); $cur2= odbc_exec( $conn, "update itemTable set tPrice='".odbc_result($cur,'tPrice')."' where itemID='$itemID' and tPrice<>'".odbc_result($cur,'tPrice')."'"); } //$cur=updateStock($conn,$itemID,$batchNo) ; $cur2= odbc_exec( $conn,"update itemTable set qty='$qty' where itemID2='$itemID' and batchNo='$batchNo'"); $cur2= odbc_exec( $conn,"update itemTable set qty='$qty' where itemID='$itemID'"); return 0; } if (isset($_GET['itemID'])) { $itemID = $_GET['itemID']; $query = "select * from itemTable where itemID='$itemID'"; $cur= odbc_exec( $conn, $query ); while( odbc_fetch_row( $cur ) ) { //$date_= date("Y-m-d", strtotime(odbc_result( $cur, 'date_' ))); $rPrice= odbc_result( $cur, 'rPrice' ); $itemName= odbc_result( $cur, 'itemName' ); $tPrice= odbc_result( $cur, 'tPrice' ); $percentage= odbc_result( $cur,'percentage'); $barCode= odbc_result( $cur,'barCode'); $packing= odbc_result( $cur,'packing'); $limit= odbc_result( $cur,'limit'); $itemType= odbc_result( $cur,'itemType'); } } if (isset($_GET['delID'])) { //$itemID = $_GET['delID']; $query=getName($conn,"select count(*) from itemInOut where itemID='".$_GET['delID']."'"); if($query=="0") { $cur= odbc_exec( $conn,"delete from itemTable where itemID='".$_GET['delID']."'"); $cur= odbc_exec( $conn,"delete from itemTable where itemID2='".$_GET['delID']."'"); echo "Record Deleted Successfully"; }else{ echo "Sorry! can't be Deleted, contains Stock"; } } echo ""; echo ""; echo ""; echo ""; echo "
Medicine Name"; echo ""; echo fillList($conn,"select itemName from itemTable where itemID>0 order by itemName asc"); echo ""; echo "
"; echo "
"; echo "
"; $expID=$itemName= ""; $cnt=$amount=0; if($pNo>0) { $invNo=$pNo; $query= "select i.itemID,i.qty,i.batchNo,i.tPrice,i.percentage,i.uPrice,i2.itemName,i.expiry from itemInOut i,itemTable i2 where i.itemID=i2.itemID and i.pNo='$invNo' order by i.itemID"; $cur= odbc_exec( $conn, $query ); $cnt=0; while( odbc_fetch_row( $cur ) ) { if ($cnt++==0){ if(getName($conn,"select count(*) from itemInOut where pNo='$invNo'")>10) //echo "
"; echo "
S.#NameBatchNoqtyprice%ageUnitPriceAmountdelete
"; else echo "
S.#NameBatchNoqtyprice%ageUnitPriceAmountdelete
"; } $itemID= odbc_result( $cur, 'itemID' ); //$itemName= getName($conn,"select itemName from itemTable where itemID='".odbc_result( $cur, 'itemID' )."'"); $qty= odbc_result( $cur, 'qty' ); $batchNo= odbc_result( $cur, 'batchNo' ); $expiry= odbc_result( $cur, 'expiry' ); $tPrice= round(odbc_result( $cur,'tPrice'),2); $percentage= round(odbc_result( $cur,'percentage'),2); $uPrice= round(odbc_result( $cur,'uPrice'),2); $amount=$uPrice*$qty; echo ""; //echo ""; echo ""; echo ""; echo ""; echo "
S.#NameBatchNoqtyprice%ageUnitPriceAmountdelete
$cnt".odbc_result($cur,'itemName').""; echo ""; echo "$tPrice"; echo ""; echo"$uPrice$amountdelete" ; //$cnt+=1; } echo "
"; } odbc_close($conn); function query2CSV($conn,$query) { $time_=date('d-m-Y-s-a', time()); //$fileName="d:\myLabel.csv"; $fileName="\\\SERVER\Open\myLabel.csv"; if(file_exists($fileName)) unlink($fileName); $fp = fopen($fileName, 'w'); $array = array(); $ar = array(); $i=0; $cur= odbc_exec( $conn, $query ); while( odbc_fetch_row( $cur ) ) { if($i==0){ for ($j = 1; $j <= odbc_num_fields($cur); $j++) { $field_name = odbc_field_name($cur, $j); $ar[$field_name] =$field_name; } $array[$i] = $ar; $i++; } for ($j = 1; $j <= odbc_num_fields($cur); $j++) { $field_name = odbc_field_name($cur, $j); if($field_name=='Branch' or $field_name=='AccountNo') $ar[$field_name] ='="' . odbc_result($cur, $field_name) . '"'; else $ar[$field_name] =odbc_result($cur, $field_name); //'="' . $yourNumber . '"' } $array[$i] = $ar; $i++; } foreach ($array as $fields) { fputcsv($fp, $fields); //fputcsv($fp, (string) $fields); } fclose($fp); return ($fileName); } ?>