"; $gam=sqlsrv_query($conn,$q72); while($gar=sqlsrv_fetch_array($gam,SQLSRV_FETCH_ASSOC)) { $buyer_name=$gar["DRCR_NAME"]; $gamres=sqlsrv_query($conn, "SELECT * FROM [CUS_SUP_ADDRESS_D] WHERE [DRCR_CODE]='$account_id' AND [SL_NO]='$delivery_to'"); while($gamr=sqlsrv_fetch_array($gamres,SQLSRV_FETCH_ASSOC)) { $address1=$gamr["ADD1"].$gamr["ADD2"]; $address2=$gamr["ADD3"].$gamr["ADD4"]; $address3=$gamr["ADD5"]; $city=$gamr["LOCATION"]; $pin=$gamr["PINCODE"]; $phone1=$gamr["PHONE_NO"]; // $phone2=$gamr["phone2"]; $mob1=$gamr["MOBILE_NO"]; // $mob2=$gamr["mob2"]; $gstin=$gamr["GST_NO"]; $temp_sup_type=$gamr["GST"]; if($temp_sup_type=='A'){$sup_type="B2B";} elseif($temp_sup_type=="C"){$sup_type="EXPWP";} elseif($temp_sup_type=="I"){$sup_type="EXPWOP";} elseif($temp_sup_type=="D"){$sup_type="SEZWP";} elseif($temp_sup_type=="K"){$sup_type="SEZWOP";} elseif($temp_sup_type=="J"){$sup_type="DEXP";} if(strtoupper($gstin)!="URP"){ $buyer_state_code=substr($gstin,0,2); }else{ $buyer_state_code=96; // For Exports } //$buyer_state_code=substr($gstin,0,2); } } $buyerDtls=' "gstin": "'.$gstin.'", "lglNm": "'.$buyer_name.'", "trdNm": "'.$buyer_name.'", "addr1": "'.$address1.'", "addr2": "'.$address2.'", "loc": "'.$city.'", "pin": "'.$pin.'", "stcd": "'.$buyer_state_code.'", "pos": "'.$buyer_state_code.'", "ph": "'.$phone1.'", "em": "test@einv.com" '; $docDtls=' "typ": "INV", "no": "'.$inv_no_db.'", "dt": "'.$inv_date.'" '; $filecontents.="=====sellerDtls=====\n".$sellerDtls."\n
"; $filecontents.="=====docDtls=====\n".$docDtls."\n
"; $filecontents.="=====buyerDtls=====\n".$buyerDtls."\n
"; $q159="SELECT * FROM [SALES_D] WHERE [DOC_NO]='$inv_id'"; $git=sqlsrv_query($conn,$q159); if(!$git){echo "Err: ";} if($debug=='y'){echo "Qry-$docDtls
$q159";} while($gitr=sqlsrv_fetch_array($git,SQLSRV_FETCH_ASSOC)){ $temp_item_id=$gitr["I_CODE"]; $temp_qty=$gitr["BALANCEAMOUNT"]; $temp_rate=$gitr["RATE"]; $discount_amt=$gitr["DISCOUNT"]; $temp_item_unit=$gitr["QTY_UNIT"]; $other_charges=$gitr["othersamt"]; $temp_disc_amt=$gitr["QTY_DISC_VALUE"]; $tot_other_charges+=sprintf('%01.2f',$other_charges); // $temp_item_name1=$gitr["item_name"]; $temp_tax_per=($gitr["IGST"]+$gitr["CGST"]+$gitr["SGST"]); if((substr($gstin,0,2))==(substr($co_gstin,0,2))){ $cgst_amt=(($temp_qty*$temp_rate)-$temp_disc_amt)*$temp_tax_per/200; $sgst_amt=(($temp_qty*$temp_rate)-$temp_disc_amt)*$temp_tax_per/200; // $sgst_amt=$temp_qty*$temp_rate*$temp_tax_per/200; $igst_amt=0; }else{ $cgst_amt=0; $sgst_amt=0; // $temp_tax_per=$gitr["IGST"]; $igst_amt=(($temp_qty*$temp_rate)-$temp_disc_amt)*$temp_tax_per/100; // echo "Interstate"; } // echo "
TTP$tax_amt $temp_tax_per SGSTA $sgst_amt, CGSTA$cgst_amt , IGST A$igst_amt
"; // $temp_discount_amt=$gitr["discount_amt"]; // $gitdet=sqlsrv_query($conn, "SELECT [I_NAME],[UNIT],[HSN_SAC_CODE] FROM [ITEM_MASTER] WHERE [I_CODE]='$temp_item_id'"); $gitdet=sqlsrv_query($conn, "SELECT [I_NAME],[HSN_SAC_CODE],[RDPF] FROM [ITEM_MASTER] WHERE [I_CODE]='$temp_item_id'"); while($gitdetr=sqlsrv_fetch_array($gitdet,SQLSRV_FETCH_ASSOC)){ $temp_item_name=$gitdetr["I_NAME"]; $temp_srvce_chk=$gitdetr["RDPF"]; //$temp_item_unit=$gitdetr["UNIT"]; $temp_vat_code=$gitdetr["HSN_SAC_CODE"]; } // echo "
iid $temp_item_id $temp_vat_code $temp_item_unit
"; //$temp_item_unit=$mysqli->result($gitdet,0,"unit"); // if($tt==0){} if($tt>0){ $itemList.=","; } $tt++; $temp_line=sprintf('%01.2f',($temp_qty*$temp_rate)); $temp_tax_amt=sprintf('%01.2f',(($temp_qty*$temp_rate)-$temp_disc_amt)*$temp_tax_per/100)); $sub_total=$sub_total+$temp_line; $ald=sprintf('%01.2f',($temp_line-$temp_disc_amt)); $tot_ald+=$ald; //$ald=sprintf('%01.2f',$ald); $tot_tax_amt=$tot_tax_amt+$temp_tax_amt; $tot_discount=$tot_discount+$temp_disc_amt; $l_st=$ald+$temp_tax_amt; $tot_st=$tot_st+$l_st; if(strtoupper($temp_srvce_chk)=='SR'){$isServc="Y";}else{$isServc="N";} $tot_cgst_amt+=$cgst_amt;; $tot_sgst_amt+=$sgst_amt; $tot_igst_amt+=$igst_amt;; // $totItemVal=sprintf('%01.2f',(($temp_qty*$temp_rate)+($temp_qty*$temp_rate*$temp_tax_per/100)+$other_charges-$temp_disc_amt)); $totItemVal=sprintf('%01.2f',(($temp_qty*$temp_rate)+$temp_tax_amt+$other_charges-$temp_disc_amt)); $itemList.='{ "slNo": "'.$tt.'", "prdDesc": "'.ucwords(strtolower($temp_item_name)).'", "isServc": "'.$isServc.'", "hsnCd": "'.$temp_vat_code.'", "qty": "'.sprintf('%01.3f',$temp_qty).'", "unit": "'.strtoupper($temp_item_unit).'", "unitPrice": "'.$temp_rate.'", "totAmt": "'.(sprintf('%01.2f',$ald)).'", "discount": "'.sprintf('%01.2f',$temp_disc_amt).'", "assAmt": "'.(sprintf('%01.2f',$ald)-sprintf('%01.2f',$temp_disc_amt)).'", "gstRt": "'.sprintf('%01.2f',$temp_tax_per).'", "igstAmt": "'.sprintf('%01.2f',$igst_amt).'", "cgstAmt":"'.sprintf('%01.2f',$cgst_amt).'", "sgstAmt":"'.sprintf('%01.2f',$sgst_amt).'", "cesRt": 0, "cesAmt": 0, "cesNonAdvlAmt": 0, "stateCesRt": 0, "stateCesAmt": 0, "stateCesNonAdvlAmt": 0, "othChrg": "'.sprintf('%01.2f',$other_charges).'", "totItemVal":"'.$totItemVal.'" }'; } $filecontents.="=====itemList=====\n".$itemList."\n
"; //echo "GST TYPE =$gst_type
$inv_date>= $gst_imple_date"; $sub_total4=$sub_total-$tot_discount+$fwd+$tot_tax_amt+$fwd_tax_amt+$tot_other_charges; $valDtls=' "assVal": '.sprintf('%01.2f',($tot_ald)).', "cgstVal":'.sprintf('%01.2f',$tot_cgst_amt).', "sgstVal":'.sprintf('%01.2f',$tot_sgst_amt).', "igstVal":'.sprintf('%01.2f',$tot_igst_amt).', "cesVal": 0, "stCesVal": 0, "totInvVal": '.sprintf('%01.2f',($sub_total4+$roundoff)).', "rndOffAmt": '.sprintf('%01.2f',$roundoff).''; $filecontents.="=====valDtls=====\n".$valDtls."\n
"; //saving JSON //$file_path ='json_files'.DIRECTORY_SEPARATOR.date('Ym').DIRECTORY_SEPARATOR.date('d'); $file_path ='json_files/'.date('Ymd'); //$set_qr_code_path = 'qr_assets/'; // If directory is not created, the create a new directory if(!file_exists($file_path)){ mkdir($file_path); } //Set a file name $filename = $file_path."/".$inv_id."-".time().'.log'; if($debug=='y'){echo "File Contents:-
$filecontents";} append_file($filename,$filecontents); function write_file($filename,$newdata) { $f=fopen($filename,"w"); fwrite($f,$newdata); fclose($f); } function append_file($filename,$newdata) { $f=fopen($filename,"a"); fwrite($f,$newdata); fclose($f); } function read_file($filename) { $f=fopen($filename,"r"); $data=fread($f,filesize($filename)); fclose($f); return $data; } //!saving JSON ?>