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