function addCropDetails //only farmer can call ( uint _cropType, //string memory _cropName, uint _quantity, string memory _location ) public { require ( owner != msg.sender , "owner cant add crop details" ); //u r not registered yet require (farmers[msg.sender].isRegistered == true, "You are not registered yet or you are not farmer"); require ( allPricesSet==true , "gov isnt initialized prices yet" ); require ( setProfitPercent == true , "gov isnt initialized profit rates yet" ); require ( _cropType < arraySize && _cropType >= 0 , "invalid crop type");
uint cropPr = cropTypes[_cropType]; //fetched cropPrice by cropType (by gov)
cropCounter++;
Crop memory crop ;
crop.cropId=cropCounter;
//adding crop type to cropType
crop.cropType = _cropType;
crop.farmer_quantity=_quantity;
crop.location=_location;
crop.farmerAddrs = payable(msg.sender);
crop.cropPrice = cropPr;
crop.isAdded=true;
crops[cropCounter] = crop; //here i passed instance to mapping
//in below lines i tried to add instance to array in many ways but not even one is working //function is working only after commenting this.
//fCropArray[cropCounter] = crops[cropCounter];
//fCropArray[cropCounter]=crop;
//addCropToArray(crops[cropCounter]);
emit cropAdded();
}