select po.status,'' posign,po.ApprovedByID, if(po.IsEdited=1,concat('Amended PO Approved by ',po.LastEditByName,' on',DATE_FORMAT(po.LastEditDate,'%d-%b-%Y')),'') pomsg, cm.centrecode,cm.centre, po.Warranty,po.NFANo,po.TermandCondition, sm.GSTIN DeliveryGSTN,sm.state deliveryState,sm.GSTINAddress deliveryGSTINAddress,(select house_no from employee_master where employee_id=po.CreatedByID) MakerUser, ifnull(spt.DeliveryTerm,'') DeliveryPeriod,ifnull(spt.TermCondition,'') PaymentTerms,CONCAT(ifnull(sl.`ContactPerson`,''),' (',IFNULL(sl.ContactPersonNo,''),')',', ',ifnull(sl.`StoreLocationAddress`,'')) DeliveryAddress, (SELECT VendorNote FROM st_purchaseorder_footer_note)VendorNote, (SELECT FooterNote FROM st_purchaseorder_footer_note)FooterNote ,concat(cccm.CategoryTypeName,'~',ssb.`Name`) Category,''ForPaymentStatusContact ,concat(img.`ItemNameGroup`,'-',ifnull(im.packsize,' '),'-',ifnull(im.CatalogNo,' '),'-',ifnull(im.MachineName,' '),'-',ifnull(im.ManufactureName,' ')) Discription,im.`HsnCode` HSN_SAC_CODE,pod.`MajorUnitName` UOM, `TrimZero`(pod.`ApprovedQty`) Qty,`TrimZero`(pod.`Rate`) UnitRate, `TrimZero`(pod.`UnitPrice`)UnitPrice, `TrimZero`(pod.`DiscountAmount`) Disc,(TrimZero(pot.CGSTTax)+TrimZero(pot.SGSTax)+TrimZero(pot.IGSTTax)) Tax, TrimZero(IFNULL(pot.CGSTTaxAmt,'0')) CGST,TrimZero(IFNULL(pot.SGSTaxAmt,'0'))SGST, TrimZero(IFNULL(pot.IGSTTaxAmt,'0')) IGST, TrimZero(pod.`NetAmount`) Amount, (pod.`ApprovedQty`*pod.UnitPrice) finalprice, po.`PurchaseOrderNo` PONumber,DATE_FORMAT(ifnull(po.ApprovedDate,po.CreatedDate),'%d-%b-%Y')PODate, po.`VendorName` VendorName,ven.`PrimaryContactPerson` VendorContactPerson,ifnull((select Address from st_supplier_gstn where supplierID=ven.`SupplierID` and StateID=sm.`id` limit 1),po.`VendorAddress`) VendorAddress, ven.`PrimaryContactPersonMobileNo` VendorMobile,ven.`EmailId` VendorEmail,(select GST_No from st_supplier_gstn where supplierID=ven.`SupplierID` and StateID=sm.`id` limit 1) VendorGSTIN, (select state from st_supplier_gstn where supplierID=ven.`SupplierID` limit 1) VendorState,1 ImageToPrint , ItemName FROM `st_purchaseorder` po INNER JOIN st_locationmaster sl ON sl.`LocationID`=po.`LocationID` INNER JOIN f_panel_master fpm ON fpm.`Panel_ID`=sl.`Panel_ID` INNER JOIN centre_master cm ON cm.`CentreID`=fpm.`CentreID` INNER JOIN state_master sm ON sm.`id`=cm.`StateID` INNER JOIN `st_purchaseorder_details` pod ON po.`PurchaseOrderID`=pod.`PurchaseOrderID` AND pod.`IsActive`=1 INNER JOIN st_itemmaster im ON pod.ItemID = im.ItemID INNER JOIN st_itemmaster_group img ON img.ItemIDgroup = im.ItemIDgroup INNER JOIN st_subcategorymaster ssb ON ssb.`SubCategoryID`=im.`SubCategoryID` inner join st_categorytypemaster cccm on cccm.CategoryTypeID=im.CategoryTypeID INNER JOIN `st_vendormaster` ven ON ven.`SupplierID`=po.`VendorID` LEFT JOIN st_purchaseorder_termsandconditions spt ON spt.`PurchaseOrderID`=po.`PurchaseOrderID` LEFT JOIN ( SELECT pot.ItemID ,pot.PurchaseOrderID, sum(IF(pot.TaxName='IGST',IFNULL(pot.Percentage,0),0))IGSTTax,sum(IF(pot.TaxName='IGST',IFNULL(pot.TaxAmt,0),0))IGSTTaxAmt, sum(IF(pot.TaxName='CGST',(pot.Percentage),0))CGSTTax,sum(IF(pot.TaxName='CGST',(pot.TaxAmt),0))CGSTTaxAmt,sum(IF(pot.TaxName='SGST',(pot.Percentage),0))SGSTax ,sum(IF(pot.TaxName='SGST',(pot.TaxAmt),0))SGSTaxAmt FROM st_purchaseorder_tax pot WHERE pot.PurchaseOrderID='29' GROUP BY ItemID )pot ON pot.ItemID=pod.ItemID and pot.PurchaseOrderID=pod.PurchaseOrderID WHERE po.PurchaseOrderID = '29' and po.status in('2','5') ORDER BY pod.ItemName