query($q24); if(!$get_inv_det){ echo "Error in Getting Invoice details. ".$mysqli->error."
$q24";; }//else{echo "ok";} while($ginvmast=$get_inv_det->fetch_array()){ $inv_no_db =$ginvmast["inv_no"]; $inv_date_db =$ginvmast["inv_date"]; $inv_date_disp= $inv_date; $inv_date=date("d/m/Y",strtotime($inv_date_db)); $sale_amt =$ginvmast["sale_amt"]; $tax_amt =$ginvmast["tax_amt"]; $discount =$ginvmast["discount"]; $inv_amt =$ginvmast["inv_amt"]; $account_id =$ginvmast["account_id"]; //echo "hh $inv_amt"; } //echo "inv Date $inv_date, $inv_date_db"; //exit("here 51 $inv_no_db"); $gam=$mysqli->query("SELECT * FROM `".$tblprfx."account_mast` WHERE `id`='$account_id' LIMIT 1"); while($gamr=$gam->fetch_array()) { $buyer_name=$gamr["account"]; $address1=$gamr["address1"]; $address2=$gamr["address2"]; $address3=$gamr["address3"]; $city=$gamr["city"]; $pin=$gamr["pin"]; $phone1=$gamr["ph"]; $phone2=$gamr["ph2"]; $mob1=$gamr["mob1"]; $gstin=$gamr["gstin"]; $gstin="05AAACG4414B1ZE"; $pin="249185"; $buyer_state_code=substr($gstin,0,2); } $gstin="05AAACG6430D1Z6"; exit("exiint $gstin"); $shipto_gstin=$gstin; $shipto_name=$co_name; $doc_details=' "supplyType": "O", "subSupplyType": "1", "subSupplyDesc": "", "docType": "INV", "docNo": "'.$_SESSION['loc_prefix'].'-'.$inv_no_db.'", "docDate": "'.$inv_date.'" '; /* //subSupplyType 1 Supply 2 Import 3 Export 4 Job Work 5 For Own Use 6 Job work Returns 7 Sales Return 8 Others 9 SKD/CKD 10 Line Sales 11 Recipient Not Known 12 Exhibition or Fairs //docType INV Tax Invoice BIL Bill of Supply BOE Bill of Entry CHL Delivery Challan CNT Credit Note OTH Others //Transportation Mode 1 Road 2 Rail 3 Air 4 Ship */ $from_details=' "fromGstin": "'.$co_gstin.'", "fromTrdName": "'.$co_name.'", "fromAddr1": "'.$add1.'", "fromAddr2": "'.$add2.'", "fromPlace": "'.$co_loc.'", "fromPincode": "'.$co_pin.'", "actFromStateCode": "'.$co_state_code.'", "fromStateCode": "'.$co_state_code.'" '; $to_details=' "toGstin": "'.$gstin.'", "toTrdName": "'.$buyer_name.'", "toAddr1": "'.$address1.'", "toAddr2": "'.$address2.'", "toPlace": "'.$city.'", "toPincode": "'.$pin.'", "actToStateCode": "'.$buyer_state_code.'", "toStateCode": "'.$buyer_state_code.'" '; $filecontents.="=====buyerDtls=====\n".$from_details."\n"; $filecontents.="=====docDtls=====\n".$doc_details."
"; $filecontents.="=====sellerDtls=====\n".$to_details."\n"; $txn_details=' "transactionType":"1", "dispatchFromGSTIN":"'.$co_gstin.'", "dispatchFromTradeName":"'.$co_name.'", "shipToGSTIN":"'.$shipto_gstin.'", "shipToTradeName":"'.$shipto_name.'" '; /* //TransactionType 1 Regular 2 Bill To Ship To 3 Bill From Dispatch From 4 Combination of 2 and 3 For type 2, shipToGSTIN, , shipToTradeName may be passed, for type 3, dispatchFromGSTIN , dispatchFromTradeName may be passed and for type 4, both may be passed */ //$gst_type="interstate"; if((substr($gstin,0,2))==(substr($co_gstin,0,2))){ $cgst_amt=$tax_amt/2; $sgst_amt=$tax_amt/2; $igst_amt=0; }else{ $cgst_amt=0; $sgst_amt=0; $igst_amt=$tax_amt; } $q159="SELECT * FROM `".$tblprfx."sale_bk` WHERE `inv_id`='$inv_id'"; //exit("hre ".$q159); $git=$mysqli->query($q159); if(!$git){echo "Err: ".$mysqli->error;} //else{echo "SELECT * FROM `".$tblprfx."sale_bk` WHERE `inv_id`='$inv_id'";} while($gitr=$git->fetch_array()){ $temp_item_id=$gitr["item_id"]; $temp_qty=$gitr["item_qty"]; $temp_rate=$gitr["item_rate"]; $temp_item_name1=$gitr["item_name"]; $temp_tax_per=$gitr["tax_per"]; $temp_tax_id=$gitr["tax_id"]; $loc_pfx=$gitr["loc_prefix"]; $temp_tax_amt=$gitr["tax_amt"]; $temp_discount_amt=$gitr["discount_amt"]; $gitdet=$mysqli->query("SELECT `item`,`unit`,`vat_code` FROM `".$tblprfx."item_mast` WHERE `item_id`='$temp_item_id'"); while($gitdetr=$gitdet->fetch_array()){ $temp_item_name=$gitdetr["item"]; $temp_item_unit=$gitdetr["unit"]; $temp_vat_code=$gitdetr["vat_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){ $item_data_details.=","; $itemList.=","; } $tt++; $temp_line=sprintf('%01.2f',($temp_qty*$temp_rate)); $sub_total=$sub_total+$temp_line; $ald=$temp_line-$temp_discount_amt; $tot_ald=$tot_ald+$ald; $ald=sprintf('%01.2f',$ald); $tot_tax_amt=$tot_tax_amt+$temp_tax_amt; $tot_discount=$tot_discount+$temp_discount_amt; $l_st=$ald+$temp_tax_amt; $tot_st=$tot_st+$l_st; if((substr($gstin,0,2))==(substr($co_gstin,0,2))){ $cgst_amt=$temp_tax_amt/2; $sgst_amt=$temp_tax_amt/2; $igst_amt=0; $cgst_rate=sprintf('%01.2f',($temp_tax_per/2)); $sgst_rate=sprintf('%01.2f',($temp_tax_per/2)); $igst_rate=0; }else{ $cgst_amt=0; $sgst_amt=0; $igst_amt=$temp_tax_amt; $igst_rate=sprintf('%01.2f',$temp_tax_per); $cgst_rate=0; $sgst_rate=0; } $tot_cgst_amt+=$cgst_amt;; $tot_sgst_amt+=$sgst_amt; $tot_igst_amt+=$igst_amt;; $item_data_details.=' { "productName":"Mobile", "productDesc":"'.ucwords(strtolower($temp_item_name)).'", "hsnCode": "'.$temp_vat_code.'", "quantity": "'.$temp_qty.'", "qtyUnit": "'.strtoupper($temp_item_unit).'", "cgstRate": "'.$cgst_rate.'", "sgstRate": "'.$sgst_rate.'", "igstRate": "'.$igst_rate.'", "cessRate": "0", "cessNonAdvol":"0", "taxableAmount":"'.sprintf('%01.2f',($temp_rate*$temp_qty)).'" }'; } $filecontents.="=====itemList=====\n".$item_data_details."\n"; //echo "GST TYPE =$gst_type
$inv_date>= $gst_imple_date"; $sub_total4=$sub_total-$tot_discount+$fwd+$tot_tax_amt+$fwd_tax_amt; $roundoff=$inv_amt-$sub_total4; $value_details=' "otherValue":"0", "totalValue": "'.sprintf('%01.2f',$sale_amt).'", "cgstValue": "'.sprintf('%01.2f',$tot_cgst_amt).'", "sgstValue": "'.sprintf('%01.2f',$tot_sgst_amt).'", "igstValue": "'.sprintf('%01.2f',$tot_igst_amt).'", "cessValue": "0", "cessNonAdvolValue":"0", "totInvValue": "'.sprintf('%01.2f',$inv_amt).'" '; $transporter_details=' "transporterId":"'.$transporter_gstin.'", "transporterName": "'.$transporter_name.'", "transDocNo": "'.$transporter_doc_no.'", "transMode": "1", "transDistance": "'.$transport_distance.'", "transDocDate": "'.$transporter_doc_date.'", "vehicleNo": "'.$vehicle_no.'", "vehicleType": "'.$vehicle_type.'" '; //TranMode // $valDtls=' // "assVal": '.sprintf('%01.2f',$sale_amt).', // "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',$inv_amt).', // "rndOffAmt": '.sprintf('%01.2f',$roundoff).' // '; $filecontents.="=====TxnDtls=====\n".$txn_details."\n"; $filecontents.="=====valDtls=====\n".$value_details."\n"; $filecontents.="=====transporterDtls=====\n".$trasporter_details."\n"; //saving JSON //$file_path ='json_files'.DIRECTORY_SEPARATOR.date('Ym').DIRECTORY_SEPARATOR.date('d'); $file_path ='json_files/ewb_inv/'.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."/".$tblprfx."-".$inv_id."-".time().'.log'; 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 ?>