Accounting-Companion / TallyConnector

You can use Tally Connector to Connect your desktop/Mobile Applications with Tally seamlessly.
47 stars 29 forks source link

Get stock quantity for a stock item #19

Closed SpideySaif closed 2 years ago

SpideySaif commented 2 years ago

Is it possible to get the available stock quantity for a particular stock item?

Thanks.

saivineeth100 commented 2 years ago

Yes(we need to extend Stock Item Model for that) I removed closing balances from all models as it can be calculated If you wat to get closing balance or any field that is not there in default models you can extend that model and add that properties with correct XML Tag In your case Stock Item Closing Balance is divided into 3 properties Closing Balance, Closing Value, Closing Rate

[XmlRoot(ElementName = "STOCKITEM")]
[XmlType(AnonymousType = true)]
public class StockItem : StockItem 
{
    [XmlElement(ElementName = "CLOSINGBALANCE")]
    public TallyQuantity? ClosingBal { get; set; }

    [XmlElement(ElementName = "CLOSINGVALUE")]
    public TallyAmount? ClosingValue { get; set; }

    [XmlElement(ElementName = "CLOSINGRATE")]
    public TallyRate? ClosingRate { get; set; }
}
#Make sure You use above type in GetStockItem<type>()
#Since Closingvalues not fetched automatically we need to explicitly specify in fetch list and send them as parameter
List<string> fetchList = new() { "MasterId", "CanDelete", "ClosingBalance", "ClosingRate", "ClosingValue", "*" };
StockItem  TallystockItem = tally.GetStockItem<StockItem>("name of StckItm", fetchList: fetchList);
# If you want closing bal at specified date then you need to send both from and to date parameters
StockItem TallystockItem = await Tally.GetStockItem<StockItem>("name of StckItm",fromDate: new DateTime(2006, 4, 1), toDate:new DateTime(2016,5,31), fetchList: fetchList);

# TallystockItem.ClosingBal  will have closingBal
SpideySaif commented 2 years ago

Can we get the closing details through XML request for a stock item?

saivineeth100 commented 2 years ago

Can we get the closing details through XML request for a stock item?

If you any issue regarding this library raise a issue here, else use forums like stackoverflow I added postman collection in other useful resources there you can find all XMLS

SpideySaif commented 2 years ago

Yes(we need to extend Stock Item Model for that) I removed closing balances from all models as it can be calculated If you wat to get closing balance or any field that is not there in default models you can extend that model and add that properties with correct XML Tag In your case Stock Item Closing Balance is divided into 3 properties Closing Balance, Closing Value, Closing Rate

[XmlRoot(ElementName = "STOCKITEM")]
[XmlType(AnonymousType = true)]
public class StockItem : StockItem 
{
    [XmlElement(ElementName = "CLOSINGBALANCE")]
    public TallyQuantity? ClosingBal { get; set; }

    [XmlElement(ElementName = "CLOSINGVALUE")]
    public TallyAmount? ClosingValue { get; set; }

    [XmlElement(ElementName = "CLOSINGRATE")]
    public TallyRate? ClosingRate { get; set; }
}
#Make sure You use above type in GetStockItem<type>()
StockItem  TallystockItem = tally.GetStockItem<StockItem>("name of StckItm");
# TallystockItem.ClosingBal  will have closingBal

I tried getting this data through your library(which is great btw) by extending the StockItem model as you said, but I am getting errors on TallyQuantity and TallyRate as their references could not be found.

saivineeth100 commented 2 years ago

You need to import relevant namespaces TallyQuantity and TallyRate are in TallyConnector.Core.Converters.XMLConverterHelpers; if TallyConnector.Core.Converters.XMLConverterHelpers is not there update TallyConnector package to latest version 1.0.8

SpideySaif commented 2 years ago

Yup.. updating to 1.0.8 solved the namespace issue. Now I am getting the ClosingBal, ClosingValue, ClosingRate as null but getting the values for same item if I check it through a xml request in postman.

saivineeth100 commented 2 years ago

Yes(we need to extend Stock Item Model for that) I removed closing balances from all models as it can be calculated If you wat to get closing balance or any field that is not there in default models you can extend that model and add that properties with correct XML Tag In your case Stock Item Closing Balance is divided into 3 properties Closing Balance, Closing Value, Closing Rate

[XmlRoot(ElementName = "STOCKITEM")]
[XmlType(AnonymousType = true)]
public class StockItem : StockItem 
{
    [XmlElement(ElementName = "CLOSINGBALANCE")]
    public TallyQuantity? ClosingBal { get; set; }

    [XmlElement(ElementName = "CLOSINGVALUE")]
    public TallyAmount? ClosingValue { get; set; }

    [XmlElement(ElementName = "CLOSINGRATE")]
    public TallyRate? ClosingRate { get; set; }
}
#Make sure You use above type in GetStockItem<type>()
#Since Closingvalues not fetched automatically we need to explicitly specify in fetch list and send them as parameter
List<string> fetchList = new() { "MasterId", "CanDelete", "ClosingBalance", "ClosingRate", "ClosingValue", "*" };
StockItem  TallystockItem = tally.GetStockItem<StockItem>("name of StckItm", fetchList: fetchList);
# If you want closing bal at specified date then you need to send both from and to date parameters
StockItem TallystockItem = await Tally.GetStockItem<StockItem>("name of StckItm",fromDate: new DateTime(2006, 4, 1), toDate:new DateTime(2016,5,31), fetchList: fetchList);

# TallystockItem.ClosingBal  will have closingBal

I updated previous code (Added Ex: to get closing balance on specific date) Closing bal ,rate, value are not calculated by tally by default , if we want them we need to explicitly specify them in fetch list an d send to tally

SpideySaif commented 2 years ago

Worked like a charm. Thank you for your help.

saivineeth100 commented 2 years ago

Worked like a charm. Thank you for your help.

I am creating a Tutorial Series on Tally Connector You can see Status at - Project

Don't forget to Start this Repo

sanketgroup commented 2 years ago

What is the best way to get list of ALL stock items with closing Balance for a given date? (Total Stock Items are around 15,000)

saivineeth100 commented 2 years ago

I added new method to get large data from Tally Which will fetch data in a paginated manner, so you no need to worry about

var StockItems= await _tallyService.GetAllObjectsAsync<StockItem>()

This update is not released yet; you can enable include-pre-release to get this update